# \[ANN\] DataFitting.jl general purpose data fitting framework

**URL:** <https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433>\
**Category:** Optimization (Mathematical)\
**Tags:** fit\
**Created:** [January 17, 2018, 12:08pm UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433 "2018-01-17T12:08:53Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)\
**Post date:** [May 6, 2021, 12:11am UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433/21 "2021-05-06T00:11:29Z")

</div>

Interesting package. Like the multi-components parts.Will definitely test it out.

---

<div class="post-metadata">

**Author:** ![Djoull](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Djoull](https://discourse.julialang.org/u/Djoull)\
**Post date:** [May 7, 2021, 4:52pm UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433/23 "2021-05-07T16:52:40Z")

</div>

Just started testing it, already like it for its simplicity of use(very close to python lmfit, which I am used to).

Would you know if it is possible to pass arguments to the CMPFIT minimizer ? (such as xtol, maximum iterations, etc…) ?

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [May 10, 2021, 5:36pm UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433/24 "2021-05-10T17:36:08Z")

</div>

Yes:

```julia
mzer = GFit.cmpfit()
mzer.config.xtol = 1.e-6
mzer.config.maxfev = 0
bestfit = fit!(model, data, minimizer=mzer)

```

See [here](https://pages.physics.wisc.edu/~craigm/idl/cmpfit.html) for the list of options (section `CONFIGURING MPFIT()`).

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [May 11, 2021, 7:44pm UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433/25 "2021-05-11T19:44:24Z")

</div>

This looks like a great project, I’ll try it out next time I do fitting in julia.

FWIW I’d like to share my own attempt to mimic lmfit, you can get the full code at this gist: [minimal version of lmfit in julia · GitHub](https://gist.github.com/ggggggggg/9ce9934c65252be43c7ccc1dac24d8db)

Since it was just for my own quick project I tried to make it as easy to use as possible to get my fit done. I like having the ability to easily create a model from a function and have all the params names after the function arguments. I also like in lmfit how you can use default argument for functions and the model learns about both the parameter and the default value, though I never got that working.

Here is an example usage:

```julia
julia> x = 1:100; ydata = x.^2.5;

julia> f(x,a,b) = x.^a .+ b;

julia> model, params = model_and_params(f)
(Model("f", f, 2), Param[Param("a", val=NaN, min=-Inf, max=Inf, vary=true, unc=NA), Param("b", val=NaN, min=-Inf, max=Inf, vary=true, unc=NA)])

julia> params.a(val=3, min=1, max=4)

julia> params.b(val=.1, vary=false) # lets force the fit to be wrong, since our models are usually somewhat wrong on real data

julia> result=fit(model, params; x=x, y=ydata);

julia> result.params
2-element Array{Param,1}:
 Param("a", val=2.4999996296745217, min=1.0, max=4.0, vary=true, unc=3.987469111135028e-8)
 Param("b", val=0.1, min=-Inf, max=Inf, vary=false, unc=NA)

```

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [October 1, 2021, 5:51am UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433/26 "2021-10-01T05:51:20Z")

</div>

@gcalderone, the `GFit.jl` is a very nice package. Is it possible to combine several components that share (or have analytical relation) of a certain parameter? In the spectroscopy (characteristic X-rays) I’m fitting several overlapping gaussian peaks and I know apriori that all lines share the same width. So, doing fitting manually (e.g. using LsqFit.jl) I have a single model function that consists of several Gaussians, but shares a single \sigma .  
Is it possible to achieve this somehow also with GFit.jl?

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [March 8, 2023, 10:40am UTC](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433/27 "2023-03-08T10:40:07Z")

</div>

Dear all, the development took much longer than expected…  
However, the package is now released, although with a different name: GModelFit.jl (see [here](https://discourse.julialang.org/t/ann-gmodelfit-jl-a-model-fitting-framework-for-julia/95725)…

Comments welcome!

[Previous page](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433.md?page=1)
