-
Notifications
You must be signed in to change notification settings - Fork 881
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
Optimisation of historical forecast for regression models #1885
Conversation
…ome issues for some scenario, lack of generalization
… properly handled, start of past covariates was not shifted
…historical forecast
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## master #1885 +/- ##
==========================================
- Coverage 93.82% 93.72% -0.11%
==========================================
Files 128 131 +3
Lines 12475 12646 +171
==========================================
+ Hits 11705 11852 +147
- Misses 770 794 +24
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, thanks a lot and congratulations @madtoinou! This will give such a boost to historical forecasting and backtesting for RegressionModels! 🚀
I left some comments and suggestions regarding what we discussed offline, to add some more information on specific parts, etc.
hist_fct_pc_start -= shift_start * unit | ||
hist_fct_fc_start -= shift_start * unit | ||
|
||
if model.output_chunk_length == forecast_horizon: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why this is not required for ocl < forecast_horizon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the other way around, forecast_horizon < ocl, and it's because these timestamps will be covered by the last prediction of length output_chunk_length
. By leaving them, the prediction will go too far.
require_auto_regression: bool = forecast_horizon > model.output_chunk_length | ||
|
||
# reshape and stride the forecast into (forecastable_index, forecast_horizon, n_components, num_samples) | ||
if model.multi_models: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part is tricky to understand, could you add some more comments that describe how the output of _predict_and_sample
is different for multi_model True/False, and share a bit more info for the slicing/reshaping.
We will be thankful in the future :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comments, let me know if it's enough
…sed some review comments
…storical forecasts
…_time_index creation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very, very cool stuff @madtoinou 🚀
I really only had some minor suggestions :)
- add some tests
- add support for optimization with encoders (or at least make it non-optimizable if they use encoders)
We can
) | ||
|
||
# retrieve stored covariates, usually handled by RegressionModel.predict() | ||
if past_covariates is None and self.past_covariate_series is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the current implemenetation models using encoders are not yet optimizable.
Do you think we could add support for this?
Edit: I'm thinking about adding something like a generate_fit_predict_encodings
which would make this a bit easier. Maybe we could drop optimization support for encoders until then.
Edit 2: I added the generate_fit_predict_encodings
in #1925. Would be cool to merge that one and then add the support for optimization with encodings here as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I tend to forget about the encoders... Thank you for implementing this, I will adjust this PR as soon as the other one is merged.
…8co/darts into refactor/hist_fc_regression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Super nice and great job @madtoinou 👏
We're ready to merge now once unit tests have passed (i adapted slightly to reduce testing time).
Fixes #1233
Summary
Reduce
historical_forecasts()
runtime for all theRegressionModels
using some tricks (enforceretrain=False
, use boundaries of the "forecastable indexes" instead of a range, predictions are vectorized with stride).Other Information
forecast_horizon > model.output_chunk_length
is not supported at the moment because it would require auto-regressionand.num_samples > 1
needs a bit of work before being fully supported[EDIT] : Some speed up statistics, also included some comparison between the refactored and "legacy" implementation.
Refactorization of the original method did not affect the performance, but it should be easier to read.
The ratio on the y axis is
(t1-t0)/(t2-t1)
Speed up when
last_points_only=True
When the conditions are met, the gain scales with the length of the forecasted period.
Speed up when
last_points_only=False
The bottleneck is the creation of the returned
TimeSeries
, the gain are less significant.