简体   繁体   English

使用傅立叶分析进行时间序列预测

[英]Using fourier analysis for time series prediction

For data that is known to have seasonal, or daily patterns I'd like to use fourier analysis be used to make predictions. 对于已知具有季节性或日常模式的数据,我希望使用傅立叶分析来进行预测。 After running fft on time series data, I obtain coefficients. 在运行时间序列数据fft后,我获得系数。 How can I use these coefficients for prediction? 如何使用这些系数进行预测?

I believe FFT assumes all data it receives constitute one period, then, if I simply regenerate data using ifft, I am also regenerating the continuation of my function, so can I use these values for future values? 我相信FFT假设它接收的所有数据构成一个周期,那么,如果我只是使用ifft重新生成数据,我也在重新生成我的函数的延续,那么我可以将这些值用于未来的值吗?

Simply put: I run fft for t=0,1,2,..10 then using ifft on coef, can I use regenerated time series for t=11,12,..20 ? 简单地说:我运行fft为t = 0,1,2,.. 10然后在coef上使用ifft,我可以使用重新生成的时间序列为t = 11,12,... 20?

I'm aware that this question may be not actual for you anymore, but for others that are looking for answers I wrote a very simple example of fourier extrapolation in Python https://gist.github.com/tartakynov/83f3cd8f44208a1856ce 我知道这个问题对你来说可能不再适用,但对于寻找答案的其他人,我在Python中写了一个非常简单的傅里叶外推的例子https://gist.github.com/tartakynov/83f3cd8f44208a1856ce

Before you run the script make sure that you have all dependencies installed (numpy, matplotlib). 在运行脚本之前,请确保已安装所有依赖项(numpy,matplotlib)。 Feel free to experiment with it. 随意尝试一下。 在此输入图像描述 PS Locally Stationary Wavelet may be better than fourier extrapolation. PS局部静止小波可能比傅立叶外推更好。 LSW is commonly used in predicting time series. LSW通常用于预测时间序列。 The main disadvantage of fourier extrapolation is that it just repeats your series with period N, where N - length of your time series. 傅立叶外推的主要缺点是它只是用周期N重复你的系列,其中N是你的时间序列的长度。

It sounds like you want a combination of extrapolation and denoising. 听起来你想要一个外推去噪的组合。

You say you want to repeat the observed data over multiple periods. 您说您想要在多个时段重复观察到的数据。 Well, then just repeat the observed data. 那么,只需重复观察到的数据。 No need for Fourier analysis. 无需傅立叶分析。

But you also want to find "patterns". 但你也想找到“模式”。 I assume that means finding the dominant frequency components in the observed data. 我认为这意味着在观察到的数据中找到主要频率成分。 Then yes, take the Fourier transform, preserve the largest coefficients, and eliminate the rest. 然后是,采用傅立叶变换,保留最大系数,并消除其余系数。

X = scipy.fft(x)
Y = scipy.zeros(len(X))
Y[important frequencies] = X[important frequencies]

As for periodic repetition: Let z = [x, x] , ie, two periods of the signal x . 至于周期性重复:设z = [x, x] ,即信号x两个周期。 Then Z[2k] = X[k] for all k in {0, 1, ..., N-1}, and zeros otherwise. 然后,对于{0,1,...,N-1}中的所有kZ[2k] = X[k] ,否则为零。

Z = scipy.zeros(2*len(X))
Z[::2] = X

When you run an FFT on time series data, you transform it into the frequency domain. 在时间序列数据上运行FFT时,会将其转换为频域。 The coefficients multiply the terms in the series (sines and cosines or complex exponentials), each with a different frequency. 系数乘以系列中的项(正弦和余弦或复指数),每个都具有不同的频率。

Extrapolation is always a dangerous thing, but you're welcome to try it. 外推总是一件危险的事情,但欢迎你试试。 You're using past information to predict the future when you do this: "Predict tomorrow's weather by looking at today." 当你这样做的时候,你正在使用过去的信息来预测未来:“通过今天的预测来预测明天的天气。” Just be aware of the risks. 请注意风险。

I'd recommend reading "Black Swan" . 我建议阅读“黑天鹅”

you can use the library that @tartakynov posted and, to not repeat exactly the same time series in the forcast (overfitting), you can add a new parameter to the function called n_param and fix a lower bound h for the amplitudes of the frequencies. 您可以使用@tartakynov发布的库,并且为了不在预测(过度拟合)中重复完全相同的时间序列,您可以向名为n_param的函数添加新参数,并为频率的幅度修复下限h

def fourierExtrapolation(x, n_predict,n_param):

usually you will find that, in a signal, there are some frequencies that have significantly higher amplitude than others, so, if you select this frequencies you will be able to isolate the periodic nature of the signal 通常你会发现,在一个信号中,有些频率的振幅明显高于其他频率,因此,如果你选择这个频率,你就能够隔离信号的周期性。

you can add this two lines who are determinated by certain number n_param 您可以添加由特定数字n_param确定的这两行

h=np.sort(x_freqdom)[-n_param]
x_freqdom=[ x_freqdom[i] if np.absolute(x_freqdom[i])>=h else 0 for i in range(len(x_freqdom)) ]

just adding this you will be able to forecast nice and smooth 只需添加此项,您就可以预测好而顺畅

another useful article about FFt: forecast FFt in R 关于FFt的另一篇有用的文章: 在R中预测FFt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM