return numeric_to_traj([varray], self._trajname, ['v'], indepvar=tmesh) pest_context = context([ (spike_interface, int_spike_iface), (geom_interface, int_geom_iface) ]) ## Parameter estimation print('Estimating pars gna and vl for fit to non-identical HH cell') print('Goal values are gna =', par_args_HH_goal['gna'], ', gl =', \ par_args_HH_goal['gl'], ' ...') pest_pars = LMpest(freeParams=['gna', 'gl'], testModel=HH_test_model, context=pest_context, verbose_level=2 ) # In case finite difference stepsize needs adjusting pest_pars.fn.eps=1e-5 pest_context.set_weights({spike_interface: {sp_feat: 10}, geom_interface: {geom_feat: 0.2}}) t0=clock() pestData_par_phase1 = pest_pars.run(parDict={'ftol':1e-5, 'xtol':1e-6 }, verbose=True)
return numeric_to_traj([varray], self._trajname, ['v'], indepvar=tmesh) pest_context = context([ (spike_interface, int_spike_iface), (geom_interface, int_geom_iface) ]) ## Parameter estimation print('Estimating pars gna and vl for fit to non-identical HH cell') print('Goal values are gna =', par_args_HH_goal['gna'], ', gl =', \ par_args_HH_goal['gl'], ' ...') pest_pars = LMpest(freeParams=['gna', 'gl'], testModel=HH_test_model, context=pest_context, verbose_level=2, usePsyco=False ) # In case finite difference stepsize needs adjusting pest_pars.fn.eps=1e-5 pest_context.set_weights({spike_interface: {sp_feat: 10}, geom_interface: {geom_feat: 0.2}}) t0=clock() pestData_par_phase1 = pest_pars.run(parDict={'ftol':1e-5, 'xtol':1e-6 }, verbose=True)
def postprocess_test_traj(self, traj): # use tmesh of data points only (may not be the same mesh as was used by # this model traj, that's why we have to resample varray = traj(tmesh)["v"] return numeric_to_traj([varray], self._trajname, ["v"], indepvar=tmesh) pest_context = context([(spike_interface, int_spike_iface), (geom_interface, int_geom_iface)]) ## Parameter estimation print("Estimating pars gna and vl for fit to non-identical HH cell") print("Goal values are gna =", par_args_HH_goal["gna"], ", gl =", par_args_HH_goal["gl"], " ...") pest_pars = LMpest( freeParams=["gna", "gl"], testModel=HH_test_model, context=pest_context, verbose_level=2, usePsyco=False ) # In case finite difference stepsize needs adjusting pest_pars.fn.eps = 1e-5 pest_context.set_weights({spike_interface: {sp_feat: 10}, geom_interface: {geom_feat: 0.2}}) t0 = clock() pestData_par_phase1 = pest_pars.run(parDict={"ftol": 1e-5, "xtol": 1e-6}, verbose=True) HH_test_model.set(pars=pestData_par_phase1["pars_sol"]) pest_context.set_weights({spike_interface: {sp_feat: 5}, geom_interface: {geom_feat: 0.7}}) pestData_par = pest_pars.run(parDict={"ftol": 1e-5, "xtol": 1e-6}, verbose=True)
class ext_iface(extModelInterface): # holds the data (external from the model) pass class int_iface(intModelInterface): # holds the test model pass pest_data_interface_w = ext_iface(reftraj, pest_condition_w) c = context([ (pest_data_interface_w, int_iface) ]) testModel_par = embed(Generator.Vode_ODEsystem(testDSargs)) pest_pars = LMpest(freeParams=['k'], testModel=testModel_par, context=c ) start_time = time.clock() pestData_par = pest_pars.run(parDict={'ftol': ftol, 'xtol':1e-3}, verbose=True) print('... finished in %.4f seconds\n' % (time.clock()-start_time)) bestFitModel_par = pestData_par['sys_sol'] ## Initial condition estimation print("Estimating initial condition for w (assuming k is correct)") print("Goal value is w(0) = ", xic['w'], " ...") modelArgs_ic = copy(testDSargs)
# embed the reference trajectory and measurement condition/features # into an instance of the external interface pest_data_interface = ext_iface(reftraj, pest_condition) # generate a context for the model between the external interface # instance and the internal interface class (not an instance yet) c = context([(pest_data_interface, int_iface)]) # specify which parameters we will fit est_parnames = ['gl', 'vl'] # parameter estimation print('Starting Least Squares parameter estimation') print('Goal pars are gl = ', est_pars_ref['gl'], ' vl = ', est_pars_ref['vl']) pest_pars = LMpest(freeParams=est_parnames, testModel=testModel, context=c) start = clock() pestData_par = pest_pars.run(parDict={ 'ftol': ftol, 'xtol': 1e-3 }, verbose=True) print(' ... finished in %.3f seconds.\n' % (clock() - start)) # Prepare plots print('\nPreparing plots') disp_dt = 0.05 ##plotData_goal = reftraj.sample(['v'], disp_dt) goalleg = "v original"