Skip to content

Commit 523232f

Browse files
committed
use pngs on big plot tutorial
1 parent 157a97f commit 523232f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/src/inverse_problems/optimization_ode_param_fitting.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ data_vals = (0.8 .+ 0.4*rand(10)) .* data_sol[:P][2:end]
3232
using Plots
3333
plot(true_sol; idxs = :P, label = "True solution", lw = 8)
3434
plot!(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

3740
Next, 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
7578
oprob_fitted = remake(oprob; p = optsol.u)
7679
fitted_sol = solve(oprob_fitted, Tsit5())
7780
plot!(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]
96101
plot(true_sol; idxs=[:S, :P], label=["True S" "True P"], lw=8)
97102
plot!(data_ts, data_vals_S; label="Measured S", seriestype=:scatter, ms=6, color=:blue)
98103
plot!(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

101110
In 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())
112121
oprob_fitted_S_P = remake(oprob; p = optsol_S_P.u)
113122
fitted_sol_S_P = solve(oprob_fitted_S_P)
114123
plot!(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

Comments
 (0)