Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K
JAX  documentation - Home

jax.numpy.polyfit

Contents

jax.numpy.polyfit#

jax.numpy.polyfit(x,y,deg,rcond=None,full=False,w=None,cov=False)[source]#

Least squares polynomial fit to data.

Jax implementation ofnumpy.polyfit().

Given a set of data points(x,y) and degree of polynomialdeg, thefunction finds a polynomial equation of the form:

\[y = p(x) = p[0] x^{deg} + p[1] x^{deg - 1} + ... + p[deg]\]
Parameters:
  • x (ArrayLike) – Array of data points of shape(M,).

  • y (ArrayLike) – Array of data points of shape(M,) or(M,K).

  • deg (int) – Degree of the polynomials. It must be specified statically.

  • rcond (float |None) – Relative condition number of the fit. Default value islen(x)*eps.It must be specified statically.

  • full (bool) – Switch that controls the return value. Default isFalse whichrestricts the return value to the array of polynomial coefficientsp.IfTrue, the function returns a tuple(p,resids,rank,s,rcond).It must be specified statically.

  • w (ArrayLike |None) – Array of weights of shape(M,). If None, all data points are consideredto have equal weight. If not None, the weight\(w_i\) is applied to theunsquared residual of\(y_i - \widehat{y}_i\) at\(x_i\), where\(\widehat{y}_i\) is the fitted value of\(y_i\). Default is None.

  • cov (bool) – Boolean or string. IfTrue, returns the covariance matrix scaledbyresids/(M-deg-1) along with polynomial coefficients. Ifcov='unscaled', returns the unscaled version of covariance matrix.Default isFalse.cov is ignored iffull=True. It must bespecified statically.

Returns:

  • An array polynomial coefficientsp iffull=False andcov=False.

  • A tuple of arrays(p,resids,rank,s,rcond) iffull=True. Where

    • p is an array of shape(M,) or(M,K) containing the polynomialcoefficients.

    • resids is the sum of squared residual of shape () or (K,).

    • rank is the rank of the matrixx.

    • s is the singular values of the matrixx.

    • rcond as the array.

  • A tuple of arrays(p,C) iffull=False andcov=True. Where

    • p is an array of shape(M,) or(M,K) containing the polynomialcoefficients.

    • C is the covariance matrix of polynomial coefficients of shape(deg+1,deg+1) or(deg+1,deg+1,1).

Return type:

Array |tuple[Array, …]

Note

Unlikenumpy.polyfit() implementation of polyfit,jax.numpy.polyfit()will not warn on rank reduction, which indicates an ill conditioned matrix.

See also

Examples

>>>x=jnp.array([3.,6.,9.,4.])>>>y=jnp.array([[0,1,2],...[2,5,7],...[8,4,9],...[1,6,3]])>>>p=jnp.polyfit(x,y,2)>>>withjnp.printoptions(precision=2,suppress=True):...print(p)[[ 0.2  -0.35 -0.14] [-1.17  4.47  2.96] [ 1.95 -8.21 -5.93]]

Iffull=True, returns a tuple of arrays as follows:

>>>p,resids,rank,s,rcond=jnp.polyfit(x,y,2,full=True)>>>withjnp.printoptions(precision=2,suppress=True):...print("Polynomial Coefficients:","\n",p,"\n",..."Residuals:",resids,"\n",..."Rank:",rank,"\n",..."s:",s,"\n",..."rcond:",rcond)Polynomial Coefficients:[[ 0.2  -0.35 -0.14][-1.17  4.47  2.96][ 1.95 -8.21 -5.93]]Residuals: [0.37 5.94 0.61]Rank: 3s: [1.67 0.47 0.04]rcond: 4.7683716e-07

Ifcov=True andfull=False, returns a tuple of arrays havingpolynomial coefficients and covariance matrix.

>>>p,C=jnp.polyfit(x,y,2,cov=True)>>>p.shape,C.shape((3, 3), (3, 3, 3))
Contents

[8]ページ先頭

©2009-2025 Movatter.jp