Chi-SquaredFit v0.5.2 Chi2fit.Fit View Source

Implements fitting a distribution function to sample data. It minimizes the liklihood function.

Asymmetric Errors

To handle asymmetric errors the module provides three ways of determining the contribution to the likelihood function:

`simple` - value difference of the observable and model divided by the averaged error lower and upper bounds;
`asimple` - value difference of the observable and model divided by the difference between upper/lower bound and the observed
  value depending on whether the model is larger or smaller than the observed value;
`linear` - value difference of the observable and model divided by a linear tranformation (See below).

‘linear’: Linear transformation

Linear transformation that:

- is continuous in u=0,
- passes through the point sigma+ at u=1,
- asymptotically reaches 1-y at u->infinity
- pass through the point -sigma- at u=-1,
- asymptotically reaches -y at u->-infinity

References

[1] See https://arxiv.org/pdf/physics/0401042v1.pdf

Link to this section Summary

Types

Chi-squared statistic

Covariance matrix

Cumulative distribution mapping ‘x’ and parameters to a float in the range [0,1]

Tuple describing the parameter values and the distribution function

Observation with asymmetric bounds ‘y1 < y < y2’

Observation with symmetric errors ‘dy’

List of parameter ranges

Functions

Calculates the Chi-squared function for a list of observables

Probes the chi-squared surface within a certain range of the parameters

Link to this section Types

Link to this type chi2() View Source
chi2() :: float

Chi-squared statistic

Link to this type distribution() View Source
distribution() :: (x :: float, [parameter :: float] -> float)

Cumulative distribution mapping ‘x’ and parameters to a float in the range [0,1].

Link to this type model() View Source
model() :: {[float], distribution}

Tuple describing the parameter values and the distribution function.

Link to this type observable_asym() View Source
observable_asym() :: {x :: float, y :: float, y1 :: float, y2 :: float}

Observation with asymmetric bounds ‘y1 < y < y2’.

Link to this type observable_symm() View Source
observable_symm() :: {x :: float, y :: float, dy :: float}

Observation with symmetric errors ‘dy’.

Link to this type observables() View Source
observables() :: [observable]
Link to this type params() View Source
params() :: [{float, float}]

List of parameter ranges

Link to this section Functions

Link to this function chi2(observables, fun, penalties \\ fn _ -> 0.0 end, options \\ []) View Source
chi2(observables, (float -> float), (float -> float), Keyword.t) :: float

Calculates the Chi-squared function for a list of observables.

The observables are given as a list. Each observation has an error associated with it. The errors can be either symmetric or asymmetric.

A ‘penalties’-function is used to assign penalties and these contribute to the chi-squared function. It may be used to ‘forbid’ certain parameter, x combinations.

Options

`model` - Required. Determines the contribution to chi-squared taking the asymmetric errors into account.
        Vaid values are `:linear`, `:simple`, and `:asimple`. See Errors below

Errors

`simple` - Use for asymmetric errors when the sigma+ and sigma- are close to each other
`asimple` - Use for asymmetric errors when y-values are not bound.
`linear` - Use this model when the y-values ar bound between 0 and 1. Linear transformation that:
    - is continuous in u=0,
    - passes through the point sigma+ at u=1,
    - asymptotically reaches 1-y at u->infinity
    - pass through the point -sigma- at u=-1,
    - asymptotically reaches -y at u->-infinity
Link to this function chi2fit(observables, model, max \\ 100, error \\ nil, options \\ []) View Source

Fits observables to a known model.

Returns the found minimum chi-squared value, covariance matrix, gradient at the minimum, and the corresponding parameter values including error estimates. For a good fit check the following:

`chi2 per degree of freedom` - this should be about 1 or less,
`gradient` - at the minimum the gradient should be zero at all directions.

For asymmetric errors use the option model equal to linear. Rough chi-squared surfaces or if numerically unstable, use the option smoothing set to true.

Arguments

`observables` - list of measurements including errors,
`model` - `{parameters, fun}`: set of initial parameter values and a function to fit against the measurements

Options

`onstep` - call back function; it is called with a map with keys `delta`, `chi2`, and `params`,
`smoothing` - boolean value indicating whether the chi-squared is smoothened using a Gauss distribution. This
is used in case the surface is rough because of numerical instabilities to smoothen the surface,
`model` - The same values as in chi2/3 and chi2/4
Link to this function chi2probe(observables, parranges, fun_penalties, options) View Source
chi2probe(observables, [float], (... -> any), Keyword.t) :: {chi2 :: float, [parameters :: float], {[float], [float]}}

Probes the chi-squared surface within a certain range of the parameters.

It does so by randomly selecting parameter value combinations and calculate the chi-squared for the list of observations based on the selected parameter values. This routine is used to roughly probe the chi-squared surface and perform more detailed and expensive calculations to precisely determine the minimum by chi2fit/5.

Returns the minimum chi-squared found, the parameter values, and all probes that resulted in chi-squared difference less than 1 with the minimum. The parameter values found in this set correspond with the errors in determining the parameters.

Options

`num` or `probes` - the number of points to calculate,
`mark` - progress indicator: a keyword list with keys `m`, `c`, `x`, and `*`; the value must be a call back
function taking zero arguments. These are called when 1000, 100, 10, probes have been done. The value of
key `*` is called when a new chi-squared minimum has been found,
`smoothing` - boolean value indicating whether the chi-squared is smoothened using a Gauss distribution. This
is used in case the surface is rough because of numerical instabilities to smoothen the surface,
`model` - See chi2/3 and chi2/4