python时间序列滞后命令,时间序列在Python中的时间延迟嵌入

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

Time Series is 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]]

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]]

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

Time delay embedding with w and g

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

Output:

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]])

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

Update 1

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

Update 2

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值