@@ -7,7 +7,7 @@ function get_timeseries(prob, sym, t)
77 @assert t[1 ] >= prob. tspan[1 ]
88 prob = remake (prob, tspan = (prob. tspan[1 ], min (prob. tspan[2 ], t[end ])))
99 sol = solve (prob, saveat = t)
10- sol[sym]
10+ return sol[sym]
1111end
1212
1313"""
@@ -24,11 +24,13 @@ function get_min_t(prob, sym)
2424 sol = solve (prob)
2525 end
2626 f (t, _) = sol (t[1 ]; idxs = sym)
27- oprob = OptimizationProblem (f, [(prob. tspan[2 ] - prob. tspan[1 ]) / 2 ],
27+ oprob = OptimizationProblem (
28+ f, [(prob. tspan[2 ] - prob. tspan[1 ]) / 2 ],
2829 lb = [prob. tspan[1 ]],
29- ub = [prob. tspan[end ]])
30+ ub = [prob. tspan[end ]]
31+ )
3032 res = solve (oprob, BBO_adaptive_de_rand_1_bin_radiuslimited (), maxiters = 10000 )
31- res. u[1 ], f (res. u[1 ], nothing )
33+ return res. u[1 ], f (res. u[1 ], nothing )
3234end
3335
3436"""
@@ -45,11 +47,13 @@ function get_max_t(prob, sym)
4547 sol = solve (prob)
4648 end
4749 f (t, _) = - sol (t[1 ]; idxs = sym)
48- oprob = OptimizationProblem (f, [(prob. tspan[2 ] - prob. tspan[1 ]) / 2 ],
50+ oprob = OptimizationProblem (
51+ f, [(prob. tspan[2 ] - prob. tspan[1 ]) / 2 ],
4952 lb = [prob. tspan[1 ]],
50- ub = [prob. tspan[end ]])
53+ ub = [prob. tspan[end ]]
54+ )
5155 res = solve (oprob, BBO_adaptive_de_rand_1_bin_radiuslimited (), maxiters = 10000 )
52- res. u[1 ], - f (res. u[1 ], nothing )
56+ return res. u[1 ], - f (res. u[1 ], nothing )
5357end
5458
5559"""
@@ -63,7 +67,7 @@ function plot_extrema(prob, sym)
6367 sol = solve (prob)
6468 plot (sol, idxs = sym)
6569 scatter! ([xmin], [xminval])
66- scatter! ([xmax], [xmaxval])
70+ return scatter! ([xmax], [xmaxval])
6771end
6872
6973"""
@@ -79,7 +83,7 @@ function phaseplot_extrema(prob, sym, plotsyms)
7983 xmax, xmaxval = get_max_t (prob, sym)
8084 plot (sol, idxs = plotsyms)
8185 scatter! ([[sol (xmin; idxs = x)] for x in plotsyms]. .. )
82- scatter! ([[sol (xmax; idxs = x)] for x in plotsyms]. .. )
86+ return scatter! ([[sol (xmax; idxs = x)] for x in plotsyms]. .. )
8387end
8488
8589"""
@@ -94,12 +98,14 @@ function get_uncertainty_forecast(prob, sym, t, uncertainp, samples)
9498 @assert t[1 ] >= prob. tspan[1 ]
9599 function prob_func (prob, i, reset)
96100 ps = getindex .(uncertainp, 1 ) .=> rand .(getindex .(uncertainp, 2 ))
97- prob = remake (prob, tspan = (prob. tspan[1 ], min (prob. tspan[2 ], t[end ])),
98- p = ps)
101+ return prob = remake (
102+ prob, tspan = (prob. tspan[1 ], min (prob. tspan[2 ], t[end ])),
103+ p = ps
104+ )
99105 end
100106 eprob = EnsembleProblem (prob, prob_func = prob_func)
101107 esol = solve (eprob, nothing , EnsembleSerial (), saveat = t, trajectories = samples)
102- Array .(reduce .(hcat, [esol[i][sym] for i in 1 : samples]))
108+ return Array .(reduce .(hcat, [esol[i][sym] for i in 1 : samples]))
103109end
104110
105111"""
@@ -112,46 +118,58 @@ distribution. Samples is the number of trajectories to run.
112118
113119Returns a tuple of arrays for the quantiles `quants` which defaults to the 95% confidence intervals.
114120"""
115- function get_uncertainty_forecast_quantiles (prob, sym, t, uncertainp, samples,
116- quants = (0.05 , 0.95 ))
121+ function get_uncertainty_forecast_quantiles (
122+ prob, sym, t, uncertainp, samples,
123+ quants = (0.05 , 0.95 )
124+ )
117125 @assert t[1 ] >= prob. tspan[1 ]
118126 function prob_func (prob, i, reset)
119127 ps = getindex .(uncertainp, 1 ) .=> rand .(getindex .(uncertainp, 2 ))
120- prob = remake (prob, tspan = (prob. tspan[1 ], min (prob. tspan[2 ], t[end ])),
121- p = ps)
128+ return prob = remake (
129+ prob, tspan = (prob. tspan[1 ], min (prob. tspan[2 ], t[end ])),
130+ p = ps
131+ )
122132 end
123133 eprob = EnsembleProblem (prob, prob_func = prob_func)
124134
125135 indexof (sym, syms) = indexin (Symbol .(sym), Symbol .(syms))
126136 idx = indexof (sym, states (prob. f. sys))
127137
128- esol = solve (eprob, nothing , EnsembleSerial (), saveat = t, trajectories = samples,
129- save_idxs = idx)
130- [Array (reduce (hcat, SciMLBase. EnsembleAnalysis. timeseries_steps_quantile (esol, q). u)' )
131- for q in quants]
138+ esol = solve (
139+ eprob, nothing , EnsembleSerial (), saveat = t, trajectories = samples,
140+ save_idxs = idx
141+ )
142+ return [
143+ Array (reduce (hcat, SciMLBase. EnsembleAnalysis. timeseries_steps_quantile (esol, q). u)' )
144+ for q in quants
145+ ]
132146end
133147
134148"""
135149 plot_uncertainty_forecast(prob, sym, t, uncertainp, samples)
136150"""
137- function plot_uncertainty_forecast (prob, sym, t, uncertainp, samples;
151+ function plot_uncertainty_forecast (
152+ prob, sym, t, uncertainp, samples;
138153 label = reshape (string .(Symbol .(sym)), 1 , length (sym)),
139- kwargs... )
154+ kwargs...
155+ )
140156 esol = get_uncertainty_forecast (prob, sym, t, uncertainp, samples)
141157 p = plot (Array (esol[1 ]' ), idxs = sym; label = label, kwargs... )
142158 for i in 2 : samples
143159 plot! (p, Array (esol[i]' ), idxs = sym; label = false , kwargs... )
144160 end
145- display (p)
161+ return display (p)
146162end
147163
148164"""
149165 plot_uncertainty_forecast_quantiles(prob, sym, t, uncertainp, samples, quants = (0.05, 0.95))
150166"""
151- function plot_uncertainty_forecast_quantiles (prob, sym, t, uncertainp, samples,
167+ function plot_uncertainty_forecast_quantiles (
168+ prob, sym, t, uncertainp, samples,
152169 quants = (0.05 , 0.95 ); label = false ,
153- kwargs... )
170+ kwargs...
171+ )
154172 qs = get_uncertainty_forecast_quantiles (prob, sym, t, uncertainp, samples, quants)
155173 plot (t, qs[1 ]; label = label, kwargs... )
156- plot! (t, qs[2 ]; label = false , kwargs... )
174+ return plot! (t, qs[2 ]; label = false , kwargs... )
157175end
0 commit comments