Skip to content

gcalderone/GModelFit.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GModelFit.jl

License DocumentationStatus

GModelFit is a general purpose, data-driven model fitting framework for Julia.

Warning

The code in version 0.3.0 underwent a signficant refactoring, and a few details may break your code. Please have a look at ChangeLog.md !!

Installation

Install with:

]add GModelFit

Example

using GModelFit

# Prepare vectors with domain points, empirical measures and uncertainties
x    = [0.1, 1.1, 2.1, 3.1, 4.1]
meas = [6.29, 7.27, 10.41, 18.67, 25.3]
unc  = [1.1, 1.1, 1.1, 1.2, 1.2]
dom  = Domain(x)
data = Measures(dom, meas, unc)

# Create a model using an explicit mathematical expression, and provide the
# initial guess values:
model = Model(@fd (x, a2=1, a1=1, a0=5) -> (a2 .* x.^2  .+  a1 .* x  .+  a0))

# Fit model to the data
bestfit, stats = fit(model, data)

The output is as follows:

(Components:
╭───────────┬───────┬───────┬─────────────┬───────────┬───────────┬───────────┬─────────╮
│ Component │ Type  │ #Free │ Eval. count │ Min       │ Max       │ Mean      │ NaN/Inf │
├───────────┼───────┼───────┼─────────────┼───────────┼───────────┼───────────┼─────────┤
│ main      │ FComp │ 3766.08825.8413.560       │
╰───────────┴───────┴───────┴─────────────┴───────────┴───────────┴───────────┴─────────╯

Parameters:
╭───────────┬───────┬────────┬──────────┬───────────┬───────────┬────────┬───────╮
│ Component │ Type  │ Param. │ Range    │ Value     │ Uncert.   │ Actual │ Patch │
├───────────┼───────┼────────┼──────────┼───────────┼───────────┼────────┼───────┤
│ main      │ FComp │ a2     │ -Inf:Inf1.2010.3051 │        │       │
│           │       │ a1     │ -Inf:Inf-0.1061.317 │        │       │
│           │       │ a0     │ -Inf:Inf6.0871.142 │        │       │
╰───────────┴───────┴────────┴──────────┴───────────┴───────────┴────────┴───────╯
, Fit results: #data: 5, #free pars: 3, red. fit stat.:     1.0129, Status: OK      
)