-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
varmap_to_vars fails when used inside of loss function for optimization. #1692
Comments
If you do function loss(p::Vector{Float64})
pred_sol = solve(prob, Tsit5(), p=p[idxs], saveat=t_save)
pred = Array(pred_sol')
mse = mean((pred - obs_vals) .^ 2)
return mse
end with If this is a good workaround, then we should document this in the FAQ. |
@ChrisRackauckas Thank you for your response. But I can't understand it... If I run the command as you adviced: If you mean something like that:
|
I just meant generate an index map. using ModelingToolkit
p = @parameters x y z
idxs = ModelingToolkit.varmap_to_vars([p[1] => 1, p[2] => 2, p[3] => 3], p)
p[Int.(idxs)] |
Thank you, @ChrisRackauckas. |
Edit: I'm dumb, I was just feeding it the actual defaults instead of the indexes. |
If I want to guarantee the order of parameters during the optimization I need to use varmap_to_vars, e.g:
loss function:
where
param_vars
are the parameters of the MTK model.The error I get:
ERROR: Compiling Tuple{Type{Dict}, Vector{Pair{Sym{Real, Base.ImmutableDict{DataType, Any}}, Float64}}}: try/catch is not supported. Refer to the Zygote documentation for fixes.
The full code description is here
The text was updated successfully, but these errors were encountered: