11
22using ParameterizedFunctions, OrdinaryDiffEq, DiffEqParamEstim, Optimization
33using OptimizationBBO, OptimizationNLopt, ForwardDiff, Plots, BenchmarkTools
4+ using ModelingToolkit: t_nounits as t, D_nounits as D
45gr (fmt= :png )
56
67
@@ -10,10 +11,24 @@ loc_init = [0.5,0.5,0.5,0.5]
1011glo_init = [2.5 ,2.5 ,2.5 ,2.5 ]
1112
1213
13- fitz = @ode_def FitzhughNagumo begin
14- dv = v - v^ 3 / 3 - w + l
15- dw = τinv* (v + a - b* w)
16- end a b τinv l
14+ @mtkmodel FitzHughNagumo begin
15+ @parameters begin
16+ a = 0.7 # Parameter for excitability
17+ b = 0.8 # Recovery rate parameter
18+ τinv = 0.08 # Inverse of the time constant
19+ l = 0.5 # External stimulus
20+ end
21+ @variables begin
22+ v (t) = 1.0 # Membrane potential with initial condition
23+ w (t) = 1.0 # Recovery variable with initial condition
24+ end
25+ @equations begin
26+ D (v) ~ v - v^ 3 / 3 - w + l
27+ D (w) ~ τinv * (v + a - b * w)
28+ end
29+ end
30+
31+ @mtkbuild fitz = FitzHughNagumo ()
1732
1833
1934p = [0.7 ,0.8 ,0.08 ,0.5 ] # Parameters used to construct the dataset
@@ -27,7 +42,7 @@ prob_short = ODEProblem(fitz, r0, tspan2,p)
2742dt = 30.0 / 3000
2843tf = 30.0
2944tinterval = 0 : dt: tf
30- t = collect (tinterval)
45+ time_points = collect (tinterval)
3146
3247
3348h = 0.01
@@ -41,7 +56,7 @@ t_short = collect(tinterval_short)
4156# Generate Data
4257data_sol_short = solve (prob_short,Vern9 (),saveat= t_short,reltol= 1e-9 ,abstol= 1e-9 )
4358data_short = convert (Array, data_sol_short) # This operation produces column major dataset obs as columns, equations as rows
44- data_sol = solve (prob,Vern9 (),saveat= t ,reltol= 1e-9 ,abstol= 1e-9 )
59+ data_sol = solve (prob,Vern9 (),saveat= time_points ,reltol= 1e-9 ,abstol= 1e-9 )
4560data = convert (Array, data_sol)
4661
4762
@@ -125,7 +140,7 @@ opt = Opt(:LD_MMA, 4)
125140@btime res1 = solve (optprob, opt, maxiters = 10000 , xtol_rel = 1e-12 )
126141
127142
128- obj = build_loss_objective (prob,Vern9 (),L2Loss (t ,data),Optimization. AutoForwardDiff (),tstops= t ,reltol= 1e-9 ,abstol= 1e-9 )
143+ obj = build_loss_objective (prob,Vern9 (),L2Loss (time_points ,data),Optimization. AutoForwardDiff (),tstops= time_points ,reltol= 1e-9 ,abstol= 1e-9 )
129144optprob = OptimizationProblem (obj, glo_init, lb = first .(glo_bounds), ub = last .(glo_bounds))
130145@btime res1 = solve (optprob, BBO_adaptive_de_rand_1_bin (), maxiters = 4e3 )
131146
0 commit comments