# Parameter Estimation of ODE system where the response variables are not the state variables

**URL:** <https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171>\
**Category:** Optimization (Mathematical)\
**Tags:** question, diffeq\
**Created:** [August 23, 2022, 3:46am UTC](https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171 "2022-08-23T03:46:03Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 26, 2022, 12:40pm UTC](https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171/7 "2022-08-26T12:40:59Z")

</div>

> [@jonlym](#):
>
> I circumvented the issue by using [JuMP](https://jump.dev/JuMP.jl/stable/) instead of SciML. The code converges to the true values (i.e. `logk1 = 1.0`, `logk2 = 2.0`).

No, what actually happened here is you switch from Zygote to ForwardDiff. I think the issue really comes down to:

> [@jonlym](#):
>
> ```julia
> ζ_df = DataFrame(sol);
> rename!(ζ_df, ["z", "ζ1", "ζ2"]);
> ζ = Matrix(ζ_df[:, ["ζ1", "ζ2"]]);
> Fj = repeat(Fj0, size(ζ)[1]) .+ ζ * v_mat;
> 
> tot_loss = LinearAlgebra.norm(Fj .- Fj_obs, 2);
> 
> ```

DataFrame operations use try/catch internally, which seems to break Zygote. You can probably build an MWE that is directly doing loss functions on DataFrames without an ODE solve. That would be nice to isolate and open an issue on Zygote.jl for.

But for this, ForwardDiff is going to be faster anyways, so `adtype = Optimization.AutoForwardDiff();` is a better idea, and would fix your issue.

---

_[View the full topic](https://discourse.julialang.org/t/parameter-estimation-of-ode-system-where-the-response-variables-are-not-the-state-variables/86171)._
