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