Skip to content

no argument checks and @inbounds is problematic #140

Description

@ValentinKaisermayer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions