numpy.polynomial.laguerre.lagfit

polynomial.laguerre.lagfit(x, y, deg, rcond=None, full=False, w=None)[源代码]

拉盖尔级数与数据的最小二乘拟合。

返回拉盖尔级数的系数 deg 这是符合数据值的最小二乘法 y 给定点 x .如果 y 是1-d,返回系数也将是1-d。如果 y 是否进行了二维多次拟合,每列一次 y ,生成的系数存储在二维返回的相应列中。拟合多项式的形式为

System Message: WARNING/2 (P(x)=C_0+C_1 * L_1(x) + ... + c_n * Lnn(x),)

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...(x) + ... + c_n * Lnn(x),\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 504 bytes). Transcript written on math.log.

在哪里? ndeg .

参数
x阵列状,形状(m,)

m采样点的x坐标 (x[i], y[i]) .

y阵列状,形状(m,)或(m,k)

采样点的Y坐标。通过传递一个每列包含一个数据集的二维数组,可以同时拟合多个共享相同X坐标的采样点数据集。

degint或一维数组

拟合多项式的度数。如果 deg 是一个整数,所有项都小于或等于 deg “这一术语包含在拟合中。对于numpy版本>=1.11.0,可以使用指定要包含项的度数的整数列表。

rcond可选浮动

拟合的相对条件数。相对于最大奇异值,小于此值的奇异值将被忽略。默认值是len(x)*eps,其中eps是浮点类型的相对精度,在大多数情况下约为2e-16。

full可选的布尔

开关决定返回值的性质。当它为假(默认值)时,仅返回系数,当同时返回奇异值分解的真实诊断信息时。

w :数组,形状 (M ,),可选阵列,形状(

砝码。如果不是没有,每个点的贡献 (x[i],y[i]) 拟合的权重为 w[i] . 理想情况下,选择权重是为了使产品的误差 w[i]*y[i] 都有相同的差异。默认值为无。

返回
coefndarray,形状(m,)或(m,k)

从低到高排列的拉盖尔系数。如果 y 为2-d,第k列数据的系数 y 列中 k .

[[residuals, rank, singular_values, rcond]]列表

只有当 full =真

resid——最小二乘拟合秩的平方残差之和——标度范德蒙矩阵Sv的数值秩——标度范德蒙矩阵Rcond的奇异值——标度范德蒙矩阵Rcond的值。 rcond .

有关详细信息,请参阅 numpy.linalg.lstsq .

警告
RankWarning

最小二乘拟合中系数矩阵的秩是不足的。只有在以下情况下才会发出警告: full =假。可通过以下方式关闭警告:

>>> import warnings
>>> warnings.simplefilter('ignore', np.RankWarning)

参见

numpy.polynomial.polynomial.polyfit
numpy.polynomial.legendre.legfit
numpy.polynomial.chebyshev.chebfit
numpy.polynomial.hermite.hermfit
numpy.polynomial.hermite_e.hermefit
lagval

计算拉盖尔级数。

lagvander

拉盖尔级数的伪范德蒙矩阵。

lagweight

拉盖尔权函数。

numpy.linalg.lstsq

从矩阵计算最小二乘拟合。

scipy.interpolate.UnivariateSpline

计算样条曲线拟合。

笔记

解是拉盖尔级数的系数。 p 使加权平方误差之和最小化

System Message: WARNING/2 (E=\sum j w_j^2*y_j-p(x_j)^2,)

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...sum j w_j^2*y_j-p(x_j)^2,\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...sum j w_j^2*y_j-p(x_j)^2,\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...sum j w_j^2*y_j-p(x_j)^2,\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...sum j w_j^2*y_j-p(x_j)^2,\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...sum j w_j^2*y_j-p(x_j)^2,\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...sum j w_j^2*y_j-p(x_j)^2,\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 548 bytes). Transcript written on math.log.

何处 w_j 是重量。这个问题是通过建立(典型的)超定矩阵方程来解决的。

System Message: WARNING/2 (V(x) * c = w * Y)

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 \begin{split}V(x) * c = w * Y\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 \begin{split}V(x) * c = w * Y\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 \begin{split}V(x) * c = w * Y\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 \begin{split}V(x) * c = w * Y\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 356 bytes). Transcript written on math.log.

在哪里? V 是的加权伪范德蒙矩阵 xc 是要求解的系数, w 是重量,和 y 是观察值。然后用奇异值分解法求解该方程。 V .

如果某些奇异值 V 是如此的小以至于被忽视,然后 RankWarning 将发布。这意味着系数值的确定可能很差。使用低阶拟合通常会消除警告。这个 rcond 也可以将参数设置为小于其默认值的值,但由此产生的拟合可能是虚假的,并且具有来自舍入误差的较大贡献。

当数据可以近似为 sqrt(w(x)) * p(x) 在哪里 w(x) 是拉盖尔的重量。在这种情况下,重量 sqrt(w(x[i])) 应与数据值一起使用 y[i]/sqrt(w(x[i])) . 重量功能可用为 lagweight .

工具书类

1

维基百科,“曲线拟合”,https://en.wikipedia.org/wiki/curve_fitting

实例

>>> from numpy.polynomial.laguerre import lagfit, lagval
>>> x = np.linspace(0, 10)
>>> err = np.random.randn(len(x))/10
>>> y = lagval(x, [1, 2, 3]) + err
>>> lagfit(x, y, 2)
array([ 0.96971004,  2.00193749,  3.00288744]) # may vary