MCPcopy Create free account
hub / github.com/numpy/numpy / hermfit

Function hermfit

numpy/polynomial/hermite.py:1275–1404  ·  view source on GitHub ↗

Least squares fit of Hermite series to data. 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

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

Source from the content-addressed store, hash-verified

1273
1274
1275def hermfit(x, y, deg, rcond=None, full=False, w=None):
1276 """
1277 Least squares fit of Hermite series to data.
1278
1279 Return the coefficients of a Hermite series of degree `deg` that is the
1280 least squares fit to the data values `y` given at points `x`. If `y` is
1281 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1282 fits are done, one for each column of `y`, and the resulting
1283 coefficients are stored in the corresponding columns of a 2-D return.
1284 The fitted polynomial(s) are in the form
1285
1286 .. math:: p(x) = c_0 + c_1 * H_1(x) + ... + c_n * H_n(x),
1287
1288 where `n` is `deg`.
1289
1290 Parameters
1291 ----------
1292 x : array_like, shape (M,)
1293 x-coordinates of the M sample points ``(x[i], y[i])``.
1294 y : array_like, shape (M,) or (M, K)
1295 y-coordinates of the sample points. Several data sets of sample
1296 points sharing the same x-coordinates can be fitted at once by
1297 passing in a 2D-array that contains one dataset per column.
1298 deg : int or 1-D array_like
1299 Degree(s) of the fitting polynomials. If `deg` is a single integer
1300 all terms up to and including the `deg`'th term are included in the
1301 fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1302 degrees of the terms to include may be used instead.
1303 rcond : float, optional
1304 Relative condition number of the fit. Singular values smaller than
1305 this relative to the largest singular value will be ignored. The
1306 default value is len(x)*eps, where eps is the relative precision of
1307 the float type, about 2e-16 in most cases.
1308 full : bool, optional
1309 Switch determining nature of return value. When it is False (the
1310 default) just the coefficients are returned, when True diagnostic
1311 information from the singular value decomposition is also returned.
1312 w : array_like, shape (`M`,), optional
1313 Weights. If not None, the weight ``w[i]`` applies to the unsquared
1314 residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1315 chosen so that the errors of the products ``w[i]*y[i]`` all have the
1316 same variance. When using inverse-variance weighting, use
1317 ``w[i] = 1/sigma(y[i])``. The default value is None.
1318
1319 Returns
1320 -------
1321 coef : ndarray, shape (M,) or (M, K)
1322 Hermite coefficients ordered from low to high. If `y` was 2-D,
1323 the coefficients for the data in column k of `y` are in column
1324 `k`.
1325
1326 [residuals, rank, singular_values, rcond] : list
1327 These values are only returned if ``full == True``
1328
1329 - residuals -- sum of squared residuals of the least squares fit
1330 - rank -- the numerical rank of the scaled Vandermonde matrix
1331 - singular_values -- singular values of the scaled Vandermonde matrix
1332 - rcond -- value of `rcond`.

Callers

nothing calls this directly

Calls 1

_fitMethod · 0.80

Tested by

no test coverage detected