Closed schlichtanders closed 1 year ago
You're missing a check for sol_new.retcode == :Success
. Your ODE solution is diverging at some parameters. https://sensitivity.sciml.ai/dev/training_tips/divergence/
thank you very much! A beginners fault apparently. Closing the issue then
An addition: It might be good to adapt documentation/examples to always account for this special case respectively.
Here one updated example from the original UDE paper https://github.com/ChrisRackauckas/universal_differential_equations/blob/master/LotkaVolterra/scenario_2.jl#L104-L124
function predict(θ, X = Xₙ[:,1], T = t)
_prob = remake(prob_nn, u0 = X, tspan = (T[1], T[end]), p = θ)
Array(solve(_prob, Vern7(), saveat = T,
abstol=1e-6, reltol=1e-6,
sensealg = ForwardDiffSensitivity()
))
end
# Multiple shooting like loss
function loss(θ)
# Start with a regularization on the network
l = convert(eltype(θ), 1e-3)*sum(abs2, θ[2:end]) ./ length(θ[2:end])
for i in 1:size(XS,1)
X̂ = predict(θ, [XS[i,1], YS[i,1]], TS[i, :])
# Full prediction in x
l += sum(abs2, XS[i,:] .- X̂[1,:])
# Add the boundary condition in y
l += abs(YS[i, 2] .- X̂[2, end])
end
return l
end
If I understand it correctly, this does not account for retcode == :Success
Indeed we should always add it to the examples, regardless if the defaults tend to diverge or not.
errors with
The problem already exists for more than 3 years - it was first reported in https://discourse.julialang.org/t/optimization-with-lbfgs-gives-dimensionmismatch-dimensions-must-match/22167 but apparently never raised enough to get fixed.
It would be really great if this can be fixed.