Skip to content

Commit

Permalink
construct outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Jul 13, 2023
1 parent 4b6dd3f commit 770510f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/SimulationService.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ end
Calibrate(o::OperationRequest) = Calibrate(o.sys, o.timespan, o.priors, o.data)

function solve(o::Calibrate; callback)
prob = ODEProblem(o.sys, [], o.timespan, saveat=1)
prob = ODEProblem(o.sys, [], o.timespan)
names = [states(o.sys);getproperty.(observed(o.sys), :lhs)]

# what the data should be like
# o.data
Expand All @@ -492,10 +493,16 @@ function solve(o::Calibrate; callback)

p_posterior = bayesian_datafit(prob, o.priors, data_with_t)

probs = [remake(prob, p = Pair.(first.(p_posterior), getindex.(p_posterior.(fit), i))) for i in 1:length(p_posterior[1][2])]
enprob = EnsembleProblem(probs)
ensol = solve(enprob, saveat = 1)
soldata = DataFrame([sol.t;Matrix(sol[names])'])
rename!(soldata, names)

df = DataFrame(last.(p_posterior), :auto)
rename!(df, Symbol.(first.(p_posterior)))

df
df, soldata
end

#-----------------------------------------------------------------------------# ensemble
Expand All @@ -521,9 +528,12 @@ function solve(o::Ensemble; callback)
fit_enprob = EnsembleProblem(forecast_probs)
sol = solve(fit_enprob; saveat = o.t_forecast);

soldata = DataFrame([sol.t;Matrix(sol[names])'])

# Requires https://github.com/SciML/SciMLBase.jl/pull/467
# weighted_ensem = WeightedEnsembleSolution(sol, ensem_weights; quantiles = o.quantiles)
# DataFrame(weighted_ensem)
# df = DataFrame(weighted_ensem)
# df, soldata
end

end # module

0 comments on commit 770510f

Please sign in to comment.