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 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/>. 27 from scipy.integrate
import odeint
29 from pyclustering.core.wrapper
import ccore_library
31 import pyclustering.core.hhn_wrapper
as wrapper
42 @brief Describes parameters of Hodgkin-Huxley Oscillatory Network. 50 @brief Default constructor of parameters for Hodgkin-Huxley Oscillatory Network. 51 @details Constructor initializes parameters by default non-zero values that can be 52 used for simple simulation. 56 self.
nu = random.random() * 2.0 - 1.0
59 self.
gNa = 120.0 * (1 + 0.02 * self.
nu)
62 self.
gK = 36.0 * (1 + 0.02 * self.
nu)
65 self.
gL = 0.3 * (1 + 0.02 * self.
nu)
130 @brief Central element consist of two central neurons that are described by a little bit different dynamic than peripheral. 138 @brief Constructor of central element. 162 @brief Returns string that represents central element. 170 @brief Oscillatory Neural Network with central element based on Hodgkin-Huxley neuron model. 171 @details Interaction between oscillators is performed via central element (no connection between oscillators that 172 are called as peripheral). Peripheral oscillators receive external stimulus. Central element consist of 173 two oscillators: the first is used for synchronization some ensemble of oscillators and the second 174 controls synchronization of the first central oscillator with various ensembles. 176 Usage example where oscillatory network with 6 oscillators is used for simulation. The first two oscillators 177 have the same stimulus, as well as the third and fourth oscillators and the last two. Thus three synchronous 178 ensembles are expected after simulation. 180 from pyclustering.nnet.hhn import hhn_network, hhn_parameters 181 from pyclustering.nnet.dynamic_visualizer import dynamic_visualizer 183 # Change period of time when high strength value of synaptic connection exists from CN2 to PN. 184 params = hhn_parameters() 187 # Create Hodgkin-Huxley oscillatory network with stimulus. 188 net = hhn_network(6, [0, 0, 25, 25, 47, 47], params) 191 (t, dyn_peripheral, dyn_central) = net.simulate(2400, 600) 193 # Visualize network's output (membrane potential of peripheral and central neurons). 194 amount_canvases = 6 + 2 # 6 peripheral oscillator + 2 central elements 195 visualizer = dynamic_visualizer(amount_canvases, x_title="Time", y_title="V", y_labels=False) 196 visualizer.append_dynamics(t, dyn_peripheral, 0, True) 197 visualizer.append_dynamics(t, dyn_central, amount_canvases - 2, True) 201 There is visualized result of simulation where three synchronous ensembles of oscillators can be observed. The 202 first and the second oscillators form the first ensemble, the third and the fourth form the second ensemble and 203 the last two oscillators form the third ensemble. 204 @image html hhn_three_ensembles.png 208 def __init__(self, num_osc, stimulus = None, parameters = None, type_conn = None, type_conn_represent = conn_represent.MATRIX, ccore = True):
210 @brief Constructor of oscillatory network based on Hodgkin-Huxley neuron model. 212 @param[in] num_osc (uint): Number of peripheral oscillators in the network. 213 @param[in] stimulus (list): List of stimulus for oscillators, number of stimulus should be equal to number of peripheral oscillators. 214 @param[in] parameters (hhn_parameters): Parameters of the network. 215 @param[in] type_conn (conn_type): Type of connections between oscillators in the network (ignored for this type of network). 216 @param[in] type_conn_represent (conn_represent): Internal representation of connection in the network: matrix or list. 217 @param[in] ccore (bool): If 'True' then CCORE is used (C/C++ implementation of the model). 221 super().
__init__(num_osc, conn_type.NONE, type_conn_represent)
228 if parameters
is not None:
236 if (ccore
is True)
and ccore_library.workable():
251 self.
_noise = [random.random() * 2.0 - 1.0
for i
in range(self.
_num_osc)]
257 @brief Destroy dynamically allocated oscillatory network instance in case of CCORE usage. 263 def simulate(self, steps, time, solution = solve_type.RK4):
265 @brief Performs static simulation of oscillatory network based on Hodgkin-Huxley neuron model. 266 @details Output dynamic is sensible to amount of steps of simulation and solver of differential equation. 267 Python implementation uses 'odeint' from 'scipy', CCORE uses classical RK4 and RFK45 methods, 268 therefore in case of CCORE HHN (Hodgkin-Huxley network) amount of steps should be greater than in 271 @param[in] steps (uint): Number steps of simulations during simulation. 272 @param[in] time (double): Time of simulation. 273 @param[in] solution (solve_type): Type of solver for differential equations. 275 @return (tuple) Dynamic of oscillatory network represented by (time, peripheral neurons dynamic, central elements 276 dynamic), where types are (list, list, list). 284 @brief Performs static simulation of oscillatory network based on Hodgkin-Huxley neuron model. 285 @details Output dynamic is sensible to amount of steps of simulation and solver of differential equation. 286 Python implementation uses 'odeint' from 'scipy', CCORE uses classical RK4 and RFK45 methods, 287 therefore in case of CCORE HHN (Hodgkin-Huxley network) amount of steps should be greater than in 290 @param[in] steps (uint): Number steps of simulations during simulation. 291 @param[in] time (double): Time of simulation. 292 @param[in] solution (solve_type): Type of solver for differential equations. 294 @return (tuple) Dynamic of oscillatory network represented by (time, peripheral neurons dynamic, central elements 295 dynamic), where types are (list, list, list). 300 if solution == solve_type.FAST:
301 raise NameError(
"Solver FAST is not support due to low accuracy that leads to huge error.")
317 return dynamic_time, peripheral_membrane_potential, central_membrane_potential
319 if solution == solve_type.RKF45:
320 raise NameError(
"Solver RKF45 is not support in python version.")
323 dyn_central = [[0.0, 0.0]]
327 int_step = step / 10.0
329 for t
in numpy.arange(step, time + step, step):
331 (memb_peripheral, memb_central) = self.
_calculate_states(solution, t, step, int_step)
334 dyn_peripheral.append(memb_peripheral)
335 dyn_central.append(memb_central)
339 return dyn_time, dyn_peripheral, dyn_central
341 def _calculate_states(self, solution, t, step, int_step):
343 @brief Calculates new state of each oscillator in the network. Returns only excitatory state of oscillators. 345 @param[in] solution (solve_type): Type solver of the differential equations. 346 @param[in] t (double): Current time of simulation. 347 @param[in] step (uint): Step of solution at the end of which states of oscillators should be calculated. 348 @param[in] int_step (double): Differentiation step that is used for solving differential equation. 350 @return (list) New states of membrane potentials for peripheral oscillators and for cental elements as a list where 351 the last two values correspond to central element 1 and 2. 355 next_membrane = [0.0] * self.
_num_osc 356 next_active_sodium = [0.0] * self.
_num_osc 357 next_inactive_sodium = [0.0] * self.
_num_osc 358 next_active_potassium = [0.0] * self.
_num_osc 361 for index
in range(0, self.
_num_osc, 1):
364 numpy.arange(t - step, t, int_step),
367 [ next_membrane[index], next_active_sodium[index], next_inactive_sodium[index], next_active_potassium[index] ] = result[len(result) - 1][0:4]
369 next_cn_membrane = [0.0, 0.0]
370 next_cn_active_sodium = [0.0, 0.0]
371 next_cn_inactive_sodium = [0.0, 0.0]
372 next_cn_active_potassium = [0.0, 0.0]
378 numpy.arange(t - step, t, int_step),
381 [ 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]
384 self.
_noise = [ 1.0 + 0.01 * (random.random() * 2.0 - 1.0)
for i
in range(self.
_num_osc)]
390 self.
__update_central_neurons(t, next_cn_membrane, next_cn_active_sodium, next_cn_inactive_sodium, next_cn_active_potassium)
392 return (next_membrane, next_cn_membrane)
394 def __update_peripheral_neurons(self, t, step, next_membrane, next_active_sodium, next_inactive_sodium, next_active_potassium):
396 @brief Update peripheral neurons in line with new values of current in channels. 398 @param[in] t (doubles): Current time of simulation. 399 @param[in] step (uint): Step (time duration) during simulation when states of oscillators should be calculated. 400 @param[in] next_membrane (list): New values of membrane potentials for peripheral neurons. 401 @Param[in] next_active_sodium (list): New values of activation conductances of the sodium channels for peripheral neurons. 402 @param[in] next_inactive_sodium (list): New values of inactivaton conductances of the sodium channels for peripheral neurons. 403 @param[in] next_active_potassium (list): New values of activation conductances of the potassium channel for peripheral neurons. 412 for index
in range(0, self.
_num_osc):
432 def __update_central_neurons(self, t, next_cn_membrane, next_cn_active_sodium, next_cn_inactive_sodium, next_cn_active_potassium):
434 @brief Update of central neurons in line with new values of current in channels. 436 @param[in] t (doubles): Current time of simulation. 437 @param[in] next_membrane (list): New values of membrane potentials for central neurons. 438 @Param[in] next_active_sodium (list): New values of activation conductances of the sodium channels for central neurons. 439 @param[in] next_inactive_sodium (list): New values of inactivaton conductances of the sodium channels for central neurons. 440 @param[in] next_active_potassium (list): New values of activation conductances of the potassium channel for central neurons. 446 self.
_central_element[index].active_cond_sodium = next_cn_active_sodium[index]
447 self.
_central_element[index].inactive_cond_sodium = next_cn_inactive_sodium[index]
448 self.
_central_element[index].active_cond_potassium = next_cn_active_potassium[index]
459 @brief Returns new values of excitatory and inhibitory parts of oscillator and potential of oscillator. 461 @param[in] inputs (list): States of oscillator for integration [v, m, h, n] (see description below). 462 @param[in] t (double): Current time of simulation. 463 @param[in] argv (tuple): Extra arguments that are not used for integration - index of oscillator. 465 @return (list) new values of oscillator [v, m, h, n], where: 466 v - membrane potantial of oscillator, 467 m - activation conductance of the sodium channel, 468 h - inactication conductance of the sodium channel, 469 n - activation conductance of the potassium channel. 482 active_sodium_part = self.
_params.gNa * (m ** 3) * h * (v - self.
_params.vNa)
483 inactive_sodium_part = self.
_params.gK * (n ** 4) * (v - self.
_params.vK)
486 Iion = active_sodium_part + inactive_sodium_part + active_potassium_part
505 central_index = index - self.
_num_osc 506 if central_index == 0:
510 for index_oscillator
in range(0, self.
_num_osc):
514 Isyn = self.
_params.w1 * (v - self.
_params.Vsynexc) * memory_impact
516 elif central_index == 1:
524 dv = -Iion + Iext - Isyn
527 potential = v - self.
_params.vRest
528 am = (2.5 - 0.1 * potential) / (math.exp(2.5 - 0.1 * potential) - 1.0)
529 ah = 0.07 * math.exp(-potential / 20.0)
530 an = (0.1 - 0.01 * potential) / (math.exp(1.0 - 0.1 * potential) - 1.0)
532 bm = 4.0 * math.exp(-potential / 18.0)
533 bh = 1.0 / (math.exp(3.0 - 0.1 * potential) + 1.0)
534 bn = 0.125 * math.exp(-potential / 80.0)
536 dm = am * (1.0 - m) - bm * m
537 dh = ah * (1.0 - h) - bh * h
538 dn = an * (1.0 - n) - bn * n
540 return [dv, dm, dh, dn]
544 @brief Allocates clusters in line with ensembles of synchronous oscillators where each. Synchronous ensemble corresponds to only one cluster. 546 @param[in] tolerance (double): maximum error for allocation of synchronous ensemble oscillators. 548 @return (list) Grours (lists) of indexes of synchronous oscillators. For example [ [index_osc1, index_osc3], [index_osc2], [index_osc4, index_osc5] ]. 554 def __alfa_function(self, time, alfa, betta):
556 @brief Calculates value of alfa-function for difference between spike generation time and current simulation time. 558 @param[in] time (double): Difference between last spike generation time and current time. 559 @param[in] alfa (double): Alfa parameter for alfa-function. 560 @param[in] betta (double): Betta parameter for alfa-function. 562 @return (double) Value of alfa-function. 566 return alfa * time * math.exp(-betta * time)
def hnn_state(self, inputs, t, argv)
Returns new values of excitatory and inhibitory parts of oscillator and potential of oscillator...
def __alfa_function(self, time, alfa, betta)
Calculates value of alfa-function for difference between spike generation time and current simulation...
Vsyninh
Synaptic reversal potential [mV] for inhibitory effects.
gK
Maximal conductivity for potassium current.
gNa
Maximal conductivity for sodium current.
def allocate_sync_ensembles(self, tolerance=0.1)
Allocates clusters in line with ensembles of synchronous oscillators where each.
membrane_potential
Membrane potential of cenral neuron (V).
Icn2
External current [mV] for central element 2.
Utils that are used by modules of pyclustering.
vNa
Reverse potential of sodium current [mV].
betta_excitatory
Betta-parameter for alfa-function for excitatory effect.
betta_inhibitory
Betta-parameter for alfa-function for inhibitory effect.
eps
Affects pulse counter.
_membrane_dynamic_pointer
deltah
Period of time [ms] when high strength value of synaptic connection exists from CN2 to PN...
def __update_central_neurons(self, t, next_cn_membrane, next_cn_active_sodium, next_cn_inactive_sodium, next_cn_active_potassium)
Update of central neurons in line with new values of current in channels.
def simulate(self, steps, time, solution=solve_type.RK4)
Performs static simulation of oscillatory network based on Hodgkin-Huxley neuron model.
threshold
Threshold of the membrane potential that should exceeded by oscillator to be considered as an active...
active_cond_sodium
Activation conductance of the sodium channel (m).
vL
Reverse potential of leakage current [mV].
gL
Maximal conductivity for leakage current.
pulse_generation_time
Timestamps of generated pulses.
def __init__(self)
Constructor of central element.
w3
Strength of the synaptic connection from CN2 to PN.
__ccore_hhn_dynamic_pointer
Central element consist of two central neurons that are described by a little bit different dynamic t...
vRest
Rest potential [mV].
Common network description that consists of information about oscillators and connection between them...
vK
Reverse potential of potassium current [mV].
inactive_cond_sodium
Inactivaton conductance of the sodium channel (h).
pulse_generation
Spike generation of central neuron.
def __repr__(self)
Returns string that represents central element.
active_cond_potassium
Activaton conductance of the sodium channel (h).
Oscillatory Neural Network with central element based on Hodgkin-Huxley neuron model.
def __init__(self)
Default constructor of parameters for Hodgkin-Huxley Oscillatory Network.
def __update_peripheral_neurons(self, t, step, next_membrane, next_active_sodium, next_inactive_sodium, next_active_potassium)
Update peripheral neurons in line with new values of current in channels.
w2
Strength of the synaptic connection from CN1 to PN.
alfa_excitatory
Alfa-parameter for alfa-function for excitatory effect.
Describes parameters of Hodgkin-Huxley Oscillatory Network.
w1
Strength of the synaptic connection from PN to CN1.
def __del__(self)
Destroy dynamically allocated oscillatory network instance in case of CCORE usage.
alfa_inhibitory
Alfa-parameter for alfa-function for inhibitory effect.
def simulate_static(self, steps, time, solution=solve_type.RK4)
Performs static simulation of oscillatory network based on Hodgkin-Huxley neuron model.
Icn1
External current [mV] for central element 1.
def _calculate_states(self, solution, t, step, int_step)
Calculates new state of each oscillator in the network.
Vsynexc
Synaptic reversal potential [mV] for exciting effects.
def __init__(self, num_osc, stimulus=None, parameters=None, type_conn=None, type_conn_represent=conn_represent.MATRIX, ccore=True)
Constructor of oscillatory network based on Hodgkin-Huxley neuron model.
Neural and oscillatory network module.