3 @brief Cluster analysis algorithm: SYNC-SOM 4 @details Implementation based on paper @cite article::syncsom::1. 6 @authors Andrei Novikov (pyclustering@yandex.ru) 8 @copyright GNU Public License 10 @cond GNU_PUBLIC_LICENSE 11 PyClustering is free software: you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation, either version 3 of the License, or 14 (at your option) any later version. 16 PyClustering is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 21 You should have received a copy of the GNU General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 39 @brief Class represents clustering algorithm SYNC-SOM. SYNC-SOM is bio-inspired algorithm that is based on oscillatory network 40 that uses self-organized feature map as the first layer. 44 # read sample for clustering 45 sample = read_sample(file); 47 # create oscillatory network for cluster analysis where the first layer has 48 # size 10x10 and connectivity radius for objects 1.0. 49 network = syncsom(sample, 10, 10, 1.0); 51 # simulate network (perform cluster analysis) and collect output dynamic 52 (dyn_time, dyn_phase) = network.process(True, 0.998); 54 # obtain encoded clusters 55 encoded_clusters = network.get_som_clusters(); 57 # obtain real clusters 58 clusters = network.get_clusters(); 60 # show the first layer of the network 61 network.show_som_layer(); 63 # show the second layer of the network 64 network.show_sync_layer(); 72 @brief The first layer of the oscillatory network - self-organized feature map. 81 @brief The second layer of the oscillatory network based on Kuramoto model. 89 @brief Constructor of the double layer oscillatory network SYNC-SOM. 91 @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple. 92 @param[in] rows (uint): Rows of neurons (number of neurons in column) in the input layer (self-organized feature map). 93 @param[in] cols (uint): Columns of neurons (number of neurons in row) in the input later (self-organized feature map). 94 @param[in] radius (double): Connectivity radius between objects that defines connection between oscillators in the second layer. 101 self.
_som =
som(rows, cols, conn_type = type_conn.grid_four, ccore =
False);
111 def process(self, collect_dynamic = False, order = 0.999):
113 @brief Performs simulation of the oscillatory network. 115 @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics. 116 @param[in] order (double): Order of process synchronization that should be considered as end of clustering, destributed 0..1. 118 @return (tuple) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time, 119 otherwise returns only last values (last step of simulation) of dynamic. 121 @see get_som_clusters() 131 for i
in range(self.
_som.size):
132 if (self.
_som.awards[i] > 0):
133 weights.append(self.
_som.weights[i]);
143 def __create_sync_layer(self, weights):
145 @brief Creates second layer of the network. 147 @param[in] weights (list): List of weights of SOM neurons. 149 @return (syncnet) Second layer of the network. 152 sync_layer =
syncnet(weights, 0.0, initial_phases = initial_type.RANDOM_GAUSSIAN, ccore =
False);
154 for oscillator_index1
in range(0, len(sync_layer)):
155 for oscillator_index2
in range(oscillator_index1 + 1, len(sync_layer)):
157 sync_layer.set_connection(oscillator_index1, oscillator_index2);
162 def __has_object_connection(self, oscillator_index1, oscillator_index2):
164 @brief Searches for pair of objects that are encoded by specified neurons and that are connected in line with connectivity radius. 166 @param[in] oscillator_index1 (uint): Index of the first oscillator in the second layer. 167 @param[in] oscillator_index2 (uint): Index of the second oscillator in the second layer. 169 @return (bool) True - if there is pair of connected objects encoded by specified oscillators. 175 for index_object1
in self.
_som.capture_objects[som_neuron_index1]:
176 for index_object2
in self.
_som.capture_objects[som_neuron_index2]:
177 distance = euclidean_distance_square(self.
_data[index_object1], self.
_data[index_object2]);
186 @brief Returns clusters with SOM neurons that encode input features in line with result of synchronization in the second (Sync) layer. 188 @return (list) List of clusters that are represented by lists of indexes of neurons that encode input data. 195 sync_clusters = self.
_analyser.allocate_clusters();
198 som_clusters = list();
199 for oscillators
in sync_clusters:
201 for index_oscillator
in oscillators:
203 cluster.append(index_neuron);
205 som_clusters.append(cluster);
212 @brief Returns clusters in line with ensembles of synchronous oscillators where each synchronous ensemble corresponds to only one cluster. 214 @param[in] eps (double): Maximum error for allocation of synchronous ensemble oscillators. 216 @return (list) List of grours (lists) of indexes of synchronous oscillators that corresponds to index of objects. 219 @see get_som_clusters() 223 sync_clusters = self.
_analyser.allocate_clusters(eps)
226 for oscillators
in sync_clusters:
228 for index_oscillator
in oscillators:
231 cluster += self.
_som.capture_objects[index_neuron]
233 clusters.append(cluster)
240 @brief Returns clustering result representation type that indicate how clusters are encoded. 242 @return (type_encoding) Clustering result representation. 248 return type_encoding.CLUSTER_INDEX_LIST_SEPARATION;
253 @brief Shows visual representation of the first (SOM) layer. 257 self.
_som.show_network();
262 @brief Shows visual representation of the second (Sync) layer. 266 self.
_sync.show_network();
def show_som_layer(self)
Shows visual representation of the first (SOM) layer.
def show_sync_layer(self)
Shows visual representation of the second (Sync) layer.
def __init__(self, data, rows, cols, radius)
Constructor of the double layer oscillatory network SYNC-SOM.
Utils that are used by modules of pyclustering.
def get_cluster_encoding(self)
Returns clustering result representation type that indicate how clusters are encoded.
Module for representing clustering results.
Class represents clustering algorithm SyncNet.
def process(self, collect_dynamic=False, order=0.999)
Performs simulation of the oscillatory network.
def som_layer(self)
The first layer of the oscillatory network - self-organized feature map.
def __create_sync_layer(self, weights)
Creates second layer of the network.
def sync_layer(self)
The second layer of the oscillatory network based on Kuramoto model.
def get_clusters(self, eps=0.1)
Returns clusters in line with ensembles of synchronous oscillators where each synchronous ensemble co...
Cluster analysis algorithm: Sync.
def get_som_clusters(self)
Returns clusters with SOM neurons that encode input features in line with result of synchronization i...
Neural Network: Self-Organized Feature Map.
Represents self-organized feature map (SOM).
Class represents clustering algorithm SYNC-SOM.
def __has_object_connection(self, oscillator_index1, oscillator_index2)
Searches for pair of objects that are encoded by specified neurons and that are connected in line wit...
Neural and oscillatory network module.