MCPcopy Index your code
hub / github.com/numpy/numpy / chebfit

Function chebfit

numpy/polynomial/chebyshev.py:1554–1676  ·  view source on GitHub ↗

Least squares fit of Chebyshev series to data. Return the coefficients of a Chebyshev series of degree `deg` that is the least squares fit to the data values `y` given at points `x`. If `y` is 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple fits are done,

(x, y, deg, rcond=None, full=False, w=None)

Source from the content-addressed store, hash-verified

1552
1553
1554def chebfit(x, y, deg, rcond=None, full=False, w=None):
1555 """
1556 Least squares fit of Chebyshev series to data.
1557
1558 Return the coefficients of a Chebyshev series of degree `deg` that is the
1559 least squares fit to the data values `y` given at points `x`. If `y` is
1560 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1561 fits are done, one for each column of `y`, and the resulting
1562 coefficients are stored in the corresponding columns of a 2-D return.
1563 The fitted polynomial(s) are in the form
1564
1565 .. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x),
1566
1567 where `n` is `deg`.
1568
1569 Parameters
1570 ----------
1571 x : array_like, shape (M,)
1572 x-coordinates of the M sample points ``(x[i], y[i])``.
1573 y : array_like, shape (M,) or (M, K)
1574 y-coordinates of the sample points. Several data sets of sample
1575 points sharing the same x-coordinates can be fitted at once by
1576 passing in a 2D-array that contains one dataset per column.
1577 deg : int or 1-D array_like
1578 Degree(s) of the fitting polynomials. If `deg` is a single integer,
1579 all terms up to and including the `deg`'th term are included in the
1580 fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1581 degrees of the terms to include may be used instead.
1582 rcond : float, optional
1583 Relative condition number of the fit. Singular values smaller than
1584 this relative to the largest singular value will be ignored. The
1585 default value is ``len(x)*eps``, where eps is the relative precision of
1586 the float type, about 2e-16 in most cases.
1587 full : bool, optional
1588 Switch determining nature of return value. When it is False (the
1589 default) just the coefficients are returned, when True diagnostic
1590 information from the singular value decomposition is also returned.
1591 w : array_like, shape (`M`,), optional
1592 Weights. If not None, the weight ``w[i]`` applies to the unsquared
1593 residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1594 chosen so that the errors of the products ``w[i]*y[i]`` all have the
1595 same variance. When using inverse-variance weighting, use
1596 ``w[i] = 1/sigma(y[i])``. The default value is None.
1597
1598 Returns
1599 -------
1600 coef : ndarray, shape (M,) or (M, K)
1601 Chebyshev coefficients ordered from low to high. If `y` was 2-D,
1602 the coefficients for the data in column k of `y` are in column
1603 `k`.
1604
1605 [residuals, rank, singular_values, rcond] : list
1606 These values are only returned if ``full == True``
1607
1608 - residuals -- sum of squared residuals of the least squares fit
1609 - rank -- the numerical rank of the scaled Vandermonde matrix
1610 - singular_values -- singular values of the scaled Vandermonde matrix
1611 - rcond -- value of `rcond`.

Callers

nothing calls this directly

Calls 1

_fitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…