Completed
Push — master ( 9a529b...6868e5 )
by Andrei
02:23
created

somsc.process()   A

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
"""!
2
3
@brief Cluster analysis algorithm: SOM-SC (Self-Organized Feature Map for Simple Clustering)
4
@details Based on article description:
5
         - no reference
6
7
@authors Andrei Novikov ([email protected])
8
@date 2014-2017
9
@copyright GNU Public License
10
11
@cond GNU_PUBLIC_LICENSE
12
    PyClustering is free software: you can redistribute it and/or modify
13
    it under the terms of the GNU General Public License as published by
14
    the Free Software Foundation, either version 3 of the License, or
15
    (at your option) any later version.
16
    
17
    PyClustering is distributed in the hope that it will be useful,
18
    but WITHOUT ANY WARRANTY; without even the implied warranty of
19
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
    GNU General Public License for more details.
21
    
22
    You should have received a copy of the GNU General Public License
23
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
@endcond
25
26
"""
27
28
29
from pyclustering.cluster.encoder import type_encoding;
30
31
from pyclustering.nnet.som import som;
32
from pyclustering.nnet.som import type_conn;
33
34
35
class somsc:
36
    """!
37
    @brief Class represents simple clustering algorithm based on self-organized feature map. 
38
    @details This algorithm uses amount of clusters that should be allocated as a size of SOM map. Captured objects by neurons are clusters.
39
             Algorithm is able to process data with Gaussian distribution that has spherical forms.
40
    
41
    Example:
42
    @code
43
        # load list of points for cluster analysis
44
        sample = read_sample(path);
45
        
46
        # create instance of SOM-SC algorithm to allocated two clusters
47
        somsc_instance = somsc(sample, 2);
48
        
49
        # run cluster analysis and obtain results
50
        somsc_instance.process();
51
        somsc_instance.get_clusters();
52
    @endcode
53
    """
54
    def __init__(self, data, amount_clusters, epouch = 100, ccore = False):
55
        
56
        self.__data_pointer = data;
57
        self.__amount_clusters = amount_clusters;
58
        self.__epouch = epouch;
59
        self.__ccore = ccore;
60
        
61
        self.__network = None;
62
63
64
    def process(self):
65
        """!
66
        @brief Performs cluster analysis by competition between neurons of SOM.
67
        
68
        @remark Results of clustering can be obtained using corresponding get methods.
69
        
70
        @see get_clusters()
71
        
72
        """
73
        
74
        self.__network = som(1, self.__amount_clusters, type_conn.grid_four, None, self.__ccore);
75
        self.__network.train(self.__data_pointer, self.__epouch, True);
76
77
78
    def get_clusters(self):
79
        """!
80
        @brief Returns list of allocated clusters, each cluster contains indexes of objects in list of data.
81
        
82
        @see process()
83
        
84
        """
85
        
86
        return self.__network.capture_objects;
87
88
89
    def get_cluster_encoding(self):
90
        """!
91
        @brief Returns clustering result representation type that indicate how clusters are encoded.
92
        
93
        @return (type_encoding) Clustering result representation.
94
        
95
        @see get_clusters()
96
        
97
        """
98
        
99
        return type_encoding.CLUSTER_INDEX_LIST_SEPARATION;
100