Parameter estimation DifferentialEquations.jl with Optim.jl

Hello,

I get a dimension mismatch while broadcasting when trying to estimate parameters with objects from the DifferentialEquations.jl package using the Optim.jl package. I have tried different numbers of data points. It seems that the output of the model, i.e. the differential equation, has two more elements than there are data points (I checked that in the supervised.jl file). I have provided the following example:

using DifferentialEquations,Optim,LossFunctions
xdata = collect(linspace(0.1,9.5,10))
ydata = randn(length(xdata))
function model4(dx,x,p,t)
    dx[1] = -p[1]*x[1]
end
tspan = (0.0,10.0)
prob = ODEProblem(model4,[10.0],tspan,[1.0])
lossfcn = CostVData(xdata,ydata;loss_func=L2DistLoss)
cost_function = build_loss_objective(prob,Tsit5(),lossfcn)
result = optimize(cost_function, [1.0])

The optimize function throws the DimensionMismatch error. I also tried to enforce the saveat option, but didn’t work out. Any ideas?

Regards,
Moritz

This sounds a bit like the problem I had here: https://github.com/JuliaDiffEq/DiffEqBayes.jl/pull/42#discussion_r186036462

Maybe you can patch it to not use saveat and instead use interpolation like I used: https://github.com/JuliaDiffEq/DiffEqBayes.jl/pull/42/files#r186114099.

This was due to an error in how saveat was defined which made it save start and save end only using save_start and save_end commands, rather than checking whether the start and end are in saveat. This was changed in DiffEq v5.0 (on Julia v1.0) to just work like you expected.