Reputation: 85
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.
Upvotes: 3
Views: 5333
Reputation: 1119
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
Check documentation on used functions np.arange, np.reshape, broadcasting rules and indexing.
Upvotes: 4