Gnuplot在多项式拟合中表现得很奇怪.这是为什么? [英] Gnuplot behaves oddly in polynomial fit. Why is that?

查看:119
本文介绍了Gnuplot在多项式拟合中表现得很奇怪.这是为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个朋友在gnuplot中发现了一些关于简单多项式拟合的奇怪行为,有人可以解释吗?

A friend of mine discovered some odd behavior in gnuplot regarding a simple polynomial fit Can sombody explain this?

这是文件:

#!/usr/bin/gnuplot -p

f(x) = B*(x**4) + A
fit f(x) "data.txt" using ($1+273.14):2 via A, B

plot    "data.txt" using ($1+273.14):2 notitle,\
        f(x) notitle

数据为:

# content of data.txt
350 3.856
330 3.242
290 2.391
250 1.713
210 1.181
170 0.763
130 0.437

结果图是绿线.蓝线表示使用基本相同形式的另一种功能拟合得更好.对于绿线,A替换为常数(A = 0.2123,大约为B * 300 ^ 4)

The resulting plot is the green line. The blue line shows a far better fit using another function of basically the same form. For the green line A was replaced by a constant value (A = 0.2123 which is about B*300^4)

因此,绿线显然不是此处的最佳拟合,因为f(x) = B*(x**4) - 0.2123产生的结果要好得多,并且也采用B * x 4 + A的形式.在绿色拟合中,参数** A只是被忽略gnuplot ,并且根据拟合算法保持不变.为A和B设置不同的初始值似乎无济于事-A的值不会因其初始值而改变.我和我的朋友使用的是Ubuntu随附的标准Gnuplot版本:gnuplot 4.4补丁程序级别3.

So the green line is clearly not the best fit here since f(x) = B*(x**4) - 0.2123 yields far betterresults and is also of the form B*x4 + A. In the green fit the parameter **A is simply ignored by gnuplot and remains unchanged by the fitting algorithm. Setting different initial values for A and B doesn't seem to help much - the value of A never changes for its inital value. My friend and I are using the standard Gnuplot version that comes with Ubuntu: gnuplot 4.4 patchlevel 3.

推荐答案

这是一个很好的(涉及的)问题,我没有完整的答案,但希望以下内容能启发您.

This is a very good (and involved) questions that I don't have a complete answer for, but the following will hopefully be illuminating.

Fit使用最小二乘拟合例程( Levenberg-Marquardt ).迭代地收敛于一个好的"解决方案. FIT_LIMIT变量确定所需的解决方案的质量.默认情况下,FIT_LIMIT设置为(保守)1.e-5.显然,与更改A相比,通过更改迭代路由中的B值,您的数据收敛得更快.实际上,正如您已经注意到的那样,即使不接触变量A,也可以达到错误阈值.达到您的期望(您希望获得更好的拟合度,因此将FIT_LIMIT设置为较低的值-我将其设置为1.e-14),您会得到更好的结果.您在这里付出的代价是,收敛可能需要更长的时间才能收敛(或者甚至会发散-我不是拟合专家).这里的一个要点是,功能拟合更多的是一门艺术,而不是一门科学-而且没有最合适的东西,只有足够合适的东西.

Fit uses a least-squares fitting routine ( Levenberg–Marquardt ). which iteratively converges on a "good" solution. How good a solution is required is determined by the FIT_LIMIT variable. By default, FIT_LIMIT is set to (a conservative) 1.e-5. Apparently, your data converges much faster by changing the value of B in the iterative routing compared to changing A. In fact, as you've noticed, you can get under the error threshold without even touching variable A. However, if you crank up your expectations (You expect to obtain better fit, so you set FIT_LIMIT to a lower value -- I set it to 1.e-14), you'll get a much better result. The price you pay here is that the fit may take much longer to converge (or it may even diverge -- I'm not an expert in fitting). One take-away here is that function fitting is more of an art than a science -- and there is no such thing as a best fit, only a good enough fit.

还请注意,该算法会搜索残差平方的局部最小值(满足您给出的公差).它不能保证找到全局最小值.

Also note that the algorithm searches for a local minimization of the squares of the residuals (that meets the tolerance you've given). It doesn't guarantee that it finds a global minimum.

#!/usr/bin/gnuplot -p

FIT_LIMIT=1.e-14
f(x) =A +  B*(x**4)
fit f(x) "data.txt" using ($1+273.14):2 via A, B

plot     "data.txt" using ($1+273.14):2 notitle,\
         f(x) notitle

还请注意,如果您发现gnuplot收敛于错误的最小值,则可以通过执行以下操作播种"拟合例程:

Also note that if you find that gnuplot is converging on the wrong minimum, you can "seed" the fit routine by doing:

FIT_LIMIT=1.e-14
f(x) =A +  B*(x**4)
A=1.3  #initial guess for A
fit f(x) "data.txt" using ($1+273.14):2 via A, B

plot     "data.txt" using ($1+273.14):2 notitle,\
         f(x) notitle

这篇关于Gnuplot在多项式拟合中表现得很奇怪.这是为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆