Custom L2Loss in DiffEqParamEstim.jl

Hello everyone,

I am very new to Julia, so I apologise if the question sounds super dumb to you guys.
I am trying to implement a Moving Horizon Estimation algorithm for parameter estimation, which I did in Matlab CasADi.
I need to have a cost function for the differential equation parameter estimation problem, which minimises the difference between data and estimates and minimises variations between consecutive parameter estimates in different time windows.

Right now I am approaching the problem following the example provided in: Getting Started with Optimization-Based ODE Parameter Estimation · DiffEqParamEstim.jl where Lotka-Volterra parameters are simultaneously estimated from synthetic data.

# Optimization problem 
cost_function = build_loss_objective(prob, Tsit5(), L2Loss(t, measurewindow; data_weight = weight),
                                     maxiters = 10000, verbose = true)
optprob = Optimization.OptimizationProblem(cost_function, p0, lb = p_lb, ub = p_ub)
opt_res = solve(optprob, BFGS())

My question is: I know I can use a custom loss function, but are there any examples of how to write it properly?
Again, sorry in advance if the question sounds dumb, hope someone can help me out, thanks.

1 Like

There are plenty of examples and tutorials of doing parameter estimation with your own loss in the SciMLSensitivity docs. There’s nothing specific to know other than writing good julia code so it’s not terribly slow :smile:

1 Like

DiffEqParamEstim.jl is a purposely constrained interface for simplicity. If you need support for completely general loss functions, use SciMLSensitivity.jl directly.

1 Like