@@ -32,6 +32,9 @@ data_vals = (0.8 .+ 0.4*rand(10)) .* data_sol[:P][2:end]
3232using Plots
3333plot(true_sol; idxs = :P, label = "True solution", lw = 8)
3434plot!(data_ts, data_vals; label = "Measurements", seriestype=:scatter, ms = 6, color = :blue)
35+ plt = plot(true_sol; idxs = :P, label = "True solution", lw = 8) # hide
36+ plot!(plt, data_ts, data_vals; label = "Measurements", seriestype=:scatter, ms = 6, color = :blue) # hide
37+ Catalyst.PNG(plot(plt; fmt = :png, dpi = 200)) # hide
3538```
3639
3740Next, we will use DiffEqParamEstim to build a loss function to measure how well our model's solutions fit the data.
@@ -75,6 +78,8 @@ We can now simulate our model for the corresponding parameter set, checking that
7578oprob_fitted = remake(oprob; p = optsol.u)
7679fitted_sol = solve(oprob_fitted, Tsit5())
7780plot!(fitted_sol; idxs = :P, label = "Fitted solution", linestyle = :dash, lw = 6, color = :lightblue)
81+ plot!(plt, fitted_sol; idxs = :P, label = "Fitted solution", linestyle = :dash, lw = 6, color = :lightblue) # hide
82+ Catalyst.PNG(plot(plt; fmt = :png, dpi = 200)) # hide
7883```
7984
8085!!! note
@@ -96,6 +101,10 @@ data_vals_P = (0.8 .+ 0.4*rand(10)) .* data_sol[:P][2:end]
96101plot(true_sol; idxs=[:S, :P], label=["True S" "True P"], lw=8)
97102plot!(data_ts, data_vals_S; label="Measured S", seriestype=:scatter, ms=6, color=:blue)
98103plot!(data_ts, data_vals_P; label="Measured P", seriestype=:scatter, ms=6, color=:red)
104+ plt2 = plot(true_sol; idxs=[:S, :P], label=["True S" "True P"], lw=8) # hide
105+ plot!(plt2, data_ts, data_vals_S; label="Measured S", seriestype=:scatter, ms=6, color=:blue) # hide
106+ plot!(plt2, data_ts, data_vals_P; label="Measured P", seriestype=:scatter, ms=6, color=:red) # hide
107+ Catalyst.PNG(plot(plt2; fmt = :png, dpi = 200)) # hide
99108```
100109
101110In this case we would have to use the ` L2Loss(data_ts, hcat(data_vals_S, data_vals_P)) ` and ` save_idxs=[1, 4] ` arguments in ` loss_function ` :
@@ -112,6 +121,8 @@ optsol_S_P = solve(optprob_S_P, Optim.NelderMead())
112121oprob_fitted_S_P = remake(oprob; p = optsol_S_P.u)
113122fitted_sol_S_P = solve(oprob_fitted_S_P)
114123plot!(fitted_sol_S_P; idxs=[:S, :P], label="Fitted solution", linestyle = :dash, lw = 6, color = [:lightblue :pink])
124+ plot!(plt2, fitted_sol_S_P; idxs=[:S, :P], label="Fitted solution", linestyle = :dash, lw = 6, color = [:lightblue :pink]) # hide
125+ Catalyst.PNG(plot(plt2; fmt = :png, dpi = 200)) # hide
115126```
116127
117128## [ Setting parameter constraints and boundaries] (@id optimization_parameter_fitting_constraints)
0 commit comments