# Estimating parameters of ODEs leads to instability

**URL:** https://discourse.julialang.org/t/estimating-parameters-of-odes-leads-to-instability/96149
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [March 15, 2023, 8:42pm UTC](https://discourse.julialang.org/t/estimating-parameters-of-odes-leads-to-instability/96149 "2023-03-15T20:42:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![stepanoslejsek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stepanoslejsek/32/218476_2.png) [@stepanoslejsek](https://discourse.julialang.org/u/stepanoslejsek)
#### Post date: [March 15, 2023, 8:42pm UTC](https://discourse.julialang.org/t/estimating-parameters-of-odes-leads-to-instability/96149/1 "2023-03-15T20:42:58Z")

</div>

I have a system of ODEs in a form of:

```julia
  Dt(θ) ~ θ̇
  Dt(θ̇) ~ a₁ * θ̇ + a₂ * sin(ψ) + a₃ * ψ̇ + a₄ * u(t)
  Dt(ψ) ~ ψ̇
  Dt(ψ̇) ~ a₅ * θ̇ + a₆ * sin(ψ) + a₇ * ψ̇ + a₈ * u(t)

```

where a₁,…,a₈ are parameters to be estimated. But when I try to perform an optimization using examples from DiffEqParamEstim website, I always get an instability detection and aborting afterwards. I also get this error message: dt(3.552713678800501e-15) \<= dtmin(3.552713678800501e-15) at t=1.2645985507940618e-5. Aborting. There is either an error in your model specification or the true solution is unstable.

I tried to increase a maxiters value, I tried different loss functions and optimizers (from Optim.jl and NLopt.jl), various amount of initial conditions and stiff/non-stiff ODE solver, but nothing is helping.

Is there anything I can do to make the optimization working?

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [March 15, 2023, 11:34pm UTC](https://discourse.julialang.org/t/estimating-parameters-of-odes-leads-to-instability/96149/2 "2023-03-15T23:34:31Z")

</div>

I’ve not used DiffEqParamEstim, but I don’t think it would be too surprising that you run into areas of the parameter space that lead to instabilities when optimising. You could make use of `SciMLBase.successful_retcode` in your objective function, giving infinite loss whenever instabilities occur so that the solver goes away from it - see [Optimization-Based Methods · DiffEqParamEstim.jl](https://docs.sciml.ai/DiffEqParamEstim/stable/methods/optimization_based_methods/), “Note About Loss Functions” (use `SciMLBase.successful_retcode(sol)` rather than the `any((s.retcode != :Success for s in sol))` shown). Note that the message `dt(3.552713678800501e-15) <= dtmin(3.552713678800501e-15) at t=1.2645985507940618e-5. Aborting` is a warning rather than an error, and will be detected by `SciMLBase.successful_retcode(sol)` returning `false`.
