3 @brief Neural Network: Local Excitatory Global Inhibitory Oscillatory Network (LEGION) 4 @details Implementation based on paper @cite article::legion::1, @cite article::legion::2. 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/>. 30 import pyclustering.core.legion_wrapper
as wrapper
32 from pyclustering.core.wrapper
import ccore_library
38 from scipy.integrate
import odeint
43 @brief Describes parameters of LEGION. 44 @details Contained parameters affect on output dynamic of each oscillator of the network. 52 @brief Default constructor of parameters for LEGION (local excitatory global inhibitory oscillatory network). 53 @details Constructor initializes parameters by default non-zero values that can be 54 used for simple simulation. 114 @brief Represents output dynamic of LEGION. 121 @brief Returns output dynamic of the network. 133 @brief Returns output dynamic of the global inhibitor of the network. 146 @brief Returns simulation time. 152 return list(range(len(self)));
155 def __init__(self, output, inhibitor, time, ccore = None):
157 @brief Constructor of legion dynamic. 159 @param[in] output (list): Output dynamic of the network represented by excitatory values of oscillators. 160 @param[in] inhibitor (list): Output dynamic of the global inhibitor of the network. 161 @param[in] time (list): Simulation time. 162 @param[in] ccore (POINTER): Pointer to CCORE legion_dynamic. If it is specified then others arguments can be omitted. 175 @brief Destructor of the dynamic of the legion network. 184 @brief Returns length of output dynamic. 190 return len(self.
_time);
195 @brief Allocate clusters in line with ensembles of synchronous oscillators where each synchronous ensemble corresponds to only one cluster. 197 @param[in] tolerance (double): Maximum error for allocation of synchronous ensemble oscillators. 199 @return (list) Grours of indexes of synchronous oscillators, for example, [ [index_osc1, index_osc3], [index_osc2], [index_osc4, index_osc5] ]. 211 @brief Local excitatory global inhibitory oscillatory network (LEGION) that uses relaxation oscillator 212 based on Van der Pol model. 214 @details The model uses global inhibitor to de-synchronize synchronous ensembles of oscillators. 216 CCORE option can be used to use the pyclustering core - C/C++ shared library for processing that significantly increases performance. 220 # Create parameters of the network 221 parameters = legion_parameters(); 225 stimulus = [1, 1, 0, 0, 0, 1, 1, 1]; 227 # Create the network (use CCORE for fast solving) 228 net = legion_network(len(stimulus), parameters, conn_type.GRID_FOUR, ccore = True); 230 # Simulate network - result of simulation is output dynamic of the network 231 output_dynamic = net.simulate(1000, 750, stimulus); 233 # Draw output dynamic 234 draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "x(t)"); 239 def __init__(self, num_osc, parameters = None, type_conn = conn_type.ALL_TO_ALL, type_conn_represent = conn_represent.MATRIX, ccore = True):
241 @brief Constructor of oscillatory network LEGION (local excitatory global inhibitory oscillatory network). 243 @param[in] num_osc (uint): Number of oscillators in the network. 244 @param[in] parameters (legion_parameters): Parameters of the network that are defined by structure 'legion_parameters'. 245 @param[in] type_conn (conn_type): Type of connection between oscillators in the network. 246 @param[in] type_conn_represent (conn_represent): Internal representation of connection in the network: matrix or list. 247 @param[in] ccore (bool): If True then all interaction with object will be performed via CCORE library (C++ implementation of pyclustering). 260 if ( (ccore
is True)
and ccore_library.workable() ):
264 super().
__init__(num_osc, type_conn, type_conn_represent);
285 @brief Default destructor of LEGION. 295 @brief (uint) Returns size of LEGION. 305 def __create_stimulus(self, stimulus):
307 @brief Create stimulus for oscillators in line with stimulus map and parameters. 309 @param[in] stimulus (list): Stimulus for oscillators that is represented by list, number of stimulus should be equal number of oscillators. 313 if (len(stimulus) != self.
_num_osc):
314 raise NameError(
"Number of stimulus should be equal number of oscillators in the network.");
323 def __create_dynamic_connections(self):
325 @brief Create dynamic connection in line with input stimulus. 330 raise NameError(
"Stimulus should initialed before creation of the dynamic connections in the network.");
337 if (len(neighbors) > 0)
and (self.
_stimulus[i] > 0):
338 number_stimulated_neighbors = 0.0
341 number_stimulated_neighbors += 1.0
343 if (number_stimulated_neighbors > 0):
344 dynamic_weight = self.
_params.Wt / number_stimulated_neighbors
350 def simulate(self, steps, time, stimulus, solution=solve_type.RK4, collect_dynamic=True):
352 @brief Performs static simulation of LEGION oscillatory network. 354 @param[in] steps (uint): Number steps of simulations during simulation. 355 @param[in] time (double): Time of simulation. 356 @param[in] stimulus (list): Stimulus for oscillators, number of stimulus should be equal to number of oscillators, 357 example of stimulus for 5 oscillators [0, 0, 1, 1, 0], value of stimulus is defined by parameter 'I'. 358 @param[in] solution (solve_type): Method that is used for differential equation. 359 @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics. 361 @return (list) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time, 362 otherwise returns only last values (last step of simulation) of dynamic. 367 pointer_dynamic = wrapper.legion_simulate(self.
__ccore_legion_pointer, steps, time, solution, collect_dynamic, stimulus)
371 if solution == solve_type.FAST:
372 raise NameError(
"Solver FAST is not support due to low accuracy that leads to huge error.")
374 elif solution == solve_type.RKF45:
375 raise NameError(
"Solver RKF45 is not support in python version. RKF45 is supported in CCORE implementation.")
388 if collect_dynamic
is True:
394 int_step = step / 10.0
396 for t
in numpy.arange(step, time + step, step):
401 if collect_dynamic
is True:
413 def _calculate_states(self, solution, t, step, int_step):
415 @brief Calculates new state of each oscillator in the network. 417 @param[in] solution (solve_type): Type solver of the differential equation. 418 @param[in] t (double): Current time of simulation. 419 @param[in] step (double): Step of solution at the end of which states of oscillators should be calculated. 420 @param[in] int_step (double): Step differentiation that is used for solving differential equation. 424 next_excitatory = [0.0] * self.
_num_osc;
425 next_inhibitory = [0.0] * self.
_num_osc;
428 if (self.
_params.ENABLE_POTENTIONAL
is True):
429 next_potential = [0.0] * self.
_num_osc;
432 for index
in range (0, self.
_num_osc, 1):
433 if (self.
_params.ENABLE_POTENTIONAL
is True):
435 [ next_excitatory[index], next_inhibitory[index], next_potential[index] ] = result[len(result) - 1][0:3];
439 [ next_excitatory[index], next_inhibitory[index] ] = result[len(result) - 1][0:2];
445 for index_neighbor
in neighbors:
459 if (self.
_params.ENABLE_POTENTIONAL
is True):
464 def _global_inhibitor_state(self, z, t, argv):
466 @brief Returns new value of global inhibitory 468 @param[in] z (dobule): Current value of inhibitory. 469 @param[in] t (double): Current time of simulation. 470 @param[in] argv (tuple): It's not used, can be ignored. 472 @return (double) New value if global inhibitory (not assign). 483 return self.
_params.fi * (sigma - z);
486 def _legion_state_simplify(self, inputs, t, argv):
488 @brief Returns new values of excitatory and inhibitory parts of oscillator of oscillator. 489 @details Simplify model doesn't consider oscillator potential. 491 @param[in] inputs (list): Initial values (current) of oscillator [excitatory, inhibitory]. 492 @param[in] t (double): Current time of simulation. 493 @param[in] argv (uint): Extra arguments that are not used for integration - index of oscillator. 495 @return (list) New values of excitatoty and inhibitory part of oscillator (not assign). 510 for index_neighbor
in neighbors:
516 def _legion_state(self, inputs, t, argv):
518 @brief Returns new values of excitatory and inhibitory parts of oscillator and potential of oscillator. 520 @param[in] inputs (list): Initial values (current) of oscillator [excitatory, inhibitory, potential]. 521 @param[in] t (double): Current time of simulation. 522 @param[in] argv (uint): Extra arguments that are not used for integration - index of oscillator. 524 @return (list) New values of excitatoty and inhibitory part of oscillator and new value of potential (not assign). 534 potential_influence = heaviside(p + math.exp(-self.
_params.alpha * t) - self.
_params.teta);
542 for index_neighbor
in neighbors:
545 dp = self.
_params.lamda * (1.0 - p) * heaviside(potential - self.
_params.teta_p) - self.
_params.mu * p;
I
Value of external stimulus.
def __init__(self)
Default constructor of parameters for LEGION (local excitatory global inhibitory oscillatory network)...
teta
Threshold that should be exceeded by a potential to switch on potential.
Local excitatory global inhibitory oscillatory network (LEGION) that uses relaxation oscillator based...
def __create_dynamic_connections(self)
Create dynamic connection in line with input stimulus.
betta
Coefficient that affects on intrinsic inhibitor of each oscillator.
def allocate_sync_ensembles(self, tolerance=0.1)
Allocate clusters in line with ensembles of synchronous oscillators where each synchronous ensemble c...
gamma
Coefficient that is used to control the ratio of the times that the solution spends in these two phas...
def __len__(self)
Returns length of output dynamic.
def simulate(self, steps, time, stimulus, solution=solve_type.RK4, collect_dynamic=True)
Performs static simulation of LEGION oscillatory network.
def __create_stimulus(self, stimulus)
Create stimulus for oscillators in line with stimulus map and parameters.
Utils that are used by modules of pyclustering.
teta_xz
Threshold that should be exceeded by any oscillator to activate global inhibitor. ...
def inhibitor(self)
Returns output dynamic of the global inhibitor of the network.
lamda
Scale coefficient that is used by potential, should be greater than 0.
Describes parameters of LEGION.
def __init__(self, num_osc, parameters=None, type_conn=conn_type.ALL_TO_ALL, type_conn_represent=conn_represent.MATRIX, ccore=True)
Constructor of oscillatory network LEGION (local excitatory global inhibitory oscillatory network)...
def __init__(self, output, inhibitor, time, ccore=None)
Constructor of legion dynamic.
ro
Multiplier of oscillator noise.
def get_neighbors(self, index)
Finds neighbors of the oscillator with specified index.
def __del__(self)
Destructor of the dynamic of the legion network.
ENABLE_POTENTIONAL
Defines whether to use potentional of oscillator or not.
def __del__(self)
Default destructor of LEGION.
Represents output dynamic of LEGION.
__ccore_legion_dynamic_pointer
Common network description that consists of information about oscillators and connection between them...
def time(self)
Returns simulation time.
teta_zx
Threshold that should be exceeded to affect on a oscillator by the global inhibitor.
def _global_inhibitor_state(self, z, t, argv)
Returns new value of global inhibitory.
Wt
Total dynamic weights to a single oscillator from neighbors.
Wz
Weight of global inhibitory connections.
def output(self)
Returns output dynamic of the network.
def _legion_state(self, inputs, t, argv)
Returns new values of excitatory and inhibitory parts of oscillator and potential of oscillator...
def __len__(self)
(uint) Returns size of LEGION.
alpha
Coefficient is chosen to be on the same order of magnitude as 'eps'.
def _calculate_states(self, solution, t, step, int_step)
Calculates new state of each oscillator in the network.
fi
Rate at which the global inhibitor reacts to the stimulation from the oscillator network.
teta_p
Threshold that should be exceeded to activate potential.
mu
Defines time scaling of relaxing of oscillator potential.
eps
Coefficient that affects intrinsic inhibitor of each oscillator.
teta_x
Threshold that should be exceeded by a single oscillator to affect its neighbors. ...
T
Weight of permanent connections.
def _legion_state_simplify(self, inputs, t, argv)
Returns new values of excitatory and inhibitory parts of oscillator of oscillator.
Neural and oscillatory network module.