# \[ANN\] GModelFit.jl: a model fitting framework for Julia

**URL:** <https://discourse.julialang.org/t/ann-gmodelfit-jl-a-model-fitting-framework-for-julia/95725>\
**Category:** Package Announcements\
**Created:** [March 8, 2023, 9:58am UTC](https://discourse.julialang.org/t/ann-gmodelfit-jl-a-model-fitting-framework-for-julia/95725 "2023-03-08T09:58:54Z")\
**Posts on this page:** 2\
**Page:** 1

<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, 9:58am UTC](https://discourse.julialang.org/t/ann-gmodelfit-jl-a-model-fitting-framework-for-julia/95725/1 "2023-03-08T09:58:54Z")

</div>

[ANN] GModelFit.jl: a model fitting framework for Julia.

Dear community, after a few years of testing and improving the user interface, the **GModelFit** data-driven model fitting framework for Julia is now released!!

The package allows to define complex models (both numerical and analytical) to be compared to empirical data. A non-linear least square minimizer varies the model parameters to reduce the residuals between model and data, thus providing the best fit parameter values (with uncertainties).

Links:

- repo: [GitHub - gcalderone/GModelFit.jl: A data-driven model fitting framework](https://github.com/gcalderone/GModelFit.jl)
- docs: [Home · GModelFit.jl](https://gcalderone.github.io/GModelFit.jl/)

Quick example:

```julia
using GModelFit
dom = Domain(0:0.01:5)
model = Model(dom, :bkg => GModelFit.OffsetSlope(1, 1, 0.1),
                   :l1 => GModelFit.Gaussian(1, 2, 0.2),
                   :l2 => GModelFit.Gaussian(1, 3, 0.4),
                   :main => SumReducer(:bkg, :l1, :l2))
data = GModelFit.mock(Measures, model)
best, res = fit(model, data)

```

The above code results in the following output:

```julia
(Components:
╭───────────┬──────────────────────────┬─────────────┬───────────┬───────────┬───────────┬─────────╮
│ Component │ Type │ Eval. count │ Min │ Max │ Mean │ NaN/Inf │
├───────────┼──────────────────────────┼─────────────┼───────────┼───────────┼───────────┼─────────┤
│ main │ SumReducer │ 204 │ 0.8851 │ 3.151 │ 1.543 │ 0 │
│ ├─ bkg │ GModelFit.OffsetSlope_1D │ 65 │ 0.8851 │ 1.398 │ 1.142 │ 0 │
│ ├─ l1 │ GModelFit.Gaussian_1D │ 87 │ 2.189e-49 │ 2.018 │ 0.2016 │ 0 │
│ └─ l2 │ GModelFit.Gaussian_1D │ 78 │ 3.608e-13 │ 1.007 │ 0.2 │ 0 │
╰───────────┴──────────────────────────┴─────────────┴───────────┴───────────┴───────────┴─────────╯

Parameters:
╭───────────┬────────┬───────┬───────────┬───────────┬────────┬───────╮
│ Component │ Param. │ Range │ Value │ Uncert. │ Actual │ Patch │
├───────────┼────────┼───────┼───────────┼───────────┼────────┼───────┤
│ bkg │ offset │ │ 0.9877 │ 0.009352 │ │ │
│ │ x0 │ │ 1 │ (FIXED) │ │ │
│ │ slope │ │ 0.1026 │ 0.004225 │ │ │
├───────────┼────────┼───────┼───────────┼───────────┼────────┼───────┤
│ l1 │ norm │ 0:Inf │ 1.01 │ 0.01883 │ │ │
│ │ center │ │ 2.002 │ 0.003727 │ │ │
│ │ sigma │ 0:Inf │ 0.1997 │ 0.003704 │ │ │
├───────────┼────────┼───────┼───────────┼───────────┼────────┼───────┤
│ l2 │ norm │ 0:Inf │ 1.002 │ 0.0288 │ │ │
│ │ center │ │ 3.005 │ 0.0102 │ │ │
│ │ sigma │ 0:Inf │ 0.3969 │ 0.01204 │ │ │
╰───────────┴────────┴───────┴───────────┴───────────┴────────┴───────╯
, Fit results:
    #Data : 501 Red. fit stat.: 1.0225 (DOF: 493)
    #Free : 8 Elapsed time : 0.011 s
    Status: OK
)

```

A quick plot of data and best fit model can be obtained with (e.g.) [Gnuplot.jl](https://github.com/gcalderone/Gnuplot.jl/):

```julia
using Gnuplot
@gp data best

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/8/181ccfe1ccfeced6ba89fba5bb5af042401bd39f.png)

(this new post replaces a previous one, wrote when the package still had the old name “DataFitting”: [[ANN] DataFitting.jl general purpose data fitting framework](https://discourse.julialang.org/t/ann-datafitting-jl-general-purpose-data-fitting-framework/8433))

Comments and suggestions (as well as PRs) are very welcome!!

---

<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 24, 2023, 10:30pm UTC](https://discourse.julialang.org/t/ann-gmodelfit-jl-a-model-fitting-framework-for-julia/95725/2 "2023-05-24T22:30:54Z")

</div>

This looks great, I’ll try it next time I need to fit something.
