Skip to content

Commit

Permalink
GFit -> GModelFit
Browse files Browse the repository at this point in the history
  • Loading branch information
gcalderone committed Mar 5, 2023
1 parent 86c9686 commit 4c37a58
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "GFit"
name = "GModelFit"
uuid = "ac42e6ba-c0bf-4fcf-827d-deea44b16255"
authors = ["Giorgio Calderone <[email protected]>"]
version = "0.1.0"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# GFit.jl
# GModelFit.jl

[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
[![DocumentationStatus](https://img.shields.io/badge/docs-stable-blue.svg?style=flat)](https://gcalderone.github.io/GFit.jl/)
[![DocumentationStatus](https://img.shields.io/badge/docs-stable-blue.svg?style=flat)](https://gcalderone.github.io/GModelFit.jl/)

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

## Installation

Install with:
```julia
]add GFit
]add GModelFit
```

## Example

```julia
using GFit
using GModelFit

# Prepare vectors with domain points, empirical measures and uncertainties
x = [0.1, 1.1, 2.1, 3.1, 4.1]
Expand All @@ -38,7 +38,7 @@ The output is as follows:
╭───────────┬────────────┬─────────────┬───────────┬───────────┬───────────┬─────────╮
│ Component │ Type │ Eval. count │ Min │ Max │ Mean │ NaN/Inf
├───────────┼────────────┼─────────────┼───────────┼───────────┼───────────┼─────────┤
│ main │ GFit.FComp │ 766.08825.8413.560
│ main │ GModelFit.FComp │ 766.08825.8413.560
╰───────────┴────────────┴─────────────┴───────────┴───────────┴───────────┴─────────╯

Parameters:
Expand Down
18 changes: 9 additions & 9 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```

## Exported symbols
The list of **GFit.jl** exported symbols is as follows:
The list of **GModelFit.jl** exported symbols is as follows:

```@docs
CartesianDomain{N}
Expand All @@ -32,14 +32,14 @@ values


## Non-exported symbols
The following symbols are not exported by the **GFit.jl** package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.
The following symbols are not exported by the **GModelFit.jl** package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.

```@docs
GFit.FitStats
GFit.FunctDesc
GFit.ModelSnapshot
GFit.Parameter
GFit.comptypes
GFit.mock
GFit.serialize
GModelFit.FitStats
GModelFit.FunctDesc
GModelFit.ModelSnapshot
GModelFit.Parameter
GModelFit.comptypes
GModelFit.mock
GModelFit.serialize
```
52 changes: 26 additions & 26 deletions docs/src/builtincomp.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("setup.jl")

# Built-in components

The **GFit.jl** provides several built-in components which may be used to build arbitrarily complex models.
The **GModelFit.jl** provides several built-in components which may be used to build arbitrarily complex models.


## FComp
Expand All @@ -20,15 +20,15 @@ In the first constructor `funct` is the Julia function, `deps` is a vector of de

#### Example
```@example abc
using GFit
using GModelFit
# Define a simple Julia function to evaluate a linear relationship
myfunc(x, b, m) = b .+ x .* m
# Prepare domain and a model with a FComp wrapping the previously defined function.
# Also specify the initial guess parameters.
dom = Domain(1:5)
model = Model(dom, :linear => GFit.FComp(myfunc, [:x], b=2, m=0.5))
model = Model(dom, :linear => GModelFit.FComp(myfunc, [:x], b=2, m=0.5))
# Fit model against data
data = Measures(dom, [4.01, 7.58, 12.13, 19.78, 29.04], 0.4)
Expand All @@ -37,7 +37,7 @@ dumpjson("ex_FComp", best, fitstats, data) # hide
show((best, fitstats)) # hide
```

In the second constructor a [`GFit.FunctDesc`](@ref) object is accepted, as generated by the [``](@ref) macro). The function is typically a mathematical expression combining any number of parameters and/or other component evaluations within the same model. The expression should be given in the form:
In the second constructor a [`GModelFit.FunctDesc`](@ref) object is accepted, as generated by the [``](@ref) macro). The function is typically a mathematical expression combining any number of parameters and/or other component evaluations within the same model. The expression should be given in the form:
```
@λ (x, [y, [further domain dimensions...],]
[comp1, [comp2, [further components ...],]]
Expand All @@ -50,7 +50,7 @@ The previous example can be rewritten as follows:

#### Examples
```@example abc
using GFit
using GModelFit
# Prepare domain and a linear model (with initial guess parameters)
dom = Domain(1:5)
Expand Down Expand Up @@ -105,7 +105,7 @@ println() # hide
To define the model we will rewrite the equation as `Ax - b = 0`, and define a model as follows
```@example abc
dom = Domain(length(b)) # dummy domain
model = Model(dom, GFit.FCompv(x -> A*x - b,
model = Model(dom, GModelFit.FCompv(x -> A*x - b,
[1, 1, 1]))
println() # hide
```
Expand All @@ -124,8 +124,8 @@ An offset and slope component for 1D and 2D domains.

The constructors are defined as follows:

- 1D: `GFit.Components.OffsetSlope(offset, x0, slope)`;
- 2D: `GFit.Components.OffsetSlope(offset, x0, y0, slopeX, slopeY)`;
- 1D: `GModelFit.Components.OffsetSlope(offset, x0, slope)`;
- 2D: `GModelFit.Components.OffsetSlope(offset, x0, y0, slopeX, slopeY)`;

The parameters are:

Expand All @@ -143,11 +143,11 @@ The parameters are:

#### Examples
```@example abc
using GFit
using GModelFit
# Prepare domain and a linear model using the OffsetSlope component
dom = Domain(1:5)
model = Model(dom, :linear => GFit.OffsetSlope(2, 0, 0.5))
model = Model(dom, :linear => GModelFit.OffsetSlope(2, 0, 0.5))
# Fit model against data
data = Measures(dom, [4.01, 7.58, 12.13, 19.78, 29.04], 0.4)
Expand All @@ -161,11 +161,11 @@ Note that the numerical results are identical to the previous example (where an

A similar example in 2D is as follows:
```@example abc
using GFit
using GModelFit
# Prepare domain and a linear model using the OffsetSlope component
dom = CartesianDomain(1:5, 1:5)
model = Model(dom, :plane => GFit.OffsetSlope(2, 0, 0, 0.5, 0.5))
model = Model(dom, :plane => GModelFit.OffsetSlope(2, 0, 0, 0.5, 0.5))
# Fit model against data
data = Measures(dom, [ 3.08403 3.46719 4.07612 4.25611 5.04716
Expand All @@ -186,18 +186,18 @@ A *n*-th degree polynomial function (*n > 1*) for 1D domains.

The constructor is defined as follows:

- `GFit.Polynomial(p1, p2, ...)`;
- `GModelFit.Polynomial(p1, p2, ...)`;
where `p1`, `p2`, etc. are the guess values for the coefficients of each degree of the polynomial.

The parameters are accessible via the `p` vector, as: `p[1]`, `p[2]`, etc.

#### Examples
```@example abc
using GFit
using GModelFit
# Prepare domain and a linear model using the Polynomial component
dom = Domain(1:5)
model = Model(dom, GFit.Polynomial(2, 0.5))
model = Model(dom, GModelFit.Polynomial(2, 0.5))
# Fit model against data
data = Measures(dom, [4.01, 7.58, 12.13, 19.78, 29.04], 0.4)
Expand All @@ -208,7 +208,7 @@ show((best, fitstats)) # hide

Note again that the numerical results are identical to the previous examples. Also note that the default name for a component (if none is provided) is `:main`. To use a 2nd degree polynomial we can simply replace the `:main` component with a new one:
```@example abc
model[:main] = GFit.Polynomial(2, 0.5, 1)
model[:main] = GModelFit.Polynomial(2, 0.5, 1)
best, fitstats = fit(model, data)
dumpjson("ex_Polynomial2", best, fitstats, data) # hide
show((best, fitstats)) # hide
Expand All @@ -222,9 +222,9 @@ A normalized Gaussian component for 1D and 2D domains.

The constructors are defined as follows:

- 1D: `GFit.Components.Gaussian(norm, center, sigma)`;
- 2D: `GFit.Components.Gaussian(norm, centerX, centerY, sigma)` (implies `sigmaX=sigmaY`, `angle=0`);
- 2D: `GFit.Components.Gaussian(norm, centerX, centerY, sigmaX, sigmaY, angle)`;
- 1D: `GModelFit.Components.Gaussian(norm, center, sigma)`;
- 2D: `GModelFit.Components.Gaussian(norm, centerX, centerY, sigma)` (implies `sigmaX=sigmaY`, `angle=0`);
- 2D: `GModelFit.Components.Gaussian(norm, centerX, centerY, sigmaX, sigmaY, angle)`;

The parameters are:

Expand All @@ -247,11 +247,11 @@ The parameters are:

#### Examples
```@example abc
using GFit
using GModelFit
# Prepare domain and model
dom = Domain(1:0.5:5)
model = Model(dom, GFit.Gaussian(1, 3, 0.5))
model = Model(dom, GModelFit.Gaussian(1, 3, 0.5))
# Fit model against data
data = Measures(dom, [0, 0.3, 6.2, 25.4, 37.6, 23., 7.1, 0.4, 0], 0.6)
Expand All @@ -263,15 +263,15 @@ show((best, fitstats)) # hide

A very common problem is to fit the histogram of a distribution with a Gaussian model. In the following example we will generate such distribution with `Random.randn`, and use the [Gnuplot.jl](https://github.com/gcalderone/Gnuplot.jl/) package to calculate the histogram and display the plot:
```@example abc
using Random, GFit, Gnuplot
using Random, GModelFit, Gnuplot
# Calculate histogram of the distribution
hh = hist(randn(10000), bs=0.25)
# Prepare domain and data and fit a model
dom = Domain(hh.bins)
data = Measures(dom, hh.counts, 1.)
model = Model(dom, GFit.Gaussian(1e3, 0, 1))
model = Model(dom, GModelFit.Gaussian(1e3, 0, 1))
best, fitstats = fit(model, data)
dumpjson("ex_Gaussian2", best, fitstats, data) # hide
show((best, fitstats)) # hide
Expand All @@ -289,15 +289,15 @@ saveas("gaussian") # hide
A similar problem in 2D can be handled as follows:

```@example abc
using Random, GFit, Gnuplot
using Random, GModelFit, Gnuplot
# Calculate histogram of the distribution
hh = hist(1 .+ randn(10000), 2 .* randn(10000))
# Prepare domain and data and fit a model
dom = CartesianDomain(hh.bins1, hh.bins2)
data = Measures(dom, hh.counts, 1.)
model = Model(dom, GFit.Gaussian(1e3, 0, 0, 1, 1, 0))
model = Model(dom, GModelFit.Gaussian(1e3, 0, 0, 1, 1, 0))
best, fitstats = fit(model, data)
dumpjson("ex_Gaussian2D", best, fitstats, data) # hide
show((best, fitstats)) # hide
Expand All @@ -324,7 +324,7 @@ The `SumReducer` component has no parameter.

#### Example
```@example abc
using GFit
using GModelFit
# Prepare domain and a linear model (with initial guess parameters)
dom = Domain(1:5)
Expand Down
Loading

0 comments on commit 4c37a58

Please sign in to comment.