Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a covariate as time_varying_unknown_real to deepAR model #1472

Open
janavl opened this issue Dec 14, 2023 · 0 comments
Open

Adding a covariate as time_varying_unknown_real to deepAR model #1472

janavl opened this issue Dec 14, 2023 · 0 comments

Comments

@janavl
Copy link

janavl commented Dec 14, 2023

  • PyTorch-Forecasting version: 0.10.3
  • Torch version: 1.13.1
  • Python version: 3.9.11
  • Operating System:
  • PyTorch-Lightning version: 1.9.5

Expected behavior

I want to add a numerical feature to the deepAR model for which future values are unknown (the feature is the price of a product, that changes over time based on discounts, promotion periods etc. and is unknown for the future). Reading the DeepAR documentation, I expected to be able to add price as a time_varying_unkown_real in the TimeSeriesDataSet. I expected the model to run without errors.

Actual behavior

However, I receive the following error when fitting the model: input.size(-1) must be equal to input_size. Expected 244, got 245.

Code to reproduce the problem

training = TimeSeriesDataSet(
        data,
        time_idx="time_idx",
        allow_missing_timesteps=True,
        target="target_name",
        group_ids=["article"],
        min_encoder_length=args.min_encoder_length,
        max_encoder_length=args.max_encoder_length,
        min_prediction_length=args.min_prediction_length,
        max_prediction_length=args.max_prediction_length,
        static_categoricals=static_cat_cols,
        static_reals=[],
        time_varying_known_categoricals=args.known_categoricals + ["campaigns"],
        variable_groups={"campaigns": campaigns},
        time_varying_known_reals=["time_idx"],
        time_varying_unknown_categoricals=[],
        time_varying_unknown_reals=["target_name","price"],
        add_relative_time_idx=True,
        add_target_scales=True,
        add_encoder_length=True,
        target_normalizer=GroupNormalizer(
            groups=["article"],
            transformation=None,
            center=True,
            eps=1e-4,
        ), 
    )

train_dataloader = training.to_dataloader(
        train=True, batch_size=args.batch_size, num_workers=args.num_workers, shuffle=True
    )

model = DeepAR.from_dataset(
        training,
        cell_type="LSTM",
        rnn_layers=args.rnn_layers,
        learning_rate=args.learning_rate,
        hidden_size=args.hidden_dimension,
        dropout=args.dropout_rate,
        loss=loss_type,
        log_interval=1,
        optimizer="ranger",
        reduce_on_plateau_patience=4,
        time_varying_reals_decoder=['time_idx','price'],
        time_varying_reals_encoder=['time_idx','price','target_name'],
    )

trainer = pl.Trainer(
        max_epochs=args.max_epochs,
        gpus=n_gpus,
        weights_summary="top",
        gradient_clip_val=gradient_clip_value,
        gradient_clip_algorithm="value",
        callbacks=[early_stop_callback],
    )

trainer_object = trainer.fit(model, train_dataloaders=train_dataloader)

When I fit the model (trainer.fit()), it fails and gives error: input.size(-1) must be equal to input_size. Expected 244, got 245.

Please help me understand if it is possible to add unkown reals other than the target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant