forked from codecheckers/Detorakis-reproduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuron_model.py
143 lines (122 loc) · 5.02 KB
/
neuron_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This script implements the Mihalas-Niebur Neuron model based on the paper
# S. Mihalas and E. Niebur, "A Generalized Linear Integrate-and-Fire Neural
# Model Produces Diverse Spiking Behaviors", Neural Computation 21, 2009.
# Copyright (C) 2017 Georgios Is. Detorakis
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
import numpy as np
# from memory_profiler import profile
def default_parameters(**kwargs):
""" Sets and stores the default values for simulations in a dictionary.
Args:
**kwargs : Keyword arguments for defining specific
values for the parameters
Return:
params (dict) : Simulation parameters dictionary
"""
params = dict()
k1, k2 = 0.2, 0.02
a, b = 0.0, 0.01
A1, A2 = 0.0, 0.0
R1, R2 = 0.0, 1.0
G, C = 0.05, 1.0
El, Vr = -70.0, -70.0
ThetaR, ThetaInf = -60.0, -50.0
params['k1'] = k1
params['k2'] = k2
params['a'] = a
params['b'] = b
params['A1'] = A1
params['A2'] = A2
params['R1'] = R1
params['R2'] = R2
params['El'] = El
params['Vr'] = Vr
params['Thetar'] = ThetaR
params['ThetaInf'] = ThetaInf
params['G'] = G
params['C'] = C
if kwargs is not None:
for key, value in kwargs.items():
if key in params:
params[key] = value
else:
print("Key {} not found! Default values are used!".format(key))
return params
# @profile
def mnn_model(pms=None, Iext=None, dt=1.0,
IC=(0.01, 0.001, -70.0, -50.0)):
""" Main simulation function. Actual implementation of MNN model.
Args:
params (dict) : Parameters dictionary
Iext (ndarray) : External current array
dt (float) : Euler's step
IC (float) : Initial conditions tuple (I1, I2, V, Theta)
Return:
sol (ndarray) : A numpy array containing the time (T), the two
intrinsic currents (I1 and I2), the membrane
potential (V) and the instantaneous threshold
potential (Theta).
theta_ (ndarray) : The values of the instantaneous threshold
potential at the spike-event times.
spikes (ndarray) : The spike trains.
"""
if Iext is None:
Iext = np.zeros((200, ))
sim_steps = Iext.shape[0] # Total simulation steps
if pms is None:
pms = default_parameters()
# ODEs Initial conditions
I1 = IC[0] * np.ones((sim_steps, )) # Internal current 1
I2 = IC[1] * np.ones((sim_steps, )) # Internal current 2
V = IC[2] * np.ones((sim_steps, )) # Membrane potential
Theta = IC[3] * np.ones((sim_steps, )) # Threshold potential
# Auxiliary vectors
theta_ = np.zeros((sim_steps, )) # Threshold track
time_ = np.zeros((sim_steps, )) # Time vector
spikes = [] # Spike-event times
# Forward Euler integration of MNN
for t in range(1, sim_steps):
# ODEs
I1[t] = I1[t-1] + dt * (-pms['k1'] * I1[t-1])
I2[t] = I2[t-1] + dt * (-pms['k2'] * I2[t-1])
V[t] = V[t-1] + dt * 1.0/pms['C'] * ((Iext[t-1] + I1[t-1]
+ I2[t-1] - pms['G'] *
(V[t-1] - pms['El'])))
Theta[t] = Theta[t-1] + dt * (pms['a'] * (V[t-1] -
pms['El']) -
pms['b'] *
(Theta[t-1] - pms['ThetaInf']))
# Spike event and update rules
if V[t] >= Theta[t]:
# Updates
I1[t] = pms['R1'] * I1[t] + pms['A1']
I2[t] = pms['R2'] * I2[t] + pms['A2']
V[t] = pms['Vr']
Theta[t] = max(pms['Thetar'], Theta[t])
# Auxiliary variables - Threshold in previous time-step
theta_[t] = Theta[t-1]
# Spike events
spikes.append(t)
# Keep track of time
time_[t] = dt * t
# Convert lists into numpy arrays
spikes = np.array(spikes)
# Pack the solution to a numpy array
sol = np.array([time_, I1, I2, V, Theta])
return sol, theta_, spikes