I’m following the model fitting example of Tutorial: TraceFitter — Brian2modelfitting 0.3 documentation, but I’m using an adaptive exponential model instead of the given HH model. Now I want to introduce also refractory period, but I get an error. Here’s my code:
from brian2modelfitting import *
from brian2 import *
import pandas as pd
inp_trace = pd.read_csv('input_traces_hh.csv', index_col=0).to_numpy()
out_trace = pd.read_csv('output_traces_hh.csv', index_col=0).to_numpy()
area = 20000*umetre**2
model = '''dv/dt = (gL*(EL-v)+gL*DeltaT*exp((v-VT)/DeltaT) -w + I)/Cm : volt (unless refractory)
dw/dt=(a*(v-EL)-w)/tauw : amp
gL : siemens (constant)
EL : volt (constant)
DeltaT : volt (constant)
VT : volt (constant)
a : siemens (constant)
tauw : second (constant)
wadd : ampere (constant)
vre : volt (constant)
Cm : farad (constant)
tref : second (constant)
'''
opt = NevergradOptimizer()
metric = MSEMetric()
fitter = TraceFitter(model=model,
input_var='I',
output_var='v',
input=inp_trace * amp,
output=out_trace*mV,
dt=0.01*ms,
n_samples=1000,
method='exponential_euler',
param_init={'v': -65*mV},
reset='v=vre; w += wadd',
threshold='v > 0*mV',
refractory='tref')
res, error = fitter.fit(n_rounds=10,
optimizer=opt,
metric=metric,
Cm=[100*pfarad,300*pfarad],
gL=[2*psiemens, 300*nsiemens],
EL=[-90*mV,-40*mV],
VT=[-90*mV,-40*mV],
DeltaT=[0.1*mV,20*mV],
a=[-1.5*nS,3.0*nS],
tauw=[1.0*ms,1000.0*ms],
vre=[-80*mV,-60*mV],
wadd=[-0.2*nA,0.5*nA],
tref=[0.0*ms,5.0*ms])
traces = fitter.generate_traces()
The code works if I remove “(unless refractory)”, that is, remove the refractory period, but otherwise it gives me a division by zero. Any ideas how to fix this issue? Is refractory period supported at all in brian2modelfitting library?
I also seem to get NaNs in the objective function values when I remove “(unless refractory)”, unless I make the length of the refractory period shorter than the simulation time step.