0

为什么scipy.signal.detrend在相同的数据上给出略有不同的结果?此外,根据是否包含关键字“线性”,它似乎给出了不同的结果(默认情况下,去趋势无论如何都是线性的)

编辑:我知道不准确性非常小,并且由于浮点运算,预计会出现一些不准确性。奇怪的是,同样的数据+函数,结果却是不同的。

from scipy.signal import detrend as scipy_detrend
from pylab import *

x = arange(10)
y = arange(10, dtype='int64')

subplot(211)
plot(x, scipy_detrend(y, type="linear"), label='scipy detrend linear')
plot(x, scipy_detrend(y), label='scipy detrend')
plot(x, detrend(y, "linear"), label='pylab detrend')

subplot(212)
plot(x, scipy_detrend(y, type="linear"), label='scipy detrend linear')
plot(x, scipy_detrend(y), label='scipy detrend')
plot(x, detrend(y, "linear"), label='pylab detrend')

show()

注:红线为pylab.detrend,蓝线为scipy.signal.detrend with linear keyword,绿线为scipy.signal.detrend 在此处输入图像描述

4

2 回答 2

4

您的数据是 arange(10),并且您的去趋势结果是 1e-15 的顺序,这意味着差异是由于浮点精度造成的。(您的去趋势结果已经比您的输入小 15 个数量级)

于 2013-10-22T08:06:19.060 回答
4

这是浮点舍入误差。在一般情况下,浮点错误不一定可以在相同 CPU、相同数据和相同代码上运行时重现,因为它可能会受到程序外部事件的影响(除非特别注意):

使用英特尔® 编译器的浮点结果的一致性或为什么我的应用程序不总是给出相同的答案?- Martyn J. Corden 博士、David Kreitzer

这似乎是一个常见问题解答

于 2013-10-22T09:22:43.213 回答