Polyfit¶
- class sofia_redux.toolkit.fitting.polynomial.Polyfit(*args, error=1, mask=None, covar=True, stats=True, robust=0.0, eps=0.01, maxiter=10, solver='gaussj', set_exponents=False, ignorenans=True, **kwargs)[source]¶
Bases:
Model
Fits and evaluates polynomials in N-dimensions.
Examples
>>> y, x = np.mgrid[:5, :5] >>> z = 1 + x * y + x ** 2 >>> poly = Polyfit(x, y, z, 2) >>> assert np.allclose(poly(x, y), z) >>> print(poly.get_coefficients()) [[ 1. 0. 1.] [ 0. 1. 0.] [-0. 0. 0.]]
- Attributes:
- coefficientsnumpy.ndarray (ncoeffs,)
Polynomial fit coefficients
- covariancenumpy.ndarray (ncoeffs, ncoeffs)
Polynomial fit covariance. Will be None if the covariance matrix was not calculated.
- exponentsnumpy.ndarray (ncoeffs, ndimensions)
Polynomial exponents
Methods Summary
evaluate
(independent_samples[, dovar])Evaluate the polynomial at independent values
get_coefficients
([covar])Return coefficients and covariance suitable for general
polynd
use.Initial fits of polynomial to samples
refit_data
(*args[, mask, error, covar])Refit samples
refit_mask
(mask[, covar])Place holder
Methods Documentation
- get_coefficients(covar=False)[source]¶
Return coefficients and covariance suitable for general
polynd
use.- Parameters:
- covarbool, optional
If True, return the covariance matrix as well.
- Returns:
- coefficients, [covariance]numpy.ndarray, (numpy.ndarray or None)
Notes
The (row, col) ordering is reversed in this case since we wish to order coefficients in the same order as the data features, which the general case usage of
polynd
expects, but numpy does not.
- refit_data(*args, mask=None, error=None, covar=False)[source]¶
Refit samples
- Parameters:
- argstuple of array_like
If one argument is supplied, it is assumed to be the dependent variable. Otherwise, all independent and dependent variables should be supplied. No other arguments should be supplied.
- maskarray_like of bool, optional
New user mask. If none is supplied then one will be created based on the
ignorenans
.- errorfloat or array_like, optional
New error. If None is supplied, the old error will be used.
- covarbool, optional
If True, calculate the covariance.