Skip to content
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

no argument checks and @inbounds is problematic #140

Open
ValentinKaisermayer opened this issue Oct 1, 2020 · 2 comments
Open

no argument checks and @inbounds is problematic #140

ValentinKaisermayer opened this issue Oct 1, 2020 · 2 comments

Comments

@ValentinKaisermayer
Copy link

Consider the following example: https://diffeq.sciml.ai/stable/analysis/parameter_estimation/#Optimization-Based-ODE-Inference-Examples
If one makes an L2Loss there is nothing that stops one from doing:

using DiffEqParamEstim, DifferentialEquations, Plots, RecursiveArrayTools

function f(du, u, p, t)
    du[1] = dx = p[1] * u[1] - u[1] * u[2]
    du[2] = dy = -3 * u[2] + u[1] * u[2]
end
  
u0 = [1.0; 1.0]
tspan = (0.0, 10.0)
p = [1.5]
prob = ODEProblem(f, u0, tspan, p)

sol = solve(prob, Tsit5())
t = collect(range(0, stop=10, length=200))
randomized = VectorOfArray([(sol(t[i]) + .01randn(2)) for i in 1:length(t)])

data = copy(convert(Array, randomized)') # this is the problem

model_ode(p_) = ODEProblem(f, u0, tspan, p_)
loss_objective = build_loss_objective(prob, Tsit5(), L2Loss(t, data); prob_generator=(prob, p) -> model_ode(p))

however, this will result in a crash of Julia. since in

@inbounds for i in 1:length(sol)

the correct dimension of data is assumed.

@ValentinKaisermayer
Copy link
Author

The same is true if one uses a PeriodicCallback. In this case sol.t might not be equal to loss.t.

@ChrisRackauckas
Copy link
Member

I missed this email. That is a good point: it should check the bounds and throw an error before proceeding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants