numpy.polynomial.hermite_e.hermefit(x, y, deg, rcond=None, full=False, w=None)
[source]
Least squares fit of Hermite series to data.
Return the coefficients of a HermiteE 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, one for each column of y
, and the resulting coefficients are stored in the corresponding columns of a 2-D return. The fitted polynomial(s) are in the form
where n
is deg
.
Parameters: |
|
---|---|
Returns: |
|
Warns: |
|
See also
chebfit
, legfit
, polyfit
, hermfit
, polyfit
hermeval
hermevander
hermeweight
linalg.lstsq
scipy.interpolate.UnivariateSpline
The solution is the coefficients of the HermiteE series p
that minimizes the sum of the weighted squared errors
where the are the weights. This problem is solved by setting up the (typically) overdetermined matrix equation
where V
is the pseudo Vandermonde matrix of x
, the elements of c
are the coefficients to be solved for, and the elements of y
are the observed values. This equation is then solved using the singular value decomposition of V
.
If some of the singular values of V
are so small that they are neglected, then a RankWarning
will be issued. This means that the coefficient values may be poorly determined. Using a lower order fit will usually get rid of the warning. The rcond
parameter can also be set to a value smaller than its default, but the resulting fit may be spurious and have large contributions from roundoff error.
Fits using HermiteE series are probably most useful when the data can be approximated by sqrt(w(x)) * p(x)
, where w(x)
is the HermiteE weight. In that case the weight sqrt(w(x[i])
should be used together with data values y[i]/sqrt(w(x[i])
. The weight function is available as hermeweight
.
[1] | Wikipedia, “Curve fitting”, https://en.wikipedia.org/wiki/Curve_fitting |
>>> from numpy.polynomial.hermite_e import hermefit, hermeval >>> x = np.linspace(-10, 10) >>> np.random.seed(123) >>> err = np.random.randn(len(x))/10 >>> y = hermeval(x, [1, 2, 3]) + err >>> hermefit(x, y, 2) array([ 1.01690445, 1.99951418, 2.99948696]) # may vary
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.polynomial.hermite_e.hermefit.html