somsc.py
1 """!
2 
3 @brief Cluster analysis algorithm: SOM-SC (Self-Organized Feature Map for Simple Clustering)
4 @details There is no paper on which implementation is based. Algorithm SOM-SC is adaptation of SOM for cluster analysis in simple way.
5  Basic idea: amount of cluster that should be allocated is defines amount of neurons in the self-organized map. SOM-SC can be
6  considered as neural network implementation of K-Means algorithm.
7 
8 @authors Andrei Novikov (pyclustering@yandex.ru)
9 @date 2014-2018
10 @copyright GNU Public License
11 
12 @cond GNU_PUBLIC_LICENSE
13  PyClustering is free software: you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  PyClustering is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program. If not, see <http://www.gnu.org/licenses/>.
25 @endcond
26 
27 """
28 
29 
30 from pyclustering.cluster.encoder import type_encoding
31 
32 from pyclustering.nnet.som import som
33 from pyclustering.nnet.som import type_conn
34 
35 
36 class somsc:
37  """!
38  @brief Class represents simple clustering algorithm based on self-organized feature map.
39  @details This algorithm uses amount of clusters that should be allocated as a size of SOM map. Captured objects by neurons are clusters.
40  Algorithm is able to process data with Gaussian distribution that has spherical forms.
41 
42  CCORE option can be used to use the pyclustering core - C/C++ shared library for processing that significantly increases performance.
43 
44  Example:
45  @code
46  # load list of points for cluster analysis
47  sample = read_sample(path);
48 
49  # create instance of SOM-SC algorithm to allocated two clusters
50  somsc_instance = somsc(sample, 2);
51 
52  # run cluster analysis and obtain results
53  somsc_instance.process();
54  somsc_instance.get_clusters();
55  @endcode
56 
57  """
58 
59  def __init__(self, data, amount_clusters, epouch = 100, ccore = True):
60  """!
61  @brief Creates SOM-SC (Self Organized Map for Simple Clustering) algorithm for clustering analysis.
62 
63  @param[in] data (list): List of points that are used for processing.
64  @param[in] amount_clusters (uint): Amount of clusters that should be allocated.
65  @param[in] epouch (uint): Number of epochs for training of SOM.
66  @param[in] ccore (bool): If it is True then CCORE implementation will be used for clustering analysis.
67 
68  """
69 
70  self.__data_pointer = data;
71  self.__amount_clusters = amount_clusters;
72  self.__epouch = epouch;
73  self.__ccore = ccore;
74 
75  self.__network = None;
76 
77 
78  def process(self):
79  """!
80  @brief Performs cluster analysis by competition between neurons of SOM.
81 
82  @remark Results of clustering can be obtained using corresponding get methods.
83 
84  @see get_clusters()
85 
86  """
87 
88  self.__network = som(1, self.__amount_clusters, type_conn.grid_four, None, self.__ccore);
89  self.__network.train(self.__data_pointer, self.__epouch, True);
90 
91 
92  def get_clusters(self):
93  """!
94  @brief Returns list of allocated clusters, each cluster contains indexes of objects in list of data.
95 
96  @see process()
97 
98  """
99 
100  return self.__network.capture_objects;
101 
102 
104  """!
105  @brief Returns clustering result representation type that indicate how clusters are encoded.
106 
107  @return (type_encoding) Clustering result representation.
108 
109  @see get_clusters()
110 
111  """
112 
113  return type_encoding.CLUSTER_INDEX_LIST_SEPARATION;
def __init__(self, data, amount_clusters, epouch=100, ccore=True)
Creates SOM-SC (Self Organized Map for Simple Clustering) algorithm for clustering analysis...
Definition: somsc.py:59
def get_cluster_encoding(self)
Returns clustering result representation type that indicate how clusters are encoded.
Definition: somsc.py:103
Module for representing clustering results.
Definition: encoder.py:1
def get_clusters(self)
Returns list of allocated clusters, each cluster contains indexes of objects in list of data...
Definition: somsc.py:92
Class represents simple clustering algorithm based on self-organized feature map. ...
Definition: somsc.py:36
def process(self)
Performs cluster analysis by competition between neurons of SOM.
Definition: somsc.py:78
Neural Network: Self-Organized Feature Map.
Definition: som.py:1
Represents self-organized feature map (SOM).
Definition: som.py:115