I have the following snippet:
module mwe
using OrdinaryDiffEq
using Plots
using Distributions
using Statistics
tspan = (0.0, 10.0)
Δt = 0.5
g(u, p, t) = p[1] * t
x0 = 0.0
# base problem
prob_x = ODEProblem(g, x0, tspan, [1])
# ensemble problem
dist_a = Exponential()
function prob_func(prob, i, repeat)
remake(prob, p=[rand(dist_a)])
end
n_traj = 10^4
ensemble_prob = EnsembleProblem(prob_x, prob_func=prob_func)
sim = solve(ensemble_prob, Euler(), dt=Δt, EnsembleThreads(), trajectories=n_traj)
display(plot(EnsembleSummary(sim)))
println("Mean at the final time")
display(mean([a[end] for a in sim.u]))
end # module mwe
which outputs
Mean at the final time
47.418223069301085
and
Do I understand it correctly that the thick blue line in the plot of the EnsembleSummary
is the mean as a function of time? And [a[end] for a in sim.u]
gets me the endpoint of every trajectory? If so, why the plot mean at tspan[end]
is 30 and the calculated mean is 47? If not, where am I mistaken?