# \[DiffEqParamEstim.jl\] Add a findfit function

**URL:** <https://discourse.julialang.org/t/diffeqparamestim-jl-add-a-findfit-function/103384>\
**Category:** General Usage\
**Tags:** package, sciml, ordinarydiffeq\
**Created:** [August 30, 2023, 7:44pm UTC](https://discourse.julialang.org/t/diffeqparamestim-jl-add-a-findfit-function/103384 "2023-08-30T19:44:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Post date:** [August 30, 2023, 7:44pm UTC](https://discourse.julialang.org/t/diffeqparamestim-jl-add-a-findfit-function/103384/1 "2023-08-30T19:44:09Z")

</div>

Hy !  
I had written a Git issue a few months ago ( [Add a findfit function · Issue #220 · SciML/DiffEqParamEstim.jl (github.com)](https://github.com/SciML/DiffEqParamEstim.jl/issues/220)) on this subject but having had no response I take the liberty of making a post here.

Since the package [DiffEqParamEstim.jl](https://docs.sciml.ai/DiffEqParamEstim/stable/) is defined as "_a simple interface for users who want to quickly run standard parameter estimation routines for model calibration_ ", it would be interesting to add a `findfit` function on the model of the homonymous functions in _Wolfram Mathematica_ ([FindFit: Find parameters to best fit data—Wolfram Documentation](https://reference.wolfram.com/language/ref/FindFit.html) ; [Fitting system of Differential equations to a dataset - Online Technical Discussion Groups—Wolfram Community](https://community.wolfram.com/groups/-/m/t/126143)) or _SageMath_ ([Numerical Root Finding and Optimization - Numerical Optimization](https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html#sage.numerical.optimize.find_fit)) for example. This `findfit` function would combine a “generic” cost function, the definition of the `OptimizationProblem` and the solving. It would greatly simplify the use of DiffEqParamEstim.jl, which is certainly very efficient for complex situations, but which is a bit of a gas factory when you only have a small ODE system to fit on data.

I’m also convinced that the [`varmap_to_vars`](https://discourse.julialang.org/t/modelingtoolkit-jl-varmap-to-vars-function/98207) function, which is essential for combining ModelingToolkit and DiffEqParamEstim.jl, is extremely unintuitive and could be greatly improved. The documentation ([Frequently Asked Questions · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/basics/FAQ/)) alone is confusing. Just one example : unless I’m mistaken, the expression

```julia
pnew = varmap_to_vars([β => 3.0, c => 10.0, γ => 2.0], parameters(sys))
su

```

suggests that `pnew` is a new ordered version of `p`, when in fact it’s a list of indices (to which `Int.` must be applied to make them integer). Further down the page, the explanations “_Using ModelingToolkit with Optimization / Automatic Differentiation_” are also quite confusing, in my opinion.

fdekerm

---

<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 31, 2023, 11:34am UTC](https://discourse.julialang.org/t/diffeqparamestim-jl-add-a-findfit-function/103384/2 "2023-08-31T11:34:14Z")

</div>

> [@fdekerme](#):
>
> I had written a Git issue a few months ago ( [Add a findfit function · Issue #220 · SciML/DiffEqParamEstim.jl (github.com)](https://github.com/SciML/DiffEqParamEstim.jl/issues/220)) on this subject but having had no response I take the liberty of making a post here.

Sorry, I generally respond to every SciML issue but I don’t have this email in my inbox so I must’ve accidentally deleted it or something. Thanks for getting back in touch.

> [@fdekerme](#):
>
> Since the package [DiffEqParamEstim.jl](https://docs.sciml.ai/DiffEqParamEstim/stable/) is defined as "_a simple interface for users who want to quickly run standard parameter estimation routines for model calibration_ ", it would be interesting to add a `findfit` function on the model of the homonymous functions in _Wolfram Mathematica_ ([FindFit: Find parameters to best fit data—Wolfram Documentation](https://reference.wolfram.com/language/ref/FindFit.html) ; [Fitting system of Differential equations to a dataset - Online Technical Discussion Groups—Wolfram Community](https://community.wolfram.com/groups/-/m/t/126143)) or _SageMath_ ([Numerical Root Finding and Optimization - Numerical Optimization](https://doc.sagemath.org/html/en/reference/numerical/sage/numerical/optimize.html#sage.numerical.optimize.find_fit)) for example. This `findfit` function would combine a “generic” cost function, the definition of the `OptimizationProblem` and the solving. It would greatly simplify the use of DiffEqParamEstim.jl, which is certainly very efficient for complex situations, but which is a bit of a gas factory when you only have a small ODE system to fit on dat

Yes, that would be a nice contribution. I don’t plan to work on this but would accept a PR.

> [@fdekerme](#):
>
> I’m also convinced that the [`varmap_to_vars`](https://discourse.julialang.org/t/modelingtoolkit-jl-varmap-to-vars-function/98207) function, which is essential for combining ModelingToolkit and DiffEqParamEstim.jl, is extremely unintuitive and could be greatly improved. The documentation ([Frequently Asked Questions · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/basics/FAQ/)) alone is confusing. Just one example : unless I’m mistaken, the expression

People shouldn’t be using this so much anymore. `remake`, `prob[p]`, and `sol[p]` should be sufficient for what most people need to be doing.
