时间序列在Python中的时间延迟嵌入 [英] Time Delay Embedding of Time Series in Python

查看:641
本文介绍了时间序列在Python中的时间延迟嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将时间序列数据作为numpy数组.我想生成像这样的数据的时间延迟嵌入:

I have Time series data as numpy array. I want to generate Time delay embedding of data like this:

时间序列是这样的:

    [[   1.           37.17]
     [   2.           36.99]
     [   3.           36.84]
     [   4.           37.57]
     [   5.           37.49]
     [   6.           37.45]
     [   7.           37.82]
     [   8.           37.95]
     [   9.           37.36]
     [   10.          37.84]
     [   11.           37.85]
     [   12.           37.12]]

假设我的窗口大小(w)= 4,间隙(g)=2.我们将每3个点选取一次,直到得到点=窗口大小以形成一个"w"维点.对于下一个"w"维点,我们将序列移位1,并对移位的序列重复相同的过程.这将给我们几个"w"维点,这些维点最终将存储在2D numpy数组中.当我们无法形成"w"维点时,即到达序列的末尾时,我们就会停止.

Suppose my window size (w) = 4 and gap (g) = 2. We will pick every 3rd point till we get points = window size to form one 'w' dimensional point. For next 'w' dimensional point we shift the series by 1 and repeat the same process for shifted series. This will give us several 'w' dimensional points which will eventually be stored in 2D numpy array. We stop when we cant form 'w' dimensional point i.e. when we reach end of series.

然后此系列的时间延迟嵌入应为:

Then time delay embedding for this series should be:

    [[ 37.17  37.57  37.82 37.84]
     [ 37.99  36.49  36.95 37.85]
     [ 37.84  37.45  36.36 37.12]]

我们将在该特定点处停止,因为对于4维中的下一个点,我们将用完第四个点.我有大约1600点的长时间序列,并且我希望参数w和g是可变的.该函数将使用给定的"w"和"g"以及时间序列,并吐出时间延迟嵌入".

We will stop at this particular point because for next point in 4 dimension we will run out of the fourth point. I have approximately 1600 points long time series and I want parameters w and g to be variable. The function will take 'w' and 'g' and time series as given and will spit out the Time Delay Embedding.

推荐答案

想法是生成重新索引矩阵

Idea is to generate reindexing matrix

A = np.array([ 37.17,  36.99,  36.84,  37.57,  37.49,  37.45, 
               37.82,  37.95,  37.36,  37.84,  37.85,  37.12])
w = 4
g = 2

使用wg

A[(np.arange(w)*(g+1))+ np.arange(np.max(a.shape[0] - (w-1)*(g+1), 0)).reshape(-1,1)]

输出:

array([[ 37.17,  37.57,  37.82,  37.84],
       [ 36.99,  37.49,  37.95,  37.85],
       [ 36.84,  37.45,  37.36,  37.12]])

如果A是矩阵[index, value],则添加值列索引A[n...) ,1]

if A is a matrix [index, value] then add value column index A[n...) ,1]

更新1

# incorrect step count calculation was replaced by a.shape[0]-(w-1)*(g+1)

更新2

# added max to avoid errors on impossible values of g and w


检查有关已使用功能的文档广播规则


Check documentation on used functions np.arange, np.reshape, broadcasting rules and indexing.

这篇关于时间序列在Python中的时间延迟嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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