3 @brief Oscillatory Neural Network based on Hodgkin-Huxley Neuron Model
4 @details Implementation based on paper @cite article::nnet::hnn::1.
6 @authors Andrei Novikov (pyclustering@yandex.ru)
8 @copyright BSD-3-Clause
12 from scipy.integrate
import odeint
14 from pyclustering.core.wrapper
import ccore_library
16 import pyclustering.core.hhn_wrapper
as wrapper
27 @brief Describes parameters of Hodgkin-Huxley Oscillatory Network.
35 @brief Default constructor of parameters for Hodgkin-Huxley Oscillatory Network.
36 @details Constructor initializes parameters by default non-zero values that can be
37 used for simple simulation.
41 self.
nu = random.random() * 2.0 - 1.0
44 self.
gNa = 120.0 * (1 + 0.02 * self.
nu)
47 self.
gK = 36.0 * (1 + 0.02 * self.
nu)
50 self.
gL = 0.3 * (1 + 0.02 * self.
nu)
115 @brief Central element consist of two central neurons that are described by a little bit different dynamic than peripheral.
123 @brief Constructor of central element.
147 @brief Returns string that represents central element.
155 @brief Oscillatory Neural Network with central element based on Hodgkin-Huxley neuron model.
156 @details Interaction between oscillators is performed via central element (no connection between oscillators that
157 are called as peripheral). Peripheral oscillators receive external stimulus. Central element consist of
158 two oscillators: the first is used for synchronization some ensemble of oscillators and the second
159 controls synchronization of the first central oscillator with various ensembles.
161 Usage example where oscillatory network with 6 oscillators is used for simulation. The first two oscillators
162 have the same stimulus, as well as the third and fourth oscillators and the last two. Thus three synchronous
163 ensembles are expected after simulation.
165 from pyclustering.nnet.hhn import hhn_network, hhn_parameters
166 from pyclustering.nnet.dynamic_visualizer import dynamic_visualizer
168 # Change period of time when high strength value of synaptic connection exists from CN2 to PN.
169 params = hhn_parameters()
172 # Create Hodgkin-Huxley oscillatory network with stimulus.
173 net = hhn_network(6, [0, 0, 25, 25, 47, 47], params)
176 (t, dyn_peripheral, dyn_central) = net.simulate(2400, 600)
178 # Visualize network's output (membrane potential of peripheral and central neurons).
179 amount_canvases = 6 + 2 # 6 peripheral oscillator + 2 central elements
180 visualizer = dynamic_visualizer(amount_canvases, x_title="Time", y_title="V", y_labels=False)
181 visualizer.append_dynamics(t, dyn_peripheral, 0, True)
182 visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True)
186 There is visualized result of simulation where three synchronous ensembles of oscillators can be observed. The
187 first and the second oscillators form the first ensemble, the third and the fourth form the second ensemble and
188 the last two oscillators form the third ensemble.
189 @image html hhn_three_ensembles.png
193 def __init__(self, num_osc, stimulus = None, parameters = None, type_conn = None, type_conn_represent = conn_represent.MATRIX, ccore = True):
195 @brief Constructor of oscillatory network based on Hodgkin-Huxley neuron model.
197 @param[in] num_osc (uint): Number of peripheral oscillators in the network.
198 @param[in] stimulus (list): List of stimulus for oscillators, number of stimulus should be equal to number of peripheral oscillators.
199 @param[in] parameters (hhn_parameters): Parameters of the network.
200 @param[in] type_conn (conn_type): Type of connections between oscillators in the network (ignored for this type of network).
201 @param[in] type_conn_represent (conn_represent): Internal representation of connection in the network: matrix or list.
202 @param[in] ccore (bool): If 'True' then CCORE is used (C/C++ implementation of the model).
206 super().
__init__(num_osc, conn_type.NONE, type_conn_represent)
213 if parameters
is not None:
221 if (ccore
is True)
and ccore_library.workable():
236 self.
_noise = [random.random() * 2.0 - 1.0
for i
in range(self.
_num_osc)]
242 @brief Destroy dynamically allocated oscillatory network instance in case of CCORE usage.
248 def simulate(self, steps, time, solution = solve_type.RK4):
250 @brief Performs static simulation of oscillatory network based on Hodgkin-Huxley neuron model.
251 @details Output dynamic is sensible to amount of steps of simulation and solver of differential equation.
252 Python implementation uses 'odeint' from 'scipy', CCORE uses classical RK4 and RFK45 methods,
253 therefore in case of CCORE HHN (Hodgkin-Huxley network) amount of steps should be greater than in
256 @param[in] steps (uint): Number steps of simulations during simulation.
257 @param[in] time (double): Time of simulation.
258 @param[in] solution (solve_type): Type of solver for differential equations.
260 @return (tuple) Dynamic of oscillatory network represented by (time, peripheral neurons dynamic, central elements
261 dynamic), where types are (list, list, list).
269 @brief Performs static simulation of oscillatory network based on Hodgkin-Huxley neuron model.
270 @details Output dynamic is sensible to amount of steps of simulation and solver of differential equation.
271 Python implementation uses 'odeint' from 'scipy', CCORE uses classical RK4 and RFK45 methods,
272 therefore in case of CCORE HHN (Hodgkin-Huxley network) amount of steps should be greater than in
275 @param[in] steps (uint): Number steps of simulations during simulation.
276 @param[in] time (double): Time of simulation.
277 @param[in] solution (solve_type): Type of solver for differential equations.
279 @return (tuple) Dynamic of oscillatory network represented by (time, peripheral neurons dynamic, central elements
280 dynamic), where types are (list, list, list).
285 if solution == solve_type.FAST:
286 raise NameError(
"Solver FAST is not support due to low accuracy that leads to huge error.")
302 return dynamic_time, peripheral_membrane_potential, central_membrane_potential
304 if solution == solve_type.RKF45:
305 raise NameError(
"Solver RKF45 is not support in python version.")
308 dyn_central = [[0.0, 0.0]]
312 int_step = step / 10.0
314 for t
in numpy.arange(step, time + step, step):
316 (memb_peripheral, memb_central) = self.
_calculate_states(solution, t, step, int_step)
319 dyn_peripheral.append(memb_peripheral)
320 dyn_central.append(memb_central)
324 return dyn_time, dyn_peripheral, dyn_central
326 def _calculate_states(self, solution, t, step, int_step):
328 @brief Calculates new state of each oscillator in the network. Returns only excitatory state of oscillators.
330 @param[in] solution (solve_type): Type solver of the differential equations.
331 @param[in] t (double): Current time of simulation.
332 @param[in] step (uint): Step of solution at the end of which states of oscillators should be calculated.
333 @param[in] int_step (double): Differentiation step that is used for solving differential equation.
335 @return (list) New states of membrane potentials for peripheral oscillators and for cental elements as a list where
336 the last two values correspond to central element 1 and 2.
340 next_membrane = [0.0] * self.
_num_osc
341 next_active_sodium = [0.0] * self.
_num_osc
342 next_inactive_sodium = [0.0] * self.
_num_osc
343 next_active_potassium = [0.0] * self.
_num_osc
346 for index
in range(0, self.
_num_osc, 1):
349 numpy.arange(t - step, t, int_step),
352 [ next_membrane[index], next_active_sodium[index], next_inactive_sodium[index], next_active_potassium[index] ] = result[len(result) - 1][0:4]
354 next_cn_membrane = [0.0, 0.0]
355 next_cn_active_sodium = [0.0, 0.0]
356 next_cn_inactive_sodium = [0.0, 0.0]
357 next_cn_active_potassium = [0.0, 0.0]
363 numpy.arange(t - step, t, int_step),
366 [ next_cn_membrane[index], next_cn_active_sodium[index], next_cn_inactive_sodium[index], next_cn_active_potassium[index] ] = result[len(result) - 1][0:4]
369 self.
_noise = [ 1.0 + 0.01 * (random.random() * 2.0 - 1.0)
for i
in range(self.
_num_osc)]
375 self.
__update_central_neurons(t, next_cn_membrane, next_cn_active_sodium, next_cn_inactive_sodium, next_cn_active_potassium)
377 return (next_membrane, next_cn_membrane)
379 def __update_peripheral_neurons(self, t, step, next_membrane, next_active_sodium, next_inactive_sodium, next_active_potassium):
381 @brief Update peripheral neurons in line with new values of current in channels.
383 @param[in] t (doubles): Current time of simulation.
384 @param[in] step (uint): Step (time duration) during simulation when states of oscillators should be calculated.
385 @param[in] next_membrane (list): New values of membrane potentials for peripheral neurons.
386 @Param[in] next_active_sodium (list): New values of activation conductances of the sodium channels for peripheral neurons.
387 @param[in] next_inactive_sodium (list): New values of inactivaton conductances of the sodium channels for peripheral neurons.
388 @param[in] next_active_potassium (list): New values of activation conductances of the potassium channel for peripheral neurons.
397 for index
in range(0, self.
_num_osc):
417 def __update_central_neurons(self, t, next_cn_membrane, next_cn_active_sodium, next_cn_inactive_sodium, next_cn_active_potassium):
419 @brief Update of central neurons in line with new values of current in channels.
421 @param[in] t (doubles): Current time of simulation.
422 @param[in] next_membrane (list): New values of membrane potentials for central neurons.
423 @Param[in] next_active_sodium (list): New values of activation conductances of the sodium channels for central neurons.
424 @param[in] next_inactive_sodium (list): New values of inactivaton conductances of the sodium channels for central neurons.
425 @param[in] next_active_potassium (list): New values of activation conductances of the potassium channel for central neurons.
431 self.
_central_element[index].active_cond_sodium = next_cn_active_sodium[index]
432 self.
_central_element[index].inactive_cond_sodium = next_cn_inactive_sodium[index]
433 self.
_central_element[index].active_cond_potassium = next_cn_active_potassium[index]
444 @brief Returns new values of excitatory and inhibitory parts of oscillator and potential of oscillator.
446 @param[in] inputs (list): States of oscillator for integration [v, m, h, n] (see description below).
447 @param[in] t (double): Current time of simulation.
448 @param[in] argv (tuple): Extra arguments that are not used for integration - index of oscillator.
450 @return (list) new values of oscillator [v, m, h, n], where:
451 v - membrane potantial of oscillator,
452 m - activation conductance of the sodium channel,
453 h - inactication conductance of the sodium channel,
454 n - activation conductance of the potassium channel.
467 active_sodium_part = self.
_params.gNa * (m ** 3) * h * (v - self.
_params.vNa)
468 inactive_sodium_part = self.
_params.gK * (n ** 4) * (v - self.
_params.vK)
471 Iion = active_sodium_part + inactive_sodium_part + active_potassium_part
490 central_index = index - self.
_num_osc
491 if central_index == 0:
495 for index_oscillator
in range(0, self.
_num_osc):
499 Isyn = self.
_params.w1 * (v - self.
_params.Vsynexc) * memory_impact
501 elif central_index == 1:
509 dv = -Iion + Iext - Isyn
512 potential = v - self.
_params.vRest
513 am = (2.5 - 0.1 * potential) / (math.exp(2.5 - 0.1 * potential) - 1.0)
514 ah = 0.07 * math.exp(-potential / 20.0)
515 an = (0.1 - 0.01 * potential) / (math.exp(1.0 - 0.1 * potential) - 1.0)
517 bm = 4.0 * math.exp(-potential / 18.0)
518 bh = 1.0 / (math.exp(3.0 - 0.1 * potential) + 1.0)
519 bn = 0.125 * math.exp(-potential / 80.0)
521 dm = am * (1.0 - m) - bm * m
522 dh = ah * (1.0 - h) - bh * h
523 dn = an * (1.0 - n) - bn * n
525 return [dv, dm, dh, dn]
529 @brief Allocates clusters in line with ensembles of synchronous oscillators where each. Synchronous ensemble corresponds to only one cluster.
531 @param[in] tolerance (double): maximum error for allocation of synchronous ensemble oscillators.
533 @return (list) Grours (lists) of indexes of synchronous oscillators. For example [ [index_osc1, index_osc3], [index_osc2], [index_osc4, index_osc5] ].
539 def __alfa_function(self, time, alfa, betta):
541 @brief Calculates value of alfa-function for difference between spike generation time and current simulation time.
543 @param[in] time (double): Difference between last spike generation time and current time.
544 @param[in] alfa (double): Alfa parameter for alfa-function.
545 @param[in] betta (double): Betta parameter for alfa-function.
547 @return (double) Value of alfa-function.
551 return alfa * time * math.exp(-betta * time)