I have a question about the ModelingToolkit package, and in particular about
@parameters value maps.
@parameters t k₁₂ k₂₁ α p = [k₁₂ => 0.0005 k₂₁ => 0.009 α => 0.09]
I have an ODE system and I want to fit some data on it.
As a test, I tried to generate fake data with the following code (from documentation of https://docs.sciml.ai/DiffEqParamEstim/stable/) without noise.
begin using RecursiveArrayTools # for VectorOfArray randomized = VectorOfArray([sol(time[i]) for i in 1:length(time)]) data = convert(Array,randomized) end
and the cost function is as follow :
cost_function = build_loss_objective(prob, Tsit5(), L2Loss(time, data[1,:]), Optimization.AutoForwardDiff(), maxiters=100000,verbose=false, save_idxs = )
cost_data(p) must be equal to
0. However, cost_data doesn’t eat value maps directly and we have to convert
p in an
Array/Vector. We can’t just create a
Vector with the values of
[0.09, 0.009, 0.0005] because the symbol ordering is not guaranteed :
varmap_to_vars ( Frequently Asked Questions · ModelingToolkit.jl (sciml.ai)) seems to be intended for that , but how it work is obscure. Documentation give the following example :
p = @parameters x y z idxs = ModelingToolkit.varmap_to_vars([p => 1, p => 2, p => 3], p) p[idxs]
p[idxs] is just
p and not a vector …
How to correctly manage the symbol ordering when we work with value maps of ModelingToolkit ?