zalandoresearch / pytorch-ts

PyTorch based Probabilistic Time Series forecasting framework based on GluonTS backend
MIT License
1.21k stars 190 forks source link

Multivariate question #21

Closed lorrp1 closed 3 years ago

lorrp1 commented 3 years ago

Hello im trying to train using a simple detaframe made of {timestamp, a, b} in which a on time t is 0, 1, 2, 3 and b on time t + 1 is =a, it should be able to predict b simply by a.

but i cant understand how MultivariateGrouper works and what should be the "max_target_dim" also why in the example MultivariateEvaluator was used "quantiles=(np.arange(20)/20.0)[1:]"?

and is the "target_dim" in TempFlowEstimator the last one because that is what we want to predict or no?

kashif commented 3 years ago

@lorrp1 the multivariate grouper is just a helper utility to convert univariate datasets to be used in multivariate methods. You can directly construct a multivariate dataset by have the target be 2-dimensional (time, variates) and use it without the need for the grouper.

Also note the multivariate methods like tempflowEstimator work best when you have a large variate size as opposed to smaller 2-dim examples for which you can use other models...

hope this helps!

lorrp1 commented 3 years ago

@kashif i have tried with both the MultivariateGrouper and without:

training_data1 = ListDataset(
    [{"start":dclose.index[0] , "target":dclose[:train]}],
    freq = "W"
)

training_data = ListDataset(
    [
        { 'start':dclose.index[0], 'target': dclose[:train]},
        {'start': dlow.index[0], 'target': dlow[:train]}
    ],
    freq="W",
    one_dim_target=False,
)

trainGrouper = MultivariateGrouper ( max_target_dim = 2)
training_data = trainGrouper(training_data1)

device = torch.device("cuda" )
estimator = TransformerTempFlowEstimator (freq="W", 
                            prediction_length=prediction_length,
                            input_size=24,
                            target_dim = 2,
                            #num_stacks =10,
                            #dequantize=True,
                            #cell_type='GRU',
                            #d_model=16,
                            #num_heads=4,
                            trainer=Trainer(epochs=500,
                                            device=device, num_batches_per_epoch=50, batch_size=120))

predictor = estimator.train(training_data=training_data)

but get RuntimeError: Sizes of tensors must match except in dimension 0. Got 120 and 60 (The offending index is 0)

lorrp1 commented 3 years ago

@kashif hello, i have also tried the example here: https://github.com/awslabs/gluon-ts/issues/190 but ended up with another error: Tensors must have same number of dimensions: got 2 and 3

could you please provide an example without a custom dataset (without the one with metadata)?

in the example with the dataset the target is set to none (freq='H', target=None,...