polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False)¶
Least squares polynomial fit.
LAX-backend implementation of
Unlike NumPy’s implementation of polyfit,
jax.numpy.polyfit()will not warn on rank reduction, which indicates an ill conditioned matrix Also, it works best on rcond <= 10e-3 values.
Original docstring below.
Fit a polynomial
p(x) = p * x**deg + ... + p[deg]of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error in the order deg, deg-1, … 0.
The Polynomial.fit <numpy.polynomial.polynomial.Polynomial.fit> class method is recommended for new code as it is more stable numerically. See the documentation of the method for more information.
x (array_like, shape (M,)) – x-coordinates of the M sample points
y (array_like, shape (M,) or (M, K)) – y-coordinates of the sample points. Several data sets of sample points sharing the same x-coordinates can be fitted at once by passing in a 2D-array that contains one dataset per column.
deg (int) – Degree of the fitting polynomial
rcond (float, optional) – Relative condition number of the fit. Singular values smaller than this relative to the largest singular value will be ignored. The default value is len(x)*eps, where eps is the relative precision of the float type, about 2e-16 in most cases.
full (bool, optional) – Switch determining nature of return value. When it is False (the default) just the coefficients are returned, when True diagnostic information from the singular value decomposition is also returned.
w (array_like, shape (M,), optional) – Weights to apply to the y-coordinates of the sample points. For gaussian uncertainties, use 1/sigma (not 1/sigma**2).
cov (bool or str, optional) – If given and not False, return not just the estimate but also its covariance matrix. By default, the covariance are scaled by chi2/sqrt(N-dof), i.e., the weights are presumed to be unreliable except in a relative sense and everything is scaled such that the reduced chi2 is unity. This scaling is omitted if
cov='unscaled', as is relevant for the case that the weights are 1/sigma**2, with sigma known to be a reliable estimate of the uncertainty.
p (ndarray, shape (deg + 1,) or (deg + 1, K)) – Polynomial coefficients, highest power first. If y was 2-D, the coefficients for k-th data set are in
residuals, rank, singular_values, rcond – Present only if full = True. Residuals is sum of squared residuals of the least-squares fit, the effective rank of the scaled Vandermonde coefficient matrix, its singular values, and the specified value of rcond. For more details, see linalg.lstsq.
V (ndarray, shape (M,M) or (M,M,K)) – Present only if full = False and cov`=True. The covariance matrix of the polynomial coefficient estimates. The diagonal of this matrix are the variance estimates for each coefficient. If y is a 2-D array, then the covariance matrix for the `k-th data set are in
Wikipedia, “Curve fitting”, https://en.wikipedia.org/wiki/Curve_fitting
Wikipedia, “Polynomial interpolation”, https://en.wikipedia.org/wiki/Polynomial_interpolation