smpl.fit

Simplified Fitting.

Uses scipy.curve_fit (no x errors) or scipy.odr (with x errors).

Chi2(datax, datay, function, ff, **kwargs)

Chi2 - Goodness of Fit

R2(datax, datay, function, ff, **kwargs)

R2 - Coefficient of determination

auto(datax, datay[, funcs])

Automatically loop over functions and fit the best one.

data_split(datax, datay, **kwargs)

Split data + errors

fit(datax, datay, function, **kwargs)

Returns a fit of function to datax and datay.

fit_kwargs(kwargs)

Set default fit_kwargs if not set. ================== ================== ================== fit_kwargs default description ================== ================== ================== params None Initial fit parameters fixed_params True Enable fixing parameters by choosing the same-named variables from kwargs. maxfev 10000 Maximum function evaluations during fitting. epsfcn 0.0001 Suitable step length for jacobian approximation. xvar None Variable in fit function parameters that corresponds to the x axis. If it is None the last of the alphabetical sorted parameters is used. autotqdm True Auto fitting display tqdm fitter Fitter.AUTO Choose from :class:`Fitter`s. ================== ================== ==================.

fit_split(datax, datay, **kwargs)

Splits datax and datay into (x,y,xerr,yerr).

Functions

smpl.fit.Chi2(datax, datay, function, ff, **kwargs)[source]

Chi2 - Goodness of Fit

In general, if Chi-squared/Nd is of order 1.0, then the fit is reasonably good. Coversely, if Chi-squared/Nd >> 1.0, then the fit is a poor one.

References

https://www.phys.hawaii.edu/~varner/PHYS305-Spr12/DataFitting.html

class smpl.fit.Fitter(value)[source]

Different implementations to perform a fit.

smpl.fit.R2(datax, datay, function, ff, **kwargs)[source]

R2 - Coefficient of determination

In the best case, the modeled values exactly match the observed values, which results in R2 = 1. A baseline model, which always predicts the mean of y, will have R2 = 0. Models that have worse predictions than this baseline will have a negative R2.

References

https://en.wikipedia.org/wiki/Coefficient_of_determination

smpl.fit.auto(datax, datay, funcs=None, **kwargs)[source]

Automatically loop over functions and fit the best one.

Parameters

funcsfunction array

functions to consider as fit. Default all smpl.functions.

**kwargsoptional

see fit_kwargs().

Returns

The best fit function and it’s parameters and a lambda where the parameters are already applied to the function.

smpl.fit.data_split(datax, datay, **kwargs)[source]

Split data + errors

smpl.fit.fit(datax, datay, function, **kwargs)

Returns a fit of function to datax and datay.

Parameters

dataxarray_like

X data either as unp.uarray or np.array or list

datayarray_like

Y data either as unp.uarray or np.array or list

functionfunc

Fit function with parameters: x, params

**kwargsoptional

see fit_kwargs().

smpl.fit.fit_kwargs(kwargs)[source]

Set default fit_kwargs if not set. ================== ================== ================== fit_kwargs default description ================== ================== ================== params None Initial fit parameters fixed_params True Enable fixing parameters by choosing the same-named variables from kwargs. maxfev 10000 Maximum function evaluations during fitting. epsfcn 0.0001 Suitable step length for jacobian approximation. xvar None Variable in fit function parameters that corresponds to the x axis. If it is None the last of the alphabetical sorted parameters is used. autotqdm True Auto fitting display tqdm fitter Fitter.AUTO Choose from :class:`Fitter`s. ================== ================== ==================

Set default data_kwargs if not set. ================== ================== ================== data_kwargs default description ================== ================== ================== frange None Limit the fit to given range. First integer is the lowest and second the highest index. fselector None Function that takes x and y as parameters and returns an array mask in order to limit the data points for fitting. Alternatively a mask for selecting elements from datax and datay. sortbyx True Enable sorting the x and y data so that x is sorted. bins 0 Number of bins for histogram binunc poisson_dist Number of bins for histogram xerror True enable xerrors yerror True enable yerrors ================== ================== ==================

smpl.fit.fit_split(datax, datay, **kwargs)[source]

Splits datax and datay into (x,y,xerr,yerr).

Parameters

**kwargsoptional

see fit_kwargs().