FittingObjectiveFunctions

About

FittingObjectiveFunctions.jl is a lightweight package without dependencies to create objective functions for model fitting. This package does not include optimizers/samplers.

Installation

The package can be installed with the following commands

using Pkg
Pkg.Registry.add()
Pkg.Registry.add(RegistrySpec(url = "https://github.com/Translational-Pain-Research/Translational-Pain-Julia-Registry"))
Pkg.add("FittingObjectiveFunctions")

Since the package is not part of the General registry the commands install the additional registry Translational-Pain-Julia-Registry first.

After the installation, the package can be used like any other package:

using FittingObjectiveFunctions

Simple example

Consider the following example data-set:

using Plots

X = collect(1:10)
Y = [1.0, 1.78, 3.64, 3.72, 5.33, 2.73, 7.52, 9.19, 6.73, 8.95]
ΔY = [0.38, 0.86, 0.29, 0.45, 0.66, 2.46, 0.39, 0.45, 1.62, 1.54]

scatter(X,Y, yerror = ΔY, legend=:none, xlabel = "X", ylabel="Y")
Example block output

Before objective functions can be created, the data needs to be summarized in a FittingData object:

data = FittingData(X,Y,ΔY)

Information about the model needs to be summarized in a ModelFunctions object. Here we choose a simple linear model $m(x,\lambda) = \lambda x$:

model = ModelFunctions((x,λ) -> λ*x)

A weighted least squares objective can be be constructed as follows:

lsq = lsq_objective(data,model)
#9 (generic function with 1 method)

The following plot (not part of this package) shows the connection between the data points, the parameter λ of the model m(x,λ) and the least squares objective lsq:

Example block output