예제 #1
0
genInfoEntry = makeGenInfoEntry(testODE, ['testODEsol'])
genInfoDict = makeGenInfo([genInfoEntry])
modelArgs_par = {'genInfo': genInfoDict,
             'name': 'test_model_par',
             'ics': xic}

testModel_par = Model.Model(modelArgs_par)
pest_par = LMpest(freeParams=['k'],
                 depVarNames=['w'],
                 testModel=testModel_par,
                 goalTraj=goaltraj,
                 trange=trange
                )

start_time = time.clock()
pestData_par = pest_par.run(verbose=True)
bestFitModel_par = pestData_par['sys_fit']
print '... finished in %.4f seconds\n' % (time.clock()-start_time)


## Initial condition estimation
print "Estimating initial condition for w (assuming k is correct)"
print "Goal value is w(0) = ", xic['w'], " ..."
modelArgs_ic = {'genInfo': genInfoDict,
             'name': 'test_model_ic',
             'ics': {'w': 0.0}}
testModel_ic = Model.Model(modelArgs_ic)
pest_ic = LMpest(freeParams=['w'],
                 depVarNames=['w'],
                 testModel=testModel_ic,
                 goalTraj=goaltraj,
예제 #2
0
# parameter estimation
print 'Starting parameter estimation'
print 'Goal pars are gl = ', est_pars_ref['gl'], ' vl = ', est_pars_ref['vl']
pest_pars = LMpest(
    freeParams=est_parnames,
    depVarNames=['v'],
    testModel=testModel,
    goalTraj=reftraj,
    trange=tdomain,
)

start = clock()
pestData_par = pest_pars.run(parDict={
    'ftol': 3e-3,
    'xtol': 1e-3
},
                             tmesh=tmesh,
                             verbose=True)
print '  ... finished in %.3f seconds.\n' % (clock() - start)

## Finish preparing plots
print '\nPreparing plots'
disp_dt = 0.05
##plotData_goal = reftraj.sample(['v'], disp_dt)
goalleg = "v original"
plotData_par = testModel.sample('par_est', ['v'], disp_dt, precise=True)

pylab.ylabel('v')
pylab.xlabel('t')
##goalline=plot(plotData_par['t'], plotData_goal['v'])
goal_v = reftraj(tmesh, 'v').toarray()
    print "adjusted error = ", adjusted, "\n"
    return vec


pest_pars = LMpest(freeParams=['vl', 'gl'],
                 depVarNames=['v'],
                 testModel=HH_test_model,
                 goalTraj=goaltraj,
                 trange=[0,15],
                 residual_fn=residual_fn,
                 usePsyco=True
                )

start = clock()
pestData_par = pest_pars.run(parDict={'ftol':1e-4,
                                      'xtol':1e-4,
                                      'args':(HH_spike_t,)},
                             verbose=True)
print '... finished in %.3f seconds\n' % (clock()-start)


## Finish preparing plots
print '\nPreparing plots'
disp_dt = 0.05
plotData_goal = goaltraj.sample(['v'], disp_dt, precise=True)
goalleg = "v original"
plotData_par = HH_test_model.sample('par_est', ['v'], disp_dt, precise=True)

pylab.ylabel('v')
pylab.xlabel('t')
goalline=plot(plotData_goal['t'], plotData_goal['v'])
estline = plot(plotData_par['t'], plotData_par['v'])
    ##    print vl, gl, vl_adjust, gl_adjust, sp_adjust
    print "adjusted error = ", adjusted, "\n"
    return vec


pest_pars = LMpest(freeParams=['vl', 'gl'],
                   depVarNames=['v'],
                   testModel=HH_test_model,
                   goalTraj=goaltraj,
                   trange=[0, 15],
                   residual_fn=residual_fn)

start = clock()
pestData_par = pest_pars.run(parDict={
    'ftol': 1e-4,
    'xtol': 1e-4,
    'args': (HH_spike_t, )
},
                             verbose=True)
print '... finished in %.3f seconds\n' % (clock() - start)

## Finish preparing plots
print '\nPreparing plots'
disp_dt = 0.05
plotData_goal = goaltraj.sample(['v'], disp_dt, precise=True)
goalleg = "v original"
plotData_par = HH_test_model.sample('par_est', ['v'], disp_dt, precise=True)

pylab.ylabel('v')
pylab.xlabel('t')
goalline = plot(plotData_goal['t'], plotData_goal['v'])
estline = plot(plotData_par['t'], plotData_par['v'])
est_parnames = ['gl', 'vl']

# parameter estimation
print 'Starting parameter estimation'
print 'Goal pars are gl = ', est_pars_ref['gl'], ' vl = ', est_pars_ref['vl']
pest_pars = LMpest(freeParams=est_parnames,
                 depVarNames=['v'],
                 testModel=testModel,
                 goalTraj=reftraj,
                 trange=tdomain,
                )

start = clock()
pestData_par = pest_pars.run(parDict={'ftol':3e-3,
                                      'xtol':1e-3},
                             tmesh=tmesh,
                             verbose=True)
print '  ... finished in %.3f seconds.\n' % (clock()-start)

## Finish preparing plots
print '\nPreparing plots'
disp_dt = 0.05
##plotData_goal = reftraj.sample(['v'], disp_dt)
goalleg = "v original"
plotData_par = testModel.sample('par_est', ['v'], disp_dt, precise=True)

pylab.ylabel('v')
pylab.xlabel('t')
##goalline=plot(plotData_par['t'], plotData_goal['v'])
goal_v = reftraj(tmesh, 'v').toarray()
goalline = plot(tmesh, goal_v, 'ok')