pyclustering  0.10.1
pyclustring is a Python, C++ data mining library.
sync.py
1 """!
2 
3 @brief Neural Network: Oscillatory Neural Network based on Kuramoto model
4 @details Implementation based on paper @cite article::syncnet::1, @cite article::nnet::sync::1, @cite inproceedings::net::sync::1.
5 
6 @authors Andrei Novikov (pyclustering@yandex.ru)
7 @date 2014-2020
8 @copyright BSD-3-Clause
9 
10 """
11 
12 import math
13 import numpy
14 import random
15 
16 import matplotlib.pyplot as plt
17 import matplotlib.animation as animation
18 
19 import pyclustering.core.sync_wrapper as wrapper
20 
21 from pyclustering.core.wrapper import ccore_library
22 
23 from scipy.integrate import odeint
24 
25 from pyclustering.nnet import network, conn_represent, conn_type, initial_type, solve_type
26 from pyclustering.utils import pi, draw_dynamics, draw_dynamics_set, set_ax_param
27 
28 
30  """!
31  @brief Provides services to calculate order parameter and local order parameter that are used
32  for synchronization level estimation.
33 
34  """
35  @staticmethod
36  def calculate_sync_order(oscillator_phases):
37  """!
38  @brief Calculates level of global synchronization (order parameter) for input phases.
39  @details This parameter is tend 1.0 when the oscillatory network close to global synchronization and it tend to 0.0 when
40  desynchronization is observed in the network.
41 
42  @param[in] oscillator_phases (list): List of oscillator phases that are used for level of global synchronization.
43 
44  @return (double) Level of global synchronization (order parameter).
45 
46  @see calculate_order_parameter()
47 
48  """
49 
50  exp_amount = 0.0
51  average_phase = 0.0
52 
53  for phase in oscillator_phases:
54  exp_amount += math.expm1(abs(1j * phase))
55  average_phase += phase
56 
57  exp_amount /= len(oscillator_phases)
58  average_phase = math.expm1(abs(1j * (average_phase / len(oscillator_phases))))
59 
60  return abs(average_phase) / abs(exp_amount)
61 
62 
63  @staticmethod
64  def calculate_local_sync_order(oscillator_phases, oscillatory_network):
65  """!
66  @brief Calculates level of local synchorization (local order parameter) for input phases for the specified network.
67  @details This parameter is tend 1.0 when the oscillatory network close to local synchronization and it tend to 0.0 when
68  desynchronization is observed in the network.
69 
70  @param[in] oscillator_phases (list): List of oscillator phases that are used for level of local (partial) synchronization.
71  @param[in] oscillatory_network (sync): Instance of oscillatory network whose connections are required for calculation.
72 
73  @return (double) Level of local synchronization (local order parameter).
74 
75  """
76 
77  exp_amount = 0.0
78  num_neigh = 0.0
79 
80  for i in range(0, len(oscillatory_network), 1):
81  for j in range(0, len(oscillatory_network), 1):
82  if oscillatory_network.has_connection(i, j) is True:
83  exp_amount += math.exp(-abs(oscillator_phases[j] - oscillator_phases[i]))
84  num_neigh += 1.0
85 
86  if num_neigh == 0:
87  num_neigh = 1.0
88 
89  return exp_amount / num_neigh
90 
91 
92 
94  """!
95  @brief Represents output dynamic of Sync.
96 
97  """
98 
99  @property
100  def output(self):
101  """!
102  @brief (list) Returns output dynamic of the Sync network (phase coordinates of each oscillator in the network) during simulation.
103 
104  """
105  if (self._ccore_sync_dynamic_pointer is not None) and ((self._dynamic is None) or (len(self._dynamic) == 0)):
106  self._dynamic = wrapper.sync_dynamic_get_output(self._ccore_sync_dynamic_pointer)
107 
108  return self._dynamic
109 
110 
111  @property
112  def time(self):
113  """!
114  @brief (list) Returns sampling times when dynamic is measured during simulation.
115 
116  """
117  if (self._ccore_sync_dynamic_pointer is not None) and ((self._time is None) or (len(self._time) == 0)):
118  self._time = wrapper.sync_dynamic_get_time(self._ccore_sync_dynamic_pointer)
119 
120  return self._time
121 
122 
123  def __init__(self, phase, time, ccore=None):
124  """!
125  @brief Constructor of Sync dynamic.
126 
127  @param[in] phase (list): Dynamic of oscillators on each step of simulation. If ccore pointer is specified than it can be ignored.
128  @param[in] time (list): Simulation time.
129  @param[in] ccore (ctypes.pointer): Pointer to CCORE sync_dynamic instance in memory.
130 
131  """
132 
133  self._dynamic = phase
134  self._time = time
135  self._ccore_sync_dynamic_pointer = ccore
136 
137 
138  def __del__(self):
139  """!
140  @brief Default destructor of Sync dynamic.
141 
142  """
143  if self._ccore_sync_dynamic_pointer is not None:
144  wrapper.sync_dynamic_destroy(self._ccore_sync_dynamic_pointer)
145 
146 
147  def __len__(self):
148  """!
149  @brief Returns number of simulation steps that are stored in dynamic.
150  @return (uint) Number of simulation steps that are stored in dynamic.
151 
152  """
153  if (self._ccore_sync_dynamic_pointer is not None):
154  return wrapper.sync_dynamic_get_size(self._ccore_sync_dynamic_pointer)
155 
156  return len(self._dynamic)
157 
158 
159  def __getitem__(self, index):
160  """!
161  @brief Indexing of the dynamic.
162 
163  """
164  if index == 0:
165  return self.time
166 
167  elif index == 1:
168  return self.output
169 
170  else:
171  raise NameError('Out of range ' + index + ': only indexes 0 and 1 are supported.')
172 
173 
174  def allocate_sync_ensembles(self, tolerance = 0.01, indexes = None, iteration = None):
175  """!
176  @brief Allocate clusters in line with ensembles of synchronous oscillators where each synchronous ensemble corresponds to only one cluster.
177 
178  @param[in] tolerance (double): Maximum error for allocation of synchronous ensemble oscillators.
179  @param[in] indexes (list): List of real object indexes and it should be equal to amount of oscillators (in case of 'None' - indexes are in range [0; amount_oscillators]).
180  @param[in] iteration (uint): Iteration of simulation that should be used for allocation.
181 
182  @return (list) Groups (lists) of indexes of synchronous oscillators.
183  For example [ [index_osc1, index_osc3], [index_osc2], [index_osc4, index_osc5] ].
184 
185  """
186 
187  if self._ccore_sync_dynamic_pointer is not None:
188  ensembles = wrapper.sync_dynamic_allocate_sync_ensembles(self._ccore_sync_dynamic_pointer, tolerance, iteration)
189 
190  if indexes is not None:
191  for ensemble in ensembles:
192  for index in range(len(ensemble)):
193  ensemble[index] = indexes[ensemble[index]]
194 
195  return ensembles
196 
197  if (self._dynamic is None) or (len(self._dynamic) == 0):
198  return []
199 
200  number_oscillators = len(self._dynamic[0])
201  last_state = None
202 
203  if iteration is None:
204  last_state = self._dynamic[len(self._dynamic) - 1]
205  else:
206  last_state = self._dynamic[iteration]
207 
208  clusters = []
209  if number_oscillators > 0:
210  clusters.append([0])
211 
212  for i in range(1, number_oscillators, 1):
213  cluster_allocated = False
214  for cluster in clusters:
215  for neuron_index in cluster:
216  last_state_shifted = abs(last_state[i] - 2 * pi)
217 
218  if ( ( (last_state[i] < (last_state[neuron_index] + tolerance)) and (last_state[i] > (last_state[neuron_index] - tolerance)) ) or
219  ( (last_state_shifted < (last_state[neuron_index] + tolerance)) and (last_state_shifted > (last_state[neuron_index] - tolerance)) ) ):
220  cluster_allocated = True
221 
222  real_index = i
223  if indexes is not None:
224  real_index = indexes[i]
225 
226  cluster.append(real_index)
227  break
228 
229  if cluster_allocated is True:
230  break
231 
232  if cluster_allocated is False:
233  clusters.append([i])
234 
235  return clusters
236 
237 
238  def allocate_phase_matrix(self, grid_width = None, grid_height = None, iteration = None):
239  """!
240  @brief Returns 2D matrix of phase values of oscillators at the specified iteration of simulation.
241  @details User should ensure correct matrix sizes in line with following expression grid_width x grid_height that should be equal to
242  amount of oscillators otherwise exception is thrown. If grid_width or grid_height are not specified than phase matrix size
243  will by calculated automatically by square root.
244 
245  @param[in] grid_width (uint): Width of the allocated matrix.
246  @param[in] grid_height (uint): Height of the allocated matrix.
247  @param[in] iteration (uint): Number of iteration of simulation for which correlation matrix should be allocated.
248  If iternation number is not specified, the last step of simulation is used for the matrix allocation.
249 
250  @return (list) Phase value matrix of oscillators with size [number_oscillators x number_oscillators].
251 
252  """
253 
254  output_dynamic = self.output
255 
256  if (output_dynamic is None) or (len(output_dynamic) == 0):
257  return []
258 
259  current_dynamic = output_dynamic[len(output_dynamic) - 1]
260  if iteration is not None:
261  current_dynamic = output_dynamic[iteration]
262 
263  width_matrix = grid_width
264  height_matrix = grid_height
265  number_oscillators = len(current_dynamic)
266  if (width_matrix is None) or (height_matrix is None):
267  width_matrix = int(math.ceil(math.sqrt(number_oscillators)))
268  height_matrix = width_matrix
269 
270  if (number_oscillators != width_matrix * height_matrix):
271  raise NameError("Impossible to allocate phase matrix with specified sizes, amout of neurons should be equal to grid_width * grid_height.");
272 
273  phase_matrix = [[0.0 for _ in range(width_matrix)] for _ in range(height_matrix)]
274  for i in range(height_matrix):
275  for j in range(width_matrix):
276  phase_matrix[i][j] = current_dynamic[j + i * width_matrix]
277 
278  return phase_matrix
279 
280 
281  def allocate_correlation_matrix(self, iteration = None):
282  """!
283  @brief Allocate correlation matrix between oscillators at the specified step of simulation.
284 
285  @param[in] iteration (uint): Number of iteration of simulation for which correlation matrix should be allocated.
286  If iternation number is not specified, the last step of simulation is used for the matrix allocation.
287 
288  @return (list) Correlation matrix between oscillators with size [number_oscillators x number_oscillators].
289 
290  """
291 
292  if self._ccore_sync_dynamic_pointer is not None:
293  return wrapper.sync_dynamic_allocate_correlation_matrix(self._ccore_sync_dynamic_pointer, iteration)
294 
295  if (self._dynamic is None) or (len(self._dynamic) == 0):
296  return []
297 
298  dynamic = self._dynamic
299  current_dynamic = dynamic[len(dynamic) - 1]
300 
301  if iteration is not None:
302  current_dynamic = dynamic[iteration]
303 
304  number_oscillators = len(dynamic[0])
305  affinity_matrix = [[0.0 for i in range(number_oscillators)] for j in range(number_oscillators)]
306 
307  for i in range(number_oscillators):
308  for j in range(number_oscillators):
309  phase1 = current_dynamic[i]
310  phase2 = current_dynamic[j]
311 
312  affinity_matrix[i][j] = abs(math.sin(phase1 - phase2))
313 
314  return affinity_matrix
315 
316 
317  def calculate_order_parameter(self, start_iteration=None, stop_iteration=None):
318  """!
319  @brief Calculates level of global synchorization (order parameter).
320  @details This parameter is tend 1.0 when the oscillatory network close to global synchronization and it tend to 0.0 when
321  desynchronization is observed in the network. Order parameter is calculated using following equation:
322 
323  \f[
324  r_{c}=\frac{1}{Ne^{i\varphi }}\sum_{j=0}^{N}e^{i\theta_{j}};
325  \f]
326 
327  where \f$\varphi\f$ is a average phase coordinate in the network, \f$N\f$ is an amount of oscillators in the network.
328 
329  @param[in] start_iteration (uint): The first iteration that is used for calculation, if 'None' then the last iteration is used.
330  @param[in] stop_iteration (uint): The last iteration that is used for calculation, if 'None' then 'start_iteration' + 1 is used.
331 
332  Example:
333  @code
334  oscillatory_network = sync(16, type_conn = conn_type.ALL_TO_ALL);
335  output_dynamic = oscillatory_network.simulate_static(100, 10);
336 
337  print("Order parameter at the last step: ", output_dynamic.calculate_order_parameter());
338  print("Order parameter at the first step:", output_dynamic.calculate_order_parameter(0));
339  print("Order parameter evolution between 40 and 50 steps:", output_dynamic.calculate_order_parameter(40, 50));
340  @endcode
341 
342  @return (list) List of levels of global synchronization (order parameter evolution).
343 
344  @see order_estimator
345 
346  """
347 
348  (start_iteration, stop_iteration) = self.__get_start_stop_iterations(start_iteration, stop_iteration)
349 
350  if self._ccore_sync_dynamic_pointer is not None:
351  return wrapper.sync_dynamic_calculate_order(self._ccore_sync_dynamic_pointer, start_iteration, stop_iteration)
352 
353  sequence_order = []
354  for index in range(start_iteration, stop_iteration):
355  sequence_order.append(order_estimator.calculate_sync_order(self.output[index]))
356 
357  return sequence_order
358 
359 
360  def calculate_local_order_parameter(self, oscillatory_network, start_iteration = None, stop_iteration = None):
361  """!
362  @brief Calculates local order parameter.
363  @details Local order parameter or so-called level of local or partial synchronization is calculated by following expression:
364 
365  \f[
366  r_{c}=\left | \sum_{i=0}^{N} \frac{1}{N_{i}} \sum_{j=0}e^{ \theta_{j} - \theta_{i} } \right |;
367  \f]
368 
369  where N - total amount of oscillators in the network and \f$N_{i}\f$ - amount of neighbors of oscillator with index \f$i\f$.
370 
371  @param[in] oscillatory_network (sync): Sync oscillatory network whose structure of connections is required for calculation.
372  @param[in] start_iteration (uint): The first iteration that is used for calculation, if 'None' then the last iteration is used.
373  @param[in] stop_iteration (uint): The last iteration that is used for calculation, if 'None' then 'start_iteration' + 1 is used.
374 
375  @return (list) List of levels of local (partial) synchronization (local order parameter evolution).
376 
377  """
378 
379  (start_iteration, stop_iteration) = self.__get_start_stop_iterations(start_iteration, stop_iteration)
380 
381  if self._ccore_sync_dynamic_pointer is not None:
382  network_pointer = oscillatory_network._ccore_network_pointer
383  return wrapper.sync_dynamic_calculate_local_order(self._ccore_sync_dynamic_pointer, network_pointer, start_iteration, stop_iteration)
384 
385  sequence_local_order = []
386  for index in range(start_iteration, stop_iteration):
387  sequence_local_order.append(order_estimator.calculate_local_sync_order(self.output[index], oscillatory_network))
388 
389  return sequence_local_order
390 
391 
392  def __get_start_stop_iterations(self, start_iteration, stop_iteration):
393  """!
394  @brief Aplly rules for start_iteration and stop_iteration parameters.
395 
396  @param[in] start_iteration (uint): The first iteration that is used for calculation.
397  @param[in] stop_iteration (uint): The last iteration that is used for calculation.
398 
399  @return (tuple) New the first iteration and the last.
400 
401  """
402  if start_iteration is None:
403  start_iteration = len(self) - 1
404 
405  if stop_iteration is None:
406  stop_iteration = start_iteration + 1
407 
408  return start_iteration, stop_iteration
409 
410 
411 
413  """!
414  @brief Visualizer of output dynamic of sync network (Sync).
415 
416  """
417 
418  @staticmethod
419  def show_output_dynamic(sync_output_dynamic):
420  """!
421  @brief Shows output dynamic (output of each oscillator) during simulation.
422 
423  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
424 
425  @see show_output_dynamics
426 
427  """
428 
429  draw_dynamics(sync_output_dynamic.time, sync_output_dynamic.output, x_title="t", y_title="phase", y_lim=[0, 2 * 3.14])
430 
431 
432  @staticmethod
433  def show_output_dynamics(sync_output_dynamics):
434  """!
435  @brief Shows several output dynamics (output of each oscillator) during simulation.
436  @details Each dynamic is presented on separate plot.
437 
438  @param[in] sync_output_dynamics (list): list of output dynamics 'sync_dynamic' of the Sync network.
439 
440  @see show_output_dynamic
441 
442  """
443 
444  draw_dynamics_set(sync_output_dynamics, "t", "phase", None, [0, 2 * 3.14], False, False)
445 
446 
447  @staticmethod
448  def show_correlation_matrix(sync_output_dynamic, iteration=None):
449  """!
450  @brief Shows correlation matrix between oscillators at the specified iteration.
451 
452  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
453  @param[in] iteration (uint): Number of iteration of simulation for which correlation matrix should be
454  allocated. If iteration number is not specified, the last step of simulation is used for the matrix
455  allocation.
456 
457  """
458 
459  _ = plt.figure()
460  correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(iteration)
461 
462  plt.imshow(correlation_matrix, cmap = plt.get_cmap('cool'), interpolation='kaiser', vmin=0.0, vmax=1.0)
463  plt.show()
464 
465 
466  @staticmethod
467  def show_phase_matrix(sync_output_dynamic, grid_width=None, grid_height=None, iteration=None):
468  """!
469  @brief Shows 2D matrix of phase values of oscillators at the specified iteration.
470  @details User should ensure correct matrix sizes in line with following expression grid_width x grid_height that should be equal to
471  amount of oscillators otherwise exception is thrown. If grid_width or grid_height are not specified than phase matrix size
472  will by calculated automatically by square root.
473 
474  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network whose phase matrix should be shown.
475  @param[in] grid_width (uint): Width of the phase matrix.
476  @param[in] grid_height (uint): Height of the phase matrix.
477  @param[in] iteration (uint): Number of iteration of simulation for which correlation matrix should be allocated.
478  If iternation number is not specified, the last step of simulation is used for the matrix allocation.
479 
480  """
481 
482  _ = plt.figure()
483  phase_matrix = sync_output_dynamic.allocate_phase_matrix(grid_width, grid_height, iteration)
484 
485  plt.imshow(phase_matrix, cmap = plt.get_cmap('jet'), interpolation='kaiser', vmin=0.0, vmax=2.0 * math.pi)
486  plt.show()
487 
488 
489  @staticmethod
490  def show_order_parameter(sync_output_dynamic, start_iteration=None, stop_iteration=None):
491  """!
492  @brief Shows evolution of order parameter (level of global synchronization in the network).
493 
494  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network whose evolution of global synchronization should be visualized.
495  @param[in] start_iteration (uint): The first iteration that is used for calculation, if 'None' then the first is used
496  @param[in] stop_iteration (uint): The last iteration that is used for calculation, if 'None' then the last is used.
497 
498  """
499 
500  (start_iteration, stop_iteration) = sync_visualizer.__get_start_stop_iterations(sync_output_dynamic, start_iteration, stop_iteration)
501 
502  order_parameter = sync_output_dynamic.calculate_order_parameter(start_iteration, stop_iteration)
503  axis = plt.subplot(111)
504  plt.plot(sync_output_dynamic.time[start_iteration:stop_iteration], order_parameter, 'b-', linewidth=2.0)
505  set_ax_param(axis, "t", "R (order parameter)", None, [0.0, 1.05])
506 
507  plt.show()
508 
509 
510  @staticmethod
511  def show_local_order_parameter(sync_output_dynamic, oscillatory_network, start_iteration=None, stop_iteration=None):
512  """!
513  @brief Shows evolution of local order parameter (level of local synchronization in the network).
514 
515  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network whose evolution of global synchronization should be visualized.
516  @param[in] oscillatory_network (sync): Sync oscillatory network whose structure of connections is required for calculation.
517  @param[in] start_iteration (uint): The first iteration that is used for calculation, if 'None' then the first is used
518  @param[in] stop_iteration (uint): The last iteration that is used for calculation, if 'None' then the last is used.
519 
520  """
521  (start_iteration, stop_iteration) = sync_visualizer.__get_start_stop_iterations(sync_output_dynamic, start_iteration, stop_iteration)
522 
523  order_parameter = sync_output_dynamic.calculate_local_order_parameter(oscillatory_network, start_iteration, stop_iteration)
524  axis = plt.subplot(111)
525  plt.plot(sync_output_dynamic.time[start_iteration:stop_iteration], order_parameter, 'b-', linewidth=2.0)
526  set_ax_param(axis, "t", "R (local order parameter)", None, [0.0, 1.05])
527 
528  plt.show()
529 
530 
531  @staticmethod
532  def animate_output_dynamic(sync_output_dynamic, animation_velocity = 75, save_movie = None):
533  """!
534  @brief Shows animation of output dynamic (output of each oscillator) during simulation on a circle from [0; 2pi].
535 
536  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
537  @param[in] animation_velocity (uint): Interval between frames in milliseconds.
538  @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
539 
540  """
541 
542  figure = plt.figure()
543 
544  dynamic = sync_output_dynamic.output[0]
545  artist, = plt.polar(dynamic, [1.0] * len(dynamic), 'o', color='blue')
546 
547  def init_frame():
548  return [artist]
549 
550  def frame_generation(index_dynamic):
551  dynamic = sync_output_dynamic.output[index_dynamic]
552  artist.set_data(dynamic, [1.0] * len(dynamic))
553 
554  return [artist]
555 
556  phase_animation = animation.FuncAnimation(figure, frame_generation, len(sync_output_dynamic), interval = animation_velocity, init_func = init_frame, repeat_delay = 5000);
557 
558  if save_movie is not None:
559  phase_animation.save(save_movie, writer='ffmpeg', fps=15, bitrate=1500)
560  else:
561  plt.show()
562 
563 
564  @staticmethod
565  def animate_correlation_matrix(sync_output_dynamic, animation_velocity = 75, colormap = 'cool', save_movie = None):
566  """!
567  @brief Shows animation of correlation matrix between oscillators during simulation.
568 
569  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
570  @param[in] animation_velocity (uint): Interval between frames in milliseconds.
571  @param[in] colormap (string): Name of colormap that is used by matplotlib ('gray', 'pink', 'cool', spring', etc.).
572  @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
573 
574  """
575 
576  figure = plt.figure()
577 
578  correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(0)
579  artist = plt.imshow(correlation_matrix, cmap = plt.get_cmap(colormap), interpolation='kaiser', vmin = 0.0, vmax = 1.0)
580 
581  def init_frame():
582  return [ artist ]
583 
584  def frame_generation(index_dynamic):
585  correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(index_dynamic)
586  artist.set_data(correlation_matrix)
587 
588  return [artist]
589 
590  correlation_animation = animation.FuncAnimation(figure, frame_generation, len(sync_output_dynamic), init_func = init_frame, interval = animation_velocity , repeat_delay = 1000, blit = True)
591 
592  if save_movie is not None:
593  correlation_animation.save(save_movie, writer='ffmpeg', fps=15, bitrate=1500)
594  else:
595  plt.show()
596 
597 
598  @staticmethod
599  def animate_phase_matrix(sync_output_dynamic, grid_width=None, grid_height=None, animation_velocity=75, colormap='jet', save_movie=None):
600  """!
601  @brief Shows animation of phase matrix between oscillators during simulation on 2D stage.
602  @details If grid_width or grid_height are not specified than phase matrix size will by calculated automatically by square root.
603 
604  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
605  @param[in] grid_width (uint): Width of the phase matrix.
606  @param[in] grid_height (uint): Height of the phase matrix.
607  @param[in] animation_velocity (uint): Interval between frames in milliseconds.
608  @param[in] colormap (string): Name of colormap that is used by matplotlib ('gray', 'pink', 'cool', spring', etc.).
609  @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
610 
611  """
612 
613  figure = plt.figure()
614 
615  def init_frame():
616  return frame_generation(0)
617 
618  def frame_generation(index_dynamic):
619  figure.clf()
620  axis = figure.add_subplot(111)
621 
622  phase_matrix = sync_output_dynamic.allocate_phase_matrix(grid_width, grid_height, index_dynamic)
623  axis.imshow(phase_matrix, cmap=plt.get_cmap(colormap), interpolation='kaiser', vmin=0.0, vmax=2.0 * math.pi)
624  artist = figure.gca()
625 
626  return [artist]
627 
628  phase_animation = animation.FuncAnimation(figure, frame_generation, len(sync_output_dynamic), init_func = init_frame, interval = animation_velocity , repeat_delay = 1000);
629 
630  if save_movie is not None:
631  phase_animation.save(save_movie, writer='ffmpeg', fps=15, bitrate=1500)
632  else:
633  plt.show()
634 
635 
636  @staticmethod
637  def __get_start_stop_iterations(sync_output_dynamic, start_iteration, stop_iteration):
638  """!
639  @brief Apply rule of preparation for start iteration and stop iteration values.
640 
641  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
642  @param[in] start_iteration (uint): The first iteration that is used for calculation.
643  @param[in] stop_iteration (uint): The last iteration that is used for calculation.
644 
645  @return (tuple) New values of start and stop iterations.
646 
647  """
648  if start_iteration is None:
649  start_iteration = 0
650 
651  if stop_iteration is None:
652  stop_iteration = len(sync_output_dynamic)
653 
654  return start_iteration, stop_iteration
655 
656 
657  @staticmethod
658  def animate(sync_output_dynamic, title=None, save_movie=None):
659  """!
660  @brief Shows animation of phase coordinates and animation of correlation matrix together for the Sync dynamic output on the same figure.
661 
662  @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
663  @param[in] title (string): Title of the animation that is displayed on a figure if it is specified.
664  @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
665 
666  """
667 
668  dynamic = sync_output_dynamic.output[0]
669  correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(0)
670 
671  figure = plt.figure(1)
672  if title is not None:
673  figure.suptitle(title, fontsize = 26, fontweight = 'bold')
674 
675  ax1 = figure.add_subplot(121, projection='polar')
676  ax2 = figure.add_subplot(122)
677 
678  artist1, = ax1.plot(dynamic, [1.0] * len(dynamic), marker='o', color='blue', ls='')
679  artist2 = ax2.imshow(correlation_matrix, cmap = plt.get_cmap('Accent'), interpolation='kaiser')
680 
681  def init_frame():
682  return [artist1, artist2]
683 
684  def frame_generation(index_dynamic):
685  dynamic = sync_output_dynamic.output[index_dynamic]
686  artist1.set_data(dynamic, [1.0] * len(dynamic))
687 
688  correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(index_dynamic)
689  artist2.set_data(correlation_matrix)
690 
691  return [artist1, artist2]
692 
693  dynamic_animation = animation.FuncAnimation(figure, frame_generation, len(sync_output_dynamic), interval=75, init_func=init_frame, repeat_delay=5000)
694 
695  if save_movie is not None:
696  dynamic_animation.save(save_movie, writer='ffmpeg', fps=15, bitrate=1500)
697  else:
698  plt.show()
699 
700 
701 
703  """!
704  @brief Model of oscillatory network that is based on the Kuramoto model of synchronization.
705 
706  @details CCORE option can be used to use the pyclustering core - C/C++ shared library for processing that significantly increases performance.
707 
708  """
709 
710  def __init__(self, num_osc, weight = 1, frequency = 0, type_conn = conn_type.ALL_TO_ALL, representation = conn_represent.MATRIX, initial_phases = initial_type.RANDOM_GAUSSIAN, ccore = True):
711  """!
712  @brief Constructor of oscillatory network is based on Kuramoto model.
713 
714  @param[in] num_osc (uint): Number of oscillators in the network.
715  @param[in] weight (double): Coupling strength of the links between oscillators.
716  @param[in] frequency (double): Multiplier of internal frequency of the oscillators.
717  @param[in] type_conn (conn_type): Type of connection between oscillators in the network (all-to-all, grid, bidirectional list, etc.).
718  @param[in] representation (conn_represent): Internal representation of connection in the network: matrix or list.
719  @param[in] initial_phases (initial_type): Type of initialization of initial phases of oscillators (random, uniformly distributed, etc.).
720  @param[in] ccore (bool): If True simulation is performed by CCORE library (C++ implementation of pyclustering).
721 
722  """
723 
724  self._ccore_network_pointer = None; # Pointer to CCORE Sync implementation of the network.
725 
726  if ( (ccore is True) and ccore_library.workable() ):
727  self._ccore_network_pointer = wrapper.sync_create_network(num_osc, weight, frequency, type_conn, initial_phases);
728  self._num_osc = num_osc;
729  self._conn_represent = conn_represent.MATRIX;
730 
731  else:
732  super().__init__(num_osc, type_conn, representation);
733 
734  self._weight = weight;
735 
736  self._phases = list();
737  self._freq = list();
738 
739  random.seed();
740  for index in range(0, num_osc, 1):
741  if (initial_phases == initial_type.RANDOM_GAUSSIAN):
742  self._phases.append(random.random() * 2 * pi);
743 
744  elif (initial_phases == initial_type.EQUIPARTITION):
745  self._phases.append( pi / num_osc * index);
746 
747  self._freq.append(random.random() * frequency);
748 
749 
750  def __del__(self):
751  """!
752  @brief Destructor of oscillatory network is based on Kuramoto model.
753 
754  """
755 
756  if (self._ccore_network_pointer is not None):
757  wrapper.sync_destroy_network(self._ccore_network_pointer);
758  self._ccore_network_pointer = None;
759 
760 
761  def sync_order(self):
762  """!
763  @brief Calculates current level of global synchorization (order parameter) in the network.
764  @details This parameter is tend 1.0 when the oscillatory network close to global synchronization and it tend to 0.0 when
765  desynchronization is observed in the network. Order parameter is calculated using following equation:
766 
767  \f[
768  r_{c}=\frac{1}{Ne^{i\varphi }}\sum_{j=0}^{N}e^{i\theta_{j}};
769  \f]
770 
771  where \f$\varphi\f$ is a average phase coordinate in the network, \f$N\f$ is an amount of oscillators in the network.
772 
773  Example:
774  @code
775  oscillatory_network = sync(16, type_conn = conn_type.ALL_TO_ALL);
776  output_dynamic = oscillatory_network.simulate_static(100, 10);
777 
778  if (oscillatory_network.sync_order() < 0.9): print("Global synchronization is not reached yet.");
779  else: print("Global synchronization is reached.");
780  @endcode
781 
782  @return (double) Level of global synchronization (order parameter).
783 
784  @see sync_local_order()
785 
786  """
787 
788  if (self._ccore_network_pointer is not None):
789  return wrapper.sync_order(self._ccore_network_pointer);
790 
791  return order_estimator.calculate_sync_order(self._phases);
792 
793 
794  def sync_local_order(self):
795  """!
796  @brief Calculates current level of local (partial) synchronization in the network.
797 
798  @return (double) Level of local (partial) synchronization.
799 
800  @see sync_order()
801 
802  """
803 
804  if (self._ccore_network_pointer is not None):
805  return wrapper.sync_local_order(self._ccore_network_pointer);
806 
807  return order_estimator.calculate_local_sync_order(self._phases, self);
808 
809 
810  def _phase_kuramoto(self, teta, t, argv):
811  """!
812  @brief Returns result of phase calculation for specified oscillator in the network.
813 
814  @param[in] teta (double): Phase of the oscillator that is differentiated.
815  @param[in] t (double): Current time of simulation.
816  @param[in] argv (tuple): Index of the oscillator in the list.
817 
818  @return (double) New phase for specified oscillator (don't assign here).
819 
820  """
821 
822  index = argv;
823  phase = 0;
824  for k in range(0, self._num_osc):
825  if (self.has_connection(index, k) == True):
826  phase += math.sin(self._phases[k] - teta);
827 
828  return ( self._freq[index] + (phase * self._weight / self._num_osc) );
829 
830 
831  def simulate(self, steps, time, solution = solve_type.FAST, collect_dynamic = True):
832  """!
833  @brief Performs static simulation of Sync oscillatory network.
834 
835  @param[in] steps (uint): Number steps of simulations during simulation.
836  @param[in] time (double): Time of simulation.
837  @param[in] solution (solve_type): Type of solution (solving).
838  @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics.
839 
840  @return (list) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time,
841  otherwise returns only last values (last step of simulation) of dynamic.
842 
843  @see simulate_dynamic()
844  @see simulate_static()
845 
846  """
847 
848  return self.simulate_static(steps, time, solution, collect_dynamic);
849 
850 
851  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):
852  """!
853  @brief Performs dynamic simulation of the network until stop condition is not reached. Stop condition is defined by input argument 'order'.
854 
855  @param[in] order (double): Order of process synchronization, distributed 0..1.
856  @param[in] solution (solve_type): Type of solution.
857  @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics.
858  @param[in] step (double): Time step of one iteration of simulation.
859  @param[in] int_step (double): Integration step, should be less than step.
860  @param[in] threshold_changes (double): Additional stop condition that helps prevent infinite simulation, defines limit of changes of oscillators between current and previous steps.
861 
862  @return (list) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time,
863  otherwise returns only last values (last step of simulation) of dynamic.
864 
865  @see simulate()
866  @see simulate_static()
867 
868  """
869 
870  if (self._ccore_network_pointer is not None):
871  ccore_instance_dynamic = wrapper.sync_simulate_dynamic(self._ccore_network_pointer, order, solution, collect_dynamic, step, int_step, threshold_changes);
872  return sync_dynamic(None, None, ccore_instance_dynamic);
873 
874  # For statistics and integration
875  time_counter = 0;
876 
877  # Prevent infinite loop. It's possible when required state cannot be reached.
878  previous_order = 0;
879  current_order = self.sync_local_order();
880 
881  # If requested input dynamics
882  dyn_phase = [];
883  dyn_time = [];
884  if (collect_dynamic == True):
885  dyn_phase.append(self._phases);
886  dyn_time.append(0);
887 
888  # Execute until sync state will be reached
889  while (current_order < order):
890  # update states of oscillators
891  self._phases = self._calculate_phases(solution, time_counter, step, int_step);
892 
893  # update time
894  time_counter += step;
895 
896  # if requested input dynamic
897  if (collect_dynamic == True):
898  dyn_phase.append(self._phases);
899  dyn_time.append(time_counter);
900 
901  # update orders
902  previous_order = current_order;
903  current_order = self.sync_local_order();
904 
905  # hang prevention
906  if (abs(current_order - previous_order) < threshold_changes):
907  # print("Warning: sync_network::simulate_dynamic - simulation is aborted due to low level of convergence rate (order = " + str(current_order) + ").");
908  break;
909 
910  if (collect_dynamic != True):
911  dyn_phase.append(self._phases);
912  dyn_time.append(time_counter);
913 
914  output_sync_dynamic = sync_dynamic(dyn_phase, dyn_time, None);
915  return output_sync_dynamic;
916 
917 
918  def simulate_static(self, steps, time, solution = solve_type.FAST, collect_dynamic = False):
919  """!
920  @brief Performs static simulation of oscillatory network.
921 
922  @param[in] steps (uint): Number steps of simulations during simulation.
923  @param[in] time (double): Time of simulation.
924  @param[in] solution (solve_type): Type of solution.
925  @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics.
926 
927  @return (list) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time,
928  otherwise returns only last values (last step of simulation) of dynamic.
929 
930  @see simulate()
931  @see simulate_dynamic()
932 
933  """
934 
935  if (self._ccore_network_pointer is not None):
936  ccore_instance_dynamic = wrapper.sync_simulate_static(self._ccore_network_pointer, steps, time, solution, collect_dynamic);
937  return sync_dynamic(None, None, ccore_instance_dynamic);
938 
939  dyn_phase = [];
940  dyn_time = [];
941 
942  if (collect_dynamic == True):
943  dyn_phase.append(self._phases);
944  dyn_time.append(0);
945 
946  step = time / steps;
947  int_step = step / 10.0;
948 
949  for t in numpy.arange(step, time + step, step):
950  # update states of oscillators
951  self._phases = self._calculate_phases(solution, t, step, int_step);
952 
953  # update states of oscillators
954  if (collect_dynamic == True):
955  dyn_phase.append(self._phases);
956  dyn_time.append(t);
957 
958  if (collect_dynamic != True):
959  dyn_phase.append(self._phases);
960  dyn_time.append(time);
961 
962  output_sync_dynamic = sync_dynamic(dyn_phase, dyn_time);
963  return output_sync_dynamic;
964 
965 
966  def _calculate_phases(self, solution, t, step, int_step):
967  """!
968  @brief Calculates new phases for oscillators in the network in line with current step.
969 
970  @param[in] solution (solve_type): Type solver of the differential equation.
971  @param[in] t (double): Time of simulation.
972  @param[in] step (double): Step of solution at the end of which states of oscillators should be calculated.
973  @param[in] int_step (double): Step differentiation that is used for solving differential equation.
974 
975  @return (list) New states (phases) for oscillators.
976 
977  """
978 
979  next_phases = [0.0] * self._num_osc; # new oscillator _phases
980 
981  for index in range (0, self._num_osc, 1):
982  if (solution == solve_type.FAST):
983  result = self._phases[index] + self._phase_kuramoto(self._phases[index], 0, index);
984  next_phases[index] = self._phase_normalization(result);
985 
986  elif ( (solution == solve_type.RK4) or (solution == solve_type.RKF45) ):
987  result = odeint(self._phase_kuramoto, self._phases[index], numpy.arange(t - step, t, int_step), (index , ));
988  next_phases[index] = self._phase_normalization(result[len(result) - 1][0]);
989 
990  else:
991  raise NameError("Solver '" + str(solution) + "' is not supported");
992 
993  return next_phases;
994 
995 
996  def _phase_normalization(self, teta):
997  """!
998  @brief Normalization of phase of oscillator that should be placed between [0; 2 * pi].
999 
1000  @param[in] teta (double): phase of oscillator.
1001 
1002  @return (double) Normalized phase.
1003 
1004  """
1005 
1006  norm_teta = teta;
1007  while (norm_teta > (2.0 * pi)) or (norm_teta < 0):
1008  if (norm_teta > (2.0 * pi)):
1009  norm_teta -= 2.0 * pi;
1010  else:
1011  norm_teta += 2.0 * pi;
1012 
1013  return norm_teta;
1014 
1015 
1016  def get_neighbors(self, index):
1017  """!
1018  @brief Finds neighbors of the oscillator with specified index.
1019 
1020  @param[in] index (uint): index of oscillator for which neighbors should be found in the network.
1021 
1022  @return (list) Indexes of neighbors of the specified oscillator.
1023 
1024  """
1025 
1026  if ( (self._ccore_network_pointer is not None) and (self._osc_conn is None) ):
1027  self._osc_conn = wrapper.sync_connectivity_matrix(self._ccore_network_pointer);
1028 
1029  return super().get_neighbors(index);
1030 
1031 
1032  def has_connection(self, i, j):
1033  """!
1034  @brief Returns True if there is connection between i and j oscillators and False - if connection doesn't exist.
1035 
1036  @param[in] i (uint): index of an oscillator in the network.
1037  @param[in] j (uint): index of an oscillator in the network.
1038 
1039  """
1040 
1041  if ( (self._ccore_network_pointer is not None) and (self._osc_conn is None) ):
1042  self._osc_conn = wrapper.sync_connectivity_matrix(self._ccore_network_pointer);
1043 
1044  return super().has_connection(i, j);
pyclustering.nnet.sync.sync_dynamic
Represents output dynamic of Sync.
Definition: sync.py:93
pyclustering.nnet.sync.sync_visualizer.show_order_parameter
def show_order_parameter(sync_output_dynamic, start_iteration=None, stop_iteration=None)
Shows evolution of order parameter (level of global synchronization in the network).
Definition: sync.py:490
pyclustering.nnet.network._osc_conn
_osc_conn
Definition: __init__.py:90
pyclustering.nnet.sync.sync_network.simulate_dynamic
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.
Definition: sync.py:851
pyclustering.nnet.sync.sync_dynamic._dynamic
_dynamic
Definition: sync.py:106
pyclustering.nnet.sync.sync_network._freq
_freq
Definition: sync.py:737
pyclustering.nnet.sync.sync_network.has_connection
def has_connection(self, i, j)
Returns True if there is connection between i and j oscillators and False - if connection doesn't exi...
Definition: sync.py:1032
pyclustering.nnet.sync.sync_dynamic.calculate_order_parameter
def calculate_order_parameter(self, start_iteration=None, stop_iteration=None)
Calculates level of global synchorization (order parameter).
Definition: sync.py:317
pyclustering.nnet.sync.sync_network._ccore_network_pointer
_ccore_network_pointer
Definition: sync.py:724
pyclustering.nnet.sync.sync_network
Model of oscillatory network that is based on the Kuramoto model of synchronization.
Definition: sync.py:702
pyclustering.nnet.sync.sync_network._calculate_phases
def _calculate_phases(self, solution, t, step, int_step)
Calculates new phases for oscillators in the network in line with current step.
Definition: sync.py:966
pyclustering.nnet.sync.order_estimator.calculate_local_sync_order
def calculate_local_sync_order(oscillator_phases, oscillatory_network)
Calculates level of local synchorization (local order parameter) for input phases for the specified n...
Definition: sync.py:64
pyclustering.nnet.sync.sync_visualizer.show_output_dynamic
def show_output_dynamic(sync_output_dynamic)
Shows output dynamic (output of each oscillator) during simulation.
Definition: sync.py:419
pyclustering.nnet.sync.order_estimator
Provides services to calculate order parameter and local order parameter that are used for synchroniz...
Definition: sync.py:29
pyclustering.nnet.network._num_osc
int _num_osc
Definition: __init__.py:88
pyclustering.nnet.sync.sync_visualizer.show_correlation_matrix
def show_correlation_matrix(sync_output_dynamic, iteration=None)
Shows correlation matrix between oscillators at the specified iteration.
Definition: sync.py:448
pyclustering.nnet.sync.sync_dynamic.__del__
def __del__(self)
Default destructor of Sync dynamic.
Definition: sync.py:138
pyclustering.nnet.sync.sync_dynamic.__len__
def __len__(self)
Returns number of simulation steps that are stored in dynamic.
Definition: sync.py:147
pyclustering.nnet.sync.sync_dynamic._ccore_sync_dynamic_pointer
_ccore_sync_dynamic_pointer
Definition: sync.py:135
pyclustering.nnet.sync.sync_visualizer.show_local_order_parameter
def show_local_order_parameter(sync_output_dynamic, oscillatory_network, start_iteration=None, stop_iteration=None)
Shows evolution of local order parameter (level of local synchronization in the network).
Definition: sync.py:511
pyclustering.nnet.sync.sync_dynamic.__init__
def __init__(self, phase, time, ccore=None)
Constructor of Sync dynamic.
Definition: sync.py:123
pyclustering.nnet.sync.sync_network.simulate_static
def simulate_static(self, steps, time, solution=solve_type.FAST, collect_dynamic=False)
Performs static simulation of oscillatory network.
Definition: sync.py:918
pyclustering.nnet.network._conn_represent
_conn_represent
Definition: __init__.py:91
pyclustering.nnet.sync.sync_dynamic.time
def time(self)
(list) Returns sampling times when dynamic is measured during simulation.
Definition: sync.py:112
pyclustering.nnet.network
Common network description that consists of information about oscillators and connection between them...
Definition: __init__.py:82
pyclustering.nnet.sync.sync_dynamic.__get_start_stop_iterations
def __get_start_stop_iterations(self, start_iteration, stop_iteration)
Aplly rules for start_iteration and stop_iteration parameters.
Definition: sync.py:392
pyclustering.nnet.network.has_connection
def has_connection(self, i, j)
Returns True if there is connection between i and j oscillators and False - if connection doesn't exi...
Definition: __init__.py:351
pyclustering.nnet.sync.order_estimator.calculate_sync_order
def calculate_sync_order(oscillator_phases)
Calculates level of global synchronization (order parameter) for input phases.
Definition: sync.py:36
pyclustering.nnet.sync.sync_visualizer.animate
def animate(sync_output_dynamic, title=None, save_movie=None)
Shows animation of phase coordinates and animation of correlation matrix together for the Sync dynami...
Definition: sync.py:658
pyclustering.nnet.sync.sync_visualizer.animate_correlation_matrix
def animate_correlation_matrix(sync_output_dynamic, animation_velocity=75, colormap='cool', save_movie=None)
Shows animation of correlation matrix between oscillators during simulation.
Definition: sync.py:565
pyclustering.nnet.sync.sync_dynamic.__getitem__
def __getitem__(self, index)
Indexing of the dynamic.
Definition: sync.py:159
pyclustering.nnet.sync.sync_network._phase_normalization
def _phase_normalization(self, teta)
Normalization of phase of oscillator that should be placed between [0; 2 * pi].
Definition: sync.py:996
pyclustering.nnet.sync.sync_dynamic.calculate_local_order_parameter
def calculate_local_order_parameter(self, oscillatory_network, start_iteration=None, stop_iteration=None)
Calculates local order parameter.
Definition: sync.py:360
pyclustering.nnet.sync.sync_network.__del__
def __del__(self)
Destructor of oscillatory network is based on Kuramoto model.
Definition: sync.py:750
pyclustering.nnet.sync.sync_visualizer.animate_output_dynamic
def animate_output_dynamic(sync_output_dynamic, animation_velocity=75, save_movie=None)
Shows animation of output dynamic (output of each oscillator) during simulation on a circle from [0; ...
Definition: sync.py:532
pyclustering.nnet.sync.sync_dynamic._time
_time
Definition: sync.py:118
pyclustering.nnet.sync.sync_dynamic.allocate_correlation_matrix
def allocate_correlation_matrix(self, iteration=None)
Allocate correlation matrix between oscillators at the specified step of simulation.
Definition: sync.py:281
pyclustering.nnet.sync.sync_visualizer.animate_phase_matrix
def animate_phase_matrix(sync_output_dynamic, grid_width=None, grid_height=None, animation_velocity=75, colormap='jet', save_movie=None)
Shows animation of phase matrix between oscillators during simulation on 2D stage.
Definition: sync.py:599
pyclustering.nnet
Neural and oscillatory network module. Consists of models of bio-inspired networks.
Definition: __init__.py:1
pyclustering.nnet.sync.sync_visualizer.show_phase_matrix
def show_phase_matrix(sync_output_dynamic, grid_width=None, grid_height=None, iteration=None)
Shows 2D matrix of phase values of oscillators at the specified iteration.
Definition: sync.py:467
pyclustering.nnet.sync.sync_network.simulate
def simulate(self, steps, time, solution=solve_type.FAST, collect_dynamic=True)
Performs static simulation of Sync oscillatory network.
Definition: sync.py:831
pyclustering.nnet.sync.sync_network.sync_local_order
def sync_local_order(self)
Calculates current level of local (partial) synchronization in the network.
Definition: sync.py:794
pyclustering.nnet.sync.sync_network._weight
_weight
Definition: sync.py:734
pyclustering.nnet.sync.sync_network.sync_order
def sync_order(self)
Calculates current level of global synchorization (order parameter) in the network.
Definition: sync.py:761
pyclustering.nnet.sync.sync_visualizer
Visualizer of output dynamic of sync network (Sync).
Definition: sync.py:412
pyclustering.nnet.sync.sync_dynamic.output
def output(self)
(list) Returns output dynamic of the Sync network (phase coordinates of each oscillator in the networ...
Definition: sync.py:100
pyclustering.nnet.sync.sync_network.get_neighbors
def get_neighbors(self, index)
Finds neighbors of the oscillator with specified index.
Definition: sync.py:1016
pyclustering.nnet.sync.sync_dynamic.allocate_sync_ensembles
def allocate_sync_ensembles(self, tolerance=0.01, indexes=None, iteration=None)
Allocate clusters in line with ensembles of synchronous oscillators where each synchronous ensemble c...
Definition: sync.py:174
pyclustering.utils
Utils that are used by modules of pyclustering.
Definition: __init__.py:1
pyclustering.nnet.sync.sync_dynamic.allocate_phase_matrix
def allocate_phase_matrix(self, grid_width=None, grid_height=None, iteration=None)
Returns 2D matrix of phase values of oscillators at the specified iteration of simulation.
Definition: sync.py:238
pyclustering.nnet.sync.sync_network._phases
_phases
Definition: sync.py:736
pyclustering.nnet.sync.sync_visualizer.show_output_dynamics
def show_output_dynamics(sync_output_dynamics)
Shows several output dynamics (output of each oscillator) during simulation.
Definition: sync.py:433
pyclustering.nnet.sync.sync_network.__init__
def __init__(self, num_osc, weight=1, frequency=0, type_conn=conn_type.ALL_TO_ALL, representation=conn_represent.MATRIX, initial_phases=initial_type.RANDOM_GAUSSIAN, ccore=True)
Constructor of oscillatory network is based on Kuramoto model.
Definition: sync.py:710
pyclustering.nnet.sync.sync_network._phase_kuramoto
def _phase_kuramoto(self, teta, t, argv)
Returns result of phase calculation for specified oscillator in the network.
Definition: sync.py:810