-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGLIF_synaptic.py
390 lines (274 loc) · 13.7 KB
/
AGLIF_synaptic.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# 002: testi in inglese
import numpy as np
#import sys
import matplotlib.pyplot as plt
import os.path
import re
import time
def AGLIFsynaptic(neuronParameters,equilibriumParameters,currentFileName,tSpikeOutputFileName,voltageOutputFileName):
EL = neuronParameters[0]
vres = neuronParameters[1]
vtm = neuronParameters[2]
Cm = neuronParameters[3]
ith = neuronParameters[4]
tao_m = neuronParameters[5]
sc = neuronParameters[6]
bet = neuronParameters[7]
delta1 = neuronParameters[8]
cost_idep_ini = neuronParameters[9]
Idep_ini_vr = neuronParameters[10]
psi1 = neuronParameters[11]
a=neuronParameters[12]
b=neuronParameters[13]
c=neuronParameters[14]
alp=neuronParameters[15]
istim_min_spikinig_exp=neuronParameters[16]
istim_max_spikinig_exp=neuronParameters[17]
time_scale = 1 / (-sc / (Cm * EL))
H = (90+EL)*sc*(bet-delta1)/(EL*(-200))
sim_lenght = neuronParameters[18]
retteParParsed = neuronParameters[19]
# equilibrium params
v_min = equilibriumParameters[0]
minCurr = equilibriumParameters[1]
zeta = equilibriumParameters[2]
eta = equilibriumParameters[3]
rho = equilibriumParameters[4]
csi = equilibriumParameters[5]
sampling = 2
d_dt = 0.05*sampling
corr_list = []
times_list = []
times_list = np.loadtxt(currentFileName, usecols=(0),dtype=np.float64, unpack=True)
corr_list = np.loadtxt(currentFileName, usecols=(1),dtype=np.float64, unpack=True)
cor = np.array(corr_list)
cor = cor[0:len(cor):1]
times = np.array(times_list)
times = times[0:len(times):1]
def tagliorette(corr,retteParParsed):
vinc_sup = retteParParsed[0]
coeffSup = retteParParsed[1]
constSup = retteParParsed[2]
vinc_inf = retteParParsed[3]
coeffInf = retteParParsed[4]
constInf = retteParParsed[5]
dur_sign=np.inf
if corr<vinc_inf and corr>0:
dur_sign = coeffInf*corr + constInf
if corr>vinc_sup:
dur_sign = coeffSup*corr + constSup
return dur_sign
def V(t, delta, Psi, alpha, beta, IaA0, IdA0, t0, V0):
return (1 / 2) * (beta + (-1) * delta) ** (-1) * (beta ** 2 + ((-1) + beta) * delta) ** (-1) * (4 * beta + (- 1) * (1 + delta) ** 2) ** (-1) * Psi * (2 * np.exp(((-1) * t + t0) * beta) * IdA0 * ((-1) + beta) * beta * (beta + (-1) * delta) * Psi + (-2) * (alpha + (-1) * beta + delta) * (beta ** 2 + ((- 1) + beta) * delta) * Psi + np.exp((1 / 2) * (t + (-1) * t0) * ((-1) + delta + (-1) * Psi)) * (IdA0 * beta * (beta + (-1) * delta) * ((-1) + (-1) * delta + beta * (3 + delta + (-1) * Psi) + Psi) + (-1) * (beta ** 2 + (-1) * delta + beta * delta) * (alpha * (1 + (-2) * beta + delta + (-1) * Psi) + (beta + (-1) * delta) * ((-1) + 2 * IaA0 * beta + (-1) * delta + Psi + V0 * ((-1) + (-1) * delta + Psi)))) + np.exp((1 / 2) * (t + (-1) * t0) * ((-1) + delta + Psi)) * ((-1) * IdA0 * beta * (beta+(-1) * delta) * ((-1) + (-1) * delta + (-1) * Psi + beta * (3 + delta + Psi)) + (beta ** 2 + (-1) * delta+beta * delta) * (alpha * (1 + (-2) * beta + delta + Psi) + (beta + (-1) * delta) * ((-1) + 2 * IaA0 * beta+(-1) * delta + (-1) * Psi + (-1) * V0 * (1 + delta + Psi)))))
def Iadap(t, delta, Psi, alpha, beta, IaA0, IdA0, t0, V0):
return (-2*alpha*(-4*beta**3+beta**2*(-1+delta)**2-delta*(1+delta)**2+beta*delta*(5+2*delta+delta**2))+2*np.exp(((-1)*t + t0) * beta)*IdA0*beta*(4*beta**2+delta*(1+delta)**2-beta*(1+6*delta+delta**2))+np.exp((1 / 2)*(t-t0)*(-1+delta+Psi))*(-IdA0*beta*(beta-delta)*(-1+(-2)*delta-delta**2-Psi+delta*Psi+2*beta*(2+Psi))+(beta**2-delta+beta*delta)*(alpha*(1+(-4)*beta+2*delta+delta**2+Psi-delta*Psi)+(beta-delta)*(4*IaA0*beta-2*(1+V0)*Psi+IaA0*(1+delta)*(-1-delta+Psi))))+np.exp((-1)*(1 / 2) * (t-t0) * (1-delta+Psi))*(IdA0*beta*(beta-delta)*(1+2*delta+delta**2-Psi+delta*Psi+2*beta*(-2+Psi))+(beta**2-delta+beta*delta)*(alpha*(1-4*beta+2*delta+delta**2-Psi+delta*Psi)-(beta-delta)*(-4*IaA0*beta-2*(1+V0)*Psi+IaA0*(1+delta)*(1+delta+Psi)))))/(2*(beta-delta)*(beta**2+(-1+beta)*delta)*(4*beta-(1+delta)**2))
def Idep(t, beta, IdA0, t0):
return np.exp(((-1) * t + t0) * beta) * IdA0
def exp_cum(x, a, b):
return a * (1 - np.exp(-b * x))
def monod(x, a, b, c, alp):
return c + (a * np.exp(b) * x) / (alp + x)
tic = time.perf_counter()
Vconvfact = -EL
vth = vtm/Vconvfact
vrm = vres/Vconvfact
t0_val = 0
vini_neg = EL
ts = np.inf
dt = d_dt/time_scale
print('dt= ', dt)
init_sign = 0
ref_t = 2
t0_val = 0
psi1 = ((-4)*bet+((1+delta1)**2))**(0.5)
Idep_ini = 0
Iadap_ini = 0
out = []
t_out = []
t_final = t0_val+dt
v_ini = -1
vini_prec = v_ini
mul = 15
v_star_min = -v_min/EL
alpha_neg = minCurr/sc
f = open(tSpikeOutputFileName, 'w')
i = 0
soglia_sign = 10
Ide = []
Iada = []
Ide2 = []
Iada2 = []
tetalist = []
t_spk = -3*d_dt
afirst = 0
meancorlastis = 0
stdcorlastis = 0
sis = 0
firstSpikeFlag = False
counter = 0
while(t_final*time_scale < sim_lenght):
if (t_final-init_sign)*time_scale >= tagliorette(cor[i],retteParParsed):
if cor[i] > ith:
if cor[i-1] < ith or i == 0:
init_sign = t_final
Idep_ini = max(Idep_ini_vr,cost_idep_ini*(cor[i]-ith))
Iadap_ini = 0
v_ini = ((EL + (1 - np.exp(-(zeta*1000*cor[i] - rho*1000*ith)/1000) )*(vtm - EL))/(-EL))
v_ini = V(t_final, delta1, psi1,
cor[i]/sc, bet, Iadap_ini, Idep_ini, t0_val, v_ini)
Iadap_ini = Iadap(
t_final, delta1, psi1, cor[i] / sc, bet, Iadap_ini, Idep_ini, t0_val, v_ini)
Idep_ini = Idep(t_final, bet, Idep_ini, t0_val)
if cor[i-1] == 0:
v_ini = vini_prec
else:
if cor[i]<ith and cor[i]>0:
v_ini = ((EL + (1 - np.exp(-(eta*1000*cor[i])/1000) )*(vtm - EL))/(-EL))
elif cor[i]<=0:
v_ini = ((EL + (1 - np.exp(-(csi*1000*cor[i])/1000) )*(vtm - EL))/(-EL))
else:
v_ini = ((EL + (1 - np.exp(-(zeta*1000*cor[i] - rho*1000*ith)/1000) )*(vtm - EL))/(-EL))
vini_prec = v_ini
out.append(v_ini)
t_out.append(t_final)
Iada.append(Iadap_ini)
Ide.append(Idep_ini)
else:
vini_prec = v_ini
if (cor[i] < ith and cor[i] >= 0) or i == 0:
v_ini = ((EL + (1 - np.exp(-(eta*1000*cor[i])/1000) )*(vtm - EL))/(-EL))
else:
if cor[i] < cor[i-1] and cor[i] > 0 and (t_spk+2*d_dt) < t_final*time_scale:
print('teta')
teta = (out[i-1]/(cor[i-1] / sc))*(1/dt-delta1) - \
(out[i-2]/((cor[i-1] / sc)*dt))-delta1/(cor[i-1] / sc)-1
if teta < 0:
teta = 0
Idep_ini = Iadap_ini + teta * (cor[i] / sc) / bet
tetalist.append(teta)
v_ini = V(t=t_final, delta=delta1, Psi=psi1,
alpha=cor[i]/sc, beta=bet, IaA0=Iadap_ini, IdA0=Idep_ini, t0=t0_val, V0=v_ini)
Iadap_ini = Iadap(t=t_final, delta=delta1, Psi=psi1,
alpha=cor[i]/sc, beta=bet, IaA0=Iadap_ini, IdA0=Idep_ini, t0=t0_val, V0=v_ini)
Idep_ini = Idep(t=t_final, beta=bet,
IdA0=Idep_ini, t0=t0_val)
else:
if cor[i] > 0:
v_ini = V(t=t_final, delta=delta1, Psi=psi1,
alpha=cor[i]/sc, beta=bet, IaA0=Iadap_ini, IdA0=Idep_ini, t0=t0_val, V0=v_ini)
Iadap_ini = Iadap(t=t_final, delta=delta1, Psi=psi1,
alpha=cor[i]/sc, beta=bet, IaA0=Iadap_ini, IdA0=Idep_ini, t0=t0_val, V0=v_ini)
Idep_ini = Idep(t=t_final, beta=bet,
IdA0=Idep_ini, t0=t0_val)
if cor[i-1] != cor[i] and (cor[i] < 0 and cor[i] > minCurr):
v_ini = vini_prec
if cor[i] < 0 and cor[i] > minCurr:
v_ini = ((EL + (1 - np.exp(-(csi*1000*cor[i])/1000) )*(vtm - EL))/(-EL))
if cor[i-1] != cor[i] and cor[i] <= minCurr:
Iadap_ini = -v_min/EL + 1
Idep_ini = 0
v_ini = ((EL + (1 - np.exp(-(csi*1000*cor[i])/1000) )*(vtm - EL))/(-EL))
if cor[i] <= minCurr:
v_ini=v_star_min
if v_ini*Vconvfact < v_min:
v_ini = v_min/Vconvfact
Iadap_ini = 0
out.append(v_ini)
t_out.append(t_final)
Iada.append(Iadap_ini)
Ide.append(Idep_ini)
if cor[i] > ith:
if cor[i-1] < ith:
init_sign = t_final
Idep_ini = max(Idep_ini_vr,cost_idep_ini*(cor[i]-ith))
Iadap_ini = 0
v_ini = ((EL + (1 - np.exp(-(zeta*1000*cor[i] - rho*1000*ith)/1000) )*(vtm - EL))/(-EL))
if cor[i-1]<1e-11:
v_ini = -1
if v_ini > vth:
t_spk = t_final*time_scale
f.write(str(round(t_spk, 3)) + ' \n')
v_ini = vrm
print('***spike***')
print('t ', t_final*time_scale, 'val_ist V', v_ini * Vconvfact, 'adap',
Iadap_ini, 'idep', Idep_ini, 't_ini', init_sign)
print('************')
if cor[i] < istim_min_spikinig_exp or cor[i] > istim_max_spikinig_exp:
c_aux = c
Iadap_ini = monod((t_final-init_sign) *
time_scale, a, b*cor[i]/1000, c_aux, alp)
else:
Iadap_ini = monod((t_final-init_sign) * time_scale, a, b*cor[i]/1000, c, alp)
if Iadap_ini<0:
print('monod negativa')
paramL = Iadap_ini
if a > 0:
c_aux = c - paramL
else:
c_aux = -a*np.exp(b*cor[i]/1000)
Iadap_ini = monod((t_final-init_sign) * time_scale, a, b*cor[i]/1000, c_aux, alp)
if cor[i] < ith:
Idep_ini = 0
Iadap_ini = 0
else:
Idep_ini = Idep_ini_vr
for k in range(int(ref_t / d_dt)):
out.append(v_ini)
t_final = t_final + dt
t_out.append(t_final)
Iada.append(Iadap_ini)
Ide.append(Idep_ini)
i = i + 1
vini_prec = v_ini
i = i + 1
t0_val = t_final
t_final = t0_val+dt
file = open(voltageOutputFileName, "w")
for i in range(len(t_out)):
file.write(str(t_out[i]*time_scale) + " " + str(out[i]*Vconvfact) + "\n")
file.close()
print(t_final)
toc = time.perf_counter()
print(f"time: {toc - tic:0.4f} seconds")
plt.show()
f.close()
'''
MAIN
'''
# user input -------------------------------------------------------------------
currentFileName = 'trace_l23-06-13.res.6-tt6clu6_0.65+1_prova20122022.txt'
tSpikeOutputFileName = '6_065_t_spk_simulated.txt'
voltageOutputFileName = '6_065_voltage_simulated.txt'
# Neuron parameters
EL = -72.5
vres = -65
vtm = -52
Cm = 2047.4164432004916
ith = 300.9987901902274
tao_m = 3310.462136574088
sc = 4526.328798037026
bet = 0.24522251335200956
delta1 = 0.009906254244852036
cost_idep_ini = 0.017625482908326662
Idep_ini_vr = 1.0122905259090516
psi1 = 0.1975362978159442
a=14.2787
b=-2.10966
c=0.0608809
alp=225.491
istim_min_spikinig_exp=400
istim_max_spikinig_exp=1000
sim_lenght = 600000.1#milliseconds
rettePar=[np.inf,-0.028,76.86,700,0.68,-190]
# equilibrium parameters
v_min = -90
minCurr = -185
# Neuron
zeta = 3.5e-3
eta = 2.5e-3
rho = 1e-3
csi = 3.5e-3
# -------------------------------------------------------------------
neuronParameters=[EL,vres,vtm,Cm,ith,tao_m,sc,bet,delta1,cost_idep_ini,Idep_ini_vr,psi1,a,b,c,alp,istim_min_spikinig_exp,istim_max_spikinig_exp,sim_lenght,rettePar]
equilibriumParameters = [v_min,minCurr,zeta,eta,rho,csi]
AGLIFsynaptic(neuronParameters,equilibriumParameters,currentFileName,tSpikeOutputFileName,voltageOutputFileName)