Parameter estimation DifferentialEquations.jl with Optim.jl




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]
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?



This sounds a bit like the problem I had here:

Maybe you can patch it to not use saveat and instead use interpolation like I used: