-
Notifications
You must be signed in to change notification settings - Fork 0
/
lif_and_elif_complex_models.py
237 lines (170 loc) · 5.83 KB
/
lif_and_elif_complex_models.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# -*- coding: utf-8 -*-
"""LIF and ELIF Complex Models
Leaky Integrate-and-Fire Full Model [ Linear , nonLinear , Threshold , Reset Model & ... ]
*by : Mostafa Abdollahi*
github.com/m-abdollahi
---
> > > ># ***Linear Exponential Leaky Integrate-and-Fire (LIF) Model ( Ordinary Model)***
# 1 ) Ordinary Model ( without threshold or reset and Start Point)
* Importing Libraries and Modules
"""
import numpy as np
import matplotlib.pyplot as plt
import math as mt
pip install brian2
from brian2 import *
"""
* Set the Neuron
"""
v_rest = -65 * mV # Rest Potential
RI = 90 * mV # RI = I * R = membrane resistance x constant input current = I/G
tau = 10*ms # Tau = Memberane time Constant
"""
* Set the LIF differential equations
"""
eqs = '''
dv/dt = (v_rest - v + RI)/tau : volt
'''
"""
* Set the Neuron Circuit
"""
Methods = 'exact' # set the method for the equations ( exact or euler)
Run_Time0 = 100*ms # Import the Run time for Record
G = NeuronGroup(1, eqs, method=Methods)
M = StateMonitor(G, 'v', record=0)
run(Run_Time0)
plot(M.t/ms, M.v[0])
xlabel('Time (ms)')
ylabel('v');
"""# 2 ) Ordinary Model ( with threshold & reset Potential and Start Point)
* Importing Libraries and Modules
"""
import numpy as np
import matplotlib.pyplot as plt
import math as mt
pip install brian2
from brian2 import *
"""
* Set the Neuron
"""
v_rest = -65 * mV # Rest Potential
v_threshold = 'v > 0*mV' # Threshold Potential
v_reset = 'v = -40*mV' # Reset Potential
v_initial = -70*mV # Initail Poteiial Value
RI = 90 * mV # RI = I * R = membrane resistance x constant input current = I/G
tau = 10*ms # Tau = Memberane time Constant
"""
* Set the LIF differential equations
"""
eqs = '''
dv/dt = (v_rest - v + RI)/tau : volt
'''
"""
* Set the Neuron Circuit
"""
Methods = 'exact' # set the method for the equations ( exact or euler)
Run_Time0 = 100*ms # Import the Run time for Record
G = NeuronGroup(1, eqs, method=Methods , threshold=v_threshold , reset=v_reset)
M = StateMonitor(G, 'v', record=0)
G.v = v_initial # initial value
run(Run_Time0)
plot(M.t/ms, M.v[0])
xlabel('Time (ms)')
ylabel('v');
"""# 3 ) Ordinary Model plus Refractoriness type Forced Voltage Clamp
* Importing Libraries and Modules
"""
import numpy as np
import matplotlib.pyplot as plt
import math as mt
pip install brian2
from brian2 import *
"""
* Set the Neuron
"""
v_rest = -65 * mV # Rest Potential
v_threshold = 'v > 0*mV' # Threshold Potential
v_reset = 'v = -40*mV' # Reset Potential
v_initial = -70*mV # Initail Poteiial Value
RI = 90 * mV # RI = I * R = membrane resistance x constant input current = I/G
tau = 10*ms # Tau = Memberane time Constant
refactorytime = 5*ms # Refactory time
"""
* Set the LIF differential equations
"""
eqs = '''
dv/dt = (v_rest - v + RI)/tau : volt (unless refractory)
'''
"""
* Set the Neuron Circuit
"""
Methods = 'euler' # set the method for the equations ( exact or euler)
Run_Time0 = 100*ms # Import the Run time for Record
G = NeuronGroup(1, eqs, method=Methods , threshold=v_threshold , reset=v_reset,refractory=refactorytime,)
M = StateMonitor(G, 'v', record=0)
G.v = v_initial # initial value
run(Run_Time0)
plot(M.t/ms, M.v[0])
xlabel('Time (ms)')
ylabel('v');
"""# 4 ) Ordinary Model plus Refractoriness type Raised Threshold
* Importing Libraries and Modules
"""
import numpy as np
import matplotlib.pyplot as plt
import math as mt
pip install brian2
from brian2 import *
"""
* Set the Neuron
"""
v_rest = -65 * mV # Rest Potential
vth = 0*mV #first Treshold Potential
vtau = 2*ms # Treshold Time Constant
Run_Time0 = 100*ms # Run time for Record
vtheqs = 0 + mt.exp(-Run_Time0/vtau) # The exponential for The Treshold
v_threshold = 'v > vtheqs*mV' # Threshold Potential
v_reset = 'v = -40*mV' # Reset Potential
v_initial = -70*mV # Initail Poteiial Value
RI = 90 * mV # RI = I * R = membrane resistance x constant input current = I/G
tau = 10*ms # Tau = Memberane time Constant
"""
* Set the LIF differential equations
"""
eqs = '''
dv/dt = (v_rest - v + RI)/tau : volt
'''
"""
* Set the Neuron Circuit
"""
Methods = 'euler' # set the method for the equations ( exact or euler)
Run_Time0 = 100*ms # Import the Run time for Record
G = NeuronGroup(1, eqs, method=Methods , threshold=v_threshold , reset=v_reset,)
M = StateMonitor(G, 'v', record=0)
G.v = v_initial # initial value
run(Run_Time0)
plot(M.t/ms, M.v[0])
xlabel('Time (ms)')
ylabel('v');
"""> > > ># ***Exponential Exponential Leaky Integrate-and-Fire (ELIF) Model***
# 1 ) Exponential Model ( with threshold or reset and Start Point)
* Importing Libraries and Modules
"""
pip install brian2
pip install neurodynex
import brian2 as b2
import matplotlib.pyplot as plt
import numpy as np
from neurodynex.leaky_integrate_and_fire import LIF
from neurodynex.tools import input_factory, plot_tools
"""
* Set the Neuron
"""
V_REST = -70*b2.mV # Reset Potential
V_RESET = -60*b2.mV # Reset Potential
FIRING_THRESHOLD = -50*b2.mV # Treshold Potential
MEMBRANE_RESISTANCE = 10. * b2.Mohm # Membereane R
MEMBRANE_TIME_SCALE = 8. * b2.ms # Time Constant
ABSOLUTE_REFRACTORY_PERIOD = 2.0 * b2.ms # Refactory time
LIF.getting_started()
LIF.print_default_parameters()