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

Feat/strided dataset for torch and regression models #2624

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

madtoinou
Copy link
Collaborator

@madtoinou madtoinou commented Dec 19, 2024

Checklist before merging this PR:

  • Mentioned all issues that this PR fixes or addresses.
  • Summarized the updates of this PR under Summary.
  • Added an entry under Unreleased in the Changelog.

Fixes #2621, fixes #1064, fixes #940, fixes #1487.

Summary

  • added the stride argument to the torch models datasets and the tabularization methods
  • updated the tests accordingly

Other Information

As discussed offline, using limit_train_batches with max_samples_per_ts=None should allow to obtain uniformly selected training samples when using torch-based models. Changing the way the samples are retained when max_samples_per_ts!=None is hence not a priority and will be tackled in a separate PR.

Copy link

codecov bot commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.19%. Comparing base (b441192) to head (c375832).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2624      +/-   ##
==========================================
- Coverage   94.24%   94.19%   -0.05%     
==========================================
  Files         141      141              
  Lines       15466    15475       +9     
==========================================
+ Hits        14576    14577       +1     
- Misses        890      898       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @madtoinou, this looks very good already 🚀

I left some suggestions, mainly regarding:

  • add support to TorchForecastingModel.fit()
  • we should extract samples starting from the end of the series in both cases (TFM already does that, RegressionModel not yet)
  • add support to HorizonBasedDataset

Comment on lines 782 to 783
stride
The number of time steps between consecutive entries.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try to make this a bit more informative (and everywhere else where it's documented).

  • let's not add another wording like "entries" (we already have samples, osbservations, ...).
  • make more clear that we create the training set by extracting samples with stride from the series
  • does it take from start or end?
  • Maybe mention that this should be used with caution regarding predict, historical forecasts, ... that one should apply it only on the same stridden scenario

darts/utils/data/shifted_dataset.py Outdated Show resolved Hide resolved
darts/utils/data/shifted_dataset.py Show resolved Hide resolved
@@ -576,6 +585,7 @@ def create_lagged_prediction_data(
check_inputs: bool = True,
use_moving_windows: bool = True,
concatenate: bool = True,
stride: int = 1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be supported for prediction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that it should be supported in predict() as it might cause a lot of issues but I need it in create_lagged_prediction_data() for the optimized historical forecast with auto-regression.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh like roll_size for the torch models @madtoinou? If so then I would use that name here as well :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no, here, I need to be able to generate a strided prediction dataset for historical forecasts in order to predict all the horizons at once. The rolling is going to happen in another function.

darts/models/forecasting/regression_model.py Show resolved Hide resolved
darts/utils/data/tabularization.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -12,6 +12,7 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
**Improved**

- New model: `StatsForecastAutoTBATS`. This model offers the [AutoTBATS](https://nixtlaverse.nixtla.io/statsforecast/src/core/models.html#autotbats) model from Nixtla's `statsforecasts` library. [#2611](https://github.com/unit8co/darts/pull/2611) by [He Weilin](https://github.com/cnhwl).
- Added a `stride` argument to the `Dataset` classes (torch-based models) and the fitting methods of the `RegressionModels` to reduce the size of the training set or apply elaborate training approaches. [#2624](https://github.com/unit8co/darts/pull/2529) by [Antoine Madrona](https://github.com/madtoinou)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mention somewhere below that it would be good to add stride also to TorchForecastingModel.predict(). Once that is done, we should update the changelog here

darts/tests/datasets/test_datasets.py Outdated Show resolved Hide resolved
darts/tests/datasets/test_datasets.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants