timeseriesAI / tsai

Time series Timeseries Deep Learning Machine Learning Python Pytorch fastai | State-of-the-art Deep Learning library for Time Series and Sequences in Pytorch / fastai
https://timeseriesai.github.io/tsai/
Apache License 2.0
5.21k stars 651 forks source link

Question about the multivariate GADF and GASF implementation #636

Closed alitirmizi23 closed 1 year ago

alitirmizi23 commented 1 year ago

Could you please elaborate a bit on the multivariate implementations of the GASF, GADF and MTF? I see that PyTs has univariate implementations, and you've adopted from there; but how exactly are you converting to multivariate?

oguiza commented 1 year ago

Hi @alitirmizi23, You're right. The way I handle it is by converting each multivariate time series sample into multiple samples of univariate time series. This way you can transform each univariate time series, and groups them together again. Here's an example: A batch of shape = (64, 24, 51) is reshaped into (64 x 24, 51), transformed into images (for example of 224x224 - shape = (64 x 24, 224, 224), and reshaped again into (64, 24, 224, 224).

Here's a code snippet with this example:

dsid = 'NATOPS'
X, y, splits = get_UCR_data(dsid, return_split=False)
print(X.shape)
tfms  = [None, [TSRegression()]]
batch_tfms = [TSNormalize(), TSToMTF()]
dls = get_ts_dls(X, y, splits=splits, tfms=tfms, batch_tfms=batch_tfms)
xb, yb = dls.one_batch()
print(xb.shape)
xb[0].show()

output: (360, 24, 51) torch.Size([64, 24, 224, 224])

Bear in mind that when the image is displayed, only the first 3 channels are displayed, even if the tensor contains 24 channels in this case. The model is then adapted to take 24 input channels.

image