3 @brief Cluster analysis algorithm: Hierarchical Sync (HSyncNet) 4 @details Implementation based on paper @cite artcile::hsyncnet::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/>. 28 import pyclustering.core.hsyncnet_wrapper
as wrapper;
30 from pyclustering.core.wrapper
import ccore_library;
41 @brief Class represents clustering algorithm HSyncNet. HSyncNet is bio-inspired algorithm that is based on oscillatory network that uses modified Kuramoto model. 43 @details CCORE option can be used to use the pyclustering core - C/C++ shared library for processing that significantly increases performance. 47 # read list of points for cluster analysis 48 sample = read_sample(file); 50 # create network for allocation three clusters using CCORE (C++ implementation) 51 network = hsyncnet(sample, 3, ccore = True); 53 # run cluster analysis and output dynamic of the network 54 (time, dynamic) = network.process(0.995, collect_dynamic = True); 56 # get allocated clusters 57 clusters = network.get_clusters(); 59 # show output dynamic of the network 60 draw_dynamics(time, dynamic); 64 def __init__(self, source_data, number_clusters, osc_initial_phases = initial_type.RANDOM_GAUSSIAN, initial_neighbors = 3, increase_persent = 0.15, ccore = True):
66 @brief Costructor of the oscillatory network hSyncNet for cluster analysis. 68 @param[in] source_data (list): Input data set defines structure of the network. 69 @param[in] number_clusters (uint): Number of clusters that should be allocated. 70 @param[in] osc_initial_phases (initial_type): Type of initialization of initial values of phases of oscillators. 71 @param[in] initial_neighbors (uint): Defines initial radius connectivity by calculation average distance to connect specify number of oscillators. 72 @param[in] increase_persent (double): Percent of increasing of radius connectivity on each step (input values in range (0.0; 1.0) correspond to (0%; 100%)). 73 @param[in] ccore (bool): If True than DLL CCORE (C++ solution) will be used for solving. 79 if (initial_neighbors >= len(source_data)):
80 initial_neighbors = len(source_data) - 1;
82 if ( (ccore
is True)
and ccore_library.workable() ):
83 self.
__ccore_network_pointer = wrapper.hsyncnet_create_network(source_data, number_clusters, osc_initial_phases, initial_neighbors, increase_persent);
85 super().
__init__(source_data, 0, initial_phases = osc_initial_phases, ccore=
False);
94 @brief Destructor of oscillatory network HSyncNet. 103 def process(self, order = 0.998, solution = solve_type.FAST, collect_dynamic = False):
105 @brief Performs clustering of input data set in line with input parameters. 107 @param[in] order (double): Level of local synchronization between oscillator that defines end of synchronization process, range [0..1]. 108 @param[in] solution (solve_type) Type of solving differential equation. 109 @param[in] collect_dynamic (bool): If True - returns whole history of process synchronization otherwise - only final state (when process of clustering is over). 111 @return (tuple) Returns dynamic of the network as tuple of lists on each iteration (time, oscillator_phases) that depends on collect_dynamic parameter. 122 current_number_clusters = float(
'inf');
127 radius = average_neighbor_distance(self.
_osc_loc, number_neighbors);
130 if (increase_step < 1):
139 if (collect_dynamic ==
True):
140 if (len(dyn_phase) == 0):
145 clusters = analyser.allocate_sync_ensembles(0.05);
148 current_number_clusters = len(clusters);
151 number_neighbors += increase_step;
156 if (collect_dynamic !=
True):
162 def __calculate_radius(self, number_neighbors, radius):
164 @brief Calculate new connectivity radius. 166 @param[in] number_neighbors (uint): Average amount of neighbors that should be connected by new radius. 167 @param[in] radius (double): Current connectivity radius. 169 @return New connectivity radius. 173 if (number_neighbors >= len(self.
_osc_loc)):
176 return average_neighbor_distance(self.
_osc_loc, number_neighbors);
179 def __store_dynamic(self, dyn_phase, dyn_time, analyser, begin_state):
181 @brief Store specified state of Sync network to hSync. 183 @param[in] dyn_phase (list): Output dynamic of hSync where state should be stored. 184 @param[in] dyn_time (list): Time points that correspond to output dynamic where new time point should be stored. 185 @param[in] analyser (syncnet_analyser): Sync analyser where Sync states are stored. 186 @param[in] begin_state (bool): If True the first state of Sync network is stored, otherwise the last state is stored. 190 if (begin_state
is True):
192 dyn_phase.append(analyser.output[0]);
195 dyn_phase.append(analyser.output[len(analyser.output) - 1]);
196 dyn_time.append(len(dyn_time));
def simulate_dynamic(self, order=0.998, solution=solve_type.FAST, collect_dynamic=False, step=0.1, int_step=0.01, threshold_changes=0.0000001)
Performs dynamic simulation of the network until stop condition is not reached.
def __del__(self)
Destructor of oscillatory network HSyncNet.
Utils that are used by modules of pyclustering.
Performs analysis of output dynamic of the oscillatory network syncnet to extract information about c...
def __init__(self, source_data, number_clusters, osc_initial_phases=initial_type.RANDOM_GAUSSIAN, initial_neighbors=3, increase_persent=0.15, ccore=True)
Costructor of the oscillatory network hSyncNet for cluster analysis.
Class represents clustering algorithm SyncNet.
def __calculate_radius(self, number_neighbors, radius)
Calculate new connectivity radius.
def __store_dynamic(self, dyn_phase, dyn_time, analyser, begin_state)
Store specified state of Sync network to hSync.
def process(self, order=0.998, solution=solve_type.FAST, collect_dynamic=False)
Performs clustering of input data set in line with input parameters.
Class represents clustering algorithm HSyncNet.
Cluster analysis algorithm: Sync.
Neural and oscillatory network module.
def _create_connections(self, radius)
Create connections between oscillators in line with input radius of connectivity. ...