fit¶
- nbi_stat.fit(f, *args, **kwargs)[source]¶
Unified interface for curve fitting
This function provides a unified interface for fitting functions to data. Exactly which kind of fit is used depends on the data passed.
If the function we provide is of the form
f(x,p) = sum_i^M p_i f_i(x)
- given as the sequence (f_1,…,f_M), we perform a linear curve fitting,
where the following arguments are
- The independent variable x - The dependent variable y - Optionally, the uncertainties delta
Otherwise, if the number of the following arguments is less than 3, then we perform an MLE curve fitting, where the arguments are
- The observations x, or bin boundaries and counts (b,x) - The initial values p_0 of the parameters
For binnned MLE, the bin boundaries must be one larger than the counts. Counts are either raw counts (density=False), number density (dN/dx, density=1), or normalized number density (1/N dN/dx, density=N - possibly a float)
If none of the above conditions are met, we perform a least-squares curve fit with the
subsequent arguments
- The independent variable x - The dependent variable y - The initial values p_0 of the parameters - Optionally, the uncertainties delta_y - Optionally, the uncertainties delta_x
Other arguments or keyword arguments are passed to the underlying functions.
- Parameters:
f (callable or sequence of callables) – Function to fit to data
args (tuple) – Further arguments
kwargs (dict) – Keyword arguments
See also
mle_fit
,lin_fit
,lsq_fit
,plot_fit
,plot_fit_func
,plot_fit_table
,chi2nu
,residuals