diff options
Diffstat (limited to 'numpy/polynomial/hermite.py')
-rw-r--r-- | numpy/polynomial/hermite.py | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index b9862ad5a..ace91d2e2 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -1297,9 +1297,16 @@ def hermfit(x, y, deg, rcond=None, full=False, w=None): """ Least squares fit of Hermite series to data. - Fit a Hermite series ``p(x) = p[0] * P_{0}(x) + ... + p[deg] * - P_{deg}(x)`` of degree `deg` to points `(x, y)`. Returns a vector of - coefficients `p` that minimises the squared error. + Return the coefficients of a Hermite 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 + + .. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x), + + where `n` is `deg`. Parameters ---------- @@ -1350,41 +1357,42 @@ def hermfit(x, y, deg, rcond=None, full=False, w=None): See Also -------- + chebfit, legfit, lagfit, polyfit, hermefit hermval : Evaluates a Hermite series. hermvander : Vandermonde matrix of Hermite series. - polyfit : least squares fit using polynomials. - chebfit : least squares fit using Chebyshev series. + hermweight : Hermite weight function linalg.lstsq : Computes a least-squares fit from the matrix. scipy.interpolate.UnivariateSpline : Computes spline fits. Notes ----- - The solution are the coefficients ``c[i]`` of the Hermite series - ``P(x)`` that minimizes the squared error + The solution is the coefficients of the Hermite series `p` that + minimizes the sum of the weighted squared errors - ``E = \\sum_j |y_j - P(x_j)|^2``. + .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2, - This problem is solved by setting up as the overdetermined matrix - equation + where the :math:`w_j` are the weights. This problem is solved by + setting up the (typically) overdetermined matrix equation - ``V(x)*c = y``, + .. math:: V(x) * c = w * y, - where ``V`` is the Vandermonde matrix of `x`, the elements of ``c`` are - the coefficients to be solved for, and the elements of `y` are the + where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the + coefficients to be solved for, `w` are the weights, `y` are the observed values. This equation is then solved using the singular value - decomposition of ``V``. + decomposition of `V`. - If some of the singular values of ``V`` are so small that they are + 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 coeficient 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 Hermite series are usually better conditioned than fits - using power series, but much can depend on the distribution of the - sample points and the smoothness of the data. If the quality of the fit - is inadequate splines may be a good alternative. + Fits using Hermite series are probably most useful when the data can be + approximated by ``sqrt(w(x)) * p(x)``, where `w(x)` is the Hermite + weight. In that case the wieght ``sqrt(w(x[i])`` should be used + together with data values ``y[i]/sqrt(w(x[i])``. The weight function is + available as `hermweight`. References ---------- |