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. 9 @authors Andrei Novikov (pyclustering@yandex.ru) 11 @copyright GNU Public License 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. 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. 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/>. 31 from pyclustering.core.wrapper
import ccore_library
39 @brief Class represents a simple clustering algorithm based on the self-organized feature map. 40 @details This algorithm uses amount of clusters that should be allocated as a size of SOM map. Captured 41 objects by neurons are considered as clusters. The algorithm is designed to process data with Gaussian 42 distribution that has spherical forms. 46 from pyclustering.cluster import cluster_visualizer 47 from pyclustering.cluster.somsc import somsc 48 from pyclustering.samples.definitions import FCPS_SAMPLES 49 from pyclustering.utils import read_sample 51 # Load list of points for cluster analysis 52 sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS) 54 # Create instance of SOM-SC algorithm to allocated two clusters 55 somsc_instance = somsc(sample, 2) 57 # Run cluster analysis and obtain results 58 somsc_instance.process() 59 clusters = somsc_instance.get_clusters() 61 # Visualize clustering results. 62 visualizer = cluster_visualizer() 63 visualizer.append_clusters(clusters, sample) 69 def __init__(self, data, amount_clusters, epouch=100, ccore=True, **kwargs):
71 @brief Creates SOM-SC (Self Organized Map for Simple Clustering) algorithm for clustering analysis. 73 @param[in] data (list): List of points that are used for processing. 74 @param[in] amount_clusters (uint): Amount of clusters that should be allocated. 75 @param[in] epouch (uint): Number of epochs for training of SOM. 76 @param[in] ccore (bool): If it is True then CCORE implementation will be used for clustering analysis. 77 @param[in] **kwargs: Arbitrary keyword arguments (available arguments: `random_state`). 79 <b>Keyword Args:</b><br> 80 - random_state (int): Seed for random state (by default is `None`, current system time is used). 93 self.
__ccore = ccore_library.workable()
100 @brief Performs cluster analysis by competition between neurons in self-organized map. 102 @return (somsc) Returns itself (SOM Simple Clustering instance). 119 @brief Calculates the closest cluster to each point. 121 @param[in] points (array_like): Points for which closest clusters are calculated. 123 @return (list) List of closest clusters for each point. Each cluster is denoted by index. Return empty 124 collection if 'process()' method was not called. 130 index_cluster = self.
__network.simulate(point)
131 result.append(index_cluster)
138 @brief Returns list of allocated clusters, each cluster contains indexes of objects in list of data. 149 @brief Returns clustering result representation type that indicate how clusters are encoded. 151 @return (type_encoding) Clustering result representation. 157 return type_encoding.CLUSTER_INDEX_LIST_SEPARATION
160 def __verify_arguments(self):
162 @brief Verify input parameters for the algorithm and throw exception in case of incorrectness. 166 raise ValueError(
"Input data is empty (size: '%d')." % len(self.
__data_pointer))
169 raise ValueError(
"Amount of clusters (current value: '%d') should be greater than 0." %
173 raise ValueError(
"Amount of epouch (current value: '%d') should be greater or equal to 0." %
def get_cluster_encoding(self)
Returns clustering result representation type that indicate how clusters are encoded.
Represents SOM parameters.
Module for representing clustering results.
def __verify_arguments(self)
Verify input parameters for the algorithm and throw exception in case of incorrectness.
def get_clusters(self)
Returns list of allocated clusters, each cluster contains indexes of objects in list of data...
Class represents a simple clustering algorithm based on the self-organized feature map...
def process(self)
Performs cluster analysis by competition between neurons in self-organized map.
def __init__(self, data, amount_clusters, epouch=100, ccore=True, kwargs)
Creates SOM-SC (Self Organized Map for Simple Clustering) algorithm for clustering analysis...
Neural Network: Self-Organized Feature Map.
def predict(self, points)
Calculates the closest cluster to each point.
Represents self-organized feature map (SOM).