linear_polyfit

sofia_redux.toolkit.fitting.polynomial.linear_polyfit(samples, order, exponents=None, error=1, mask=None, covar=False, ignorenans=True, info=None, product=None, **kwargs)[source]

Fit a polynomial to data samples using linear least-squares.

Creates a system of polynomial equations, solving Ax=B with linear least-squares. Polynomial exponents are generated following the rules of polynomial_exponents.

If the solution fails, all coefficients are set to NaN.

Parameters:
samplesarray_like of float (ndim + 1, n_points)

samples[0] should contain the independent values of the samples in the first dimension. samples[-1] should contain the dependent values of the samples If solving for two features, samples[1] contains the independent values of the samples in the second dimension. i.e. x = samples[0], y = samples[1], z = samples[2].

orderint or array_like of int

Either a scalar polynomial order to fit across all features or an array specifying the order to fit across each dimension.

exponentsnumpy.ndarray of (int or float) (n_coeffs, ndimensions)

If set will override order.

errorfloat or numpy.ndarray, optional

(n_points,) error in z

maskarray_like of bool

array where True indicates a value to use in fitting and False is a value to ignore. Overrides ignorenans.

covarbool, optional

If True, return the covariance

ignorenansbool, optional

If True, remove any sample points containing NaNs.

productnumpy.ndarray of numpy.float64, optional

Pre-calculated array to pass into polysys. Overrides orders and exponents.

infodict, optional

If provided will be updated with product and exponents

kwargsdict, optional

Currently does nothing. Just a place holder

Returns:
coefficients, exponents, [covariance]tuple of numpy.ndarray

The polynomial coefficients (ncoeffs,), the polynomial exponents (ncoeffs, ndim), and (optionally) the covariance matrix (ncoeffs, ncoeffs)