Completed
Push — master ( 83c807...9a529b )
by Andrei
02:33
created

somsc.get_clusters()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
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.nnet.som import som;
30
from pyclustering.nnet.som import type_conn;
31
32
33
class somsc:
34
    """!
35
    @brief Class represents simple clustering algorithm based on self-organized feature map. 
36
    @details This algorithm uses amount of clusters that should be allocated as a size of SOM map. Captured objects by neurons are clusters.
37
             Algorithm is able to process data with Gaussian distribution that has spherical forms.
38
    
39
    """
40
    def __init__(self, data, amount_clusters, epouch = 100, ccore = False):
41
        self.__data_pointer = data;
42
        self.__amount_clusters = amount_clusters;
43
        self.__epouch = epouch;
44
        self.__ccore = ccore;
45
        
46
        self.__network = None;
47
48
49
    def process(self):
50
        """!
51
        @brief Performs cluster analysis in line with rules of K-Means algorithm.
52
        
53
        @remark Results of clustering can be obtained using corresponding get methods.
54
        
55
        @see get_clusters()
56
        
57
        """
58
        
59
        self.__network = som(1, self.__amount_clusters, type_conn.grid_four, None, self.__ccore);
60
        self.__network.train(self.__data_pointer, self.__epouch, True);
61
62
63
    def get_clusters(self):
64
        return self.__network.capture_objects;
65