Skip to content

Commit eecfd0f

Browse files
authored
Merge branch 'master' into feature/pl_auto_batch_size
2 parents 35d1d58 + c3a6112 commit eecfd0f

6 files changed

Lines changed: 1572 additions & 734 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
8787
- Moved functions `retain_period_common_to_all()`, `series2seq()`, `seq2series()`, `get_single_series()` from `darts.utils.utils` to `darts.utils.ts_utils`.
8888
- Improvements to `ForecastingModel`: [#2269](https://github.com/unit8co/darts/pull/2269) by [Felix Divo](https://github.com/felixdivo).
8989
- Renamed the private `_is_probabilistic` property to a public `supports_probabilistic_prediction`.
90+
- Improvements to `RegressionModel`: [#2320](https://github.com/unit8co/darts/pull/2320) by [Felix Divo](https://github.com/felixdivo).
91+
- Added a progress bar when performing optimized historical forecasts (`retrain=False` and no autoregression) to display the series-level progress.
9092
- Improvements to `DataTransformer`: [#2267](https://github.com/unit8co/darts/pull/2267) by [Alicja Krzeminska-Sciga](https://github.com/alicjakrzeminska).
9193
- `InvertibleDataTransformer` now supports parallelized inverse transformation for `series` being a list of lists of `TimeSeries` (`Sequence[Sequence[TimeSeries]]`). This `series` type represents for example the output from `historical_forecasts()` when using multiple series.
9294
- New method `TorchForecastingModel.scale_batch_size()` that helps to find batch size automatically. [#2318](https://github.com/unit8co/darts/pull/2318) by [Bohdan Bilonoh](https://github.com/BohdanBilonoh)
9395

9496
**Fixed**
9597
- Fixed a bug in `quantile_loss`, where the loss was computed on all samples rather than only on the predicted quantiles. [#2284](https://github.com/unit8co/darts/pull/2284) by [Dennis Bader](https://github.com/dennisbader).
9698
- Fixed type hint warning "Unexpected argument" when calling `historical_forecasts()` caused by the `_with_sanity_checks` decorator. The type hinting is now properly configured to expect any input arguments and return the output type of the method for which the sanity checks are performed for. [#2286](https://github.com/unit8co/darts/pull/2286) by [Dennis Bader](https://github.com/dennisbader).
99+
- Fixed the order of the features when using component-wise lags so that they are grouped by values, then by components (before, were grouped by components, then by values). [#2272](https://github.com/unit8co/darts/pull/2272) by [Antoine Madrona](https://github.com/madtoinou).
97100
- Fixed a segmentation fault that some users were facing when importing a `LightGBMModel`. [#2304](https://github.com/unit8co/darts/pull/2304) by [Dennis Bader](https://github.com/dennisbader).
98101
- Fixed a bug when using a dropout with a `TorchForecasting` and pytorch lightning versions >= 2.2.0, where the dropout was not properly activated during training. [#2312](https://github.com/unit8co/darts/pull/2312) by [Dennis Bader](https://github.com/dennisbader).
99102

darts/models/forecasting/regression_model.py

Lines changed: 20 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from darts.models.forecasting.forecasting_model import GlobalForecastingModel
4444
from darts.timeseries import TimeSeries
4545
from darts.utils.data.tabularization import (
46-
add_static_covariates_to_lagged_data,
46+
_create_lagged_data_autoregression,
4747
create_lagged_component_names,
4848
create_lagged_training_data,
4949
)
@@ -1019,83 +1019,25 @@ def predict(
10191019
last_step_shift = t_pred - (n - step)
10201020
t_pred = n - step
10211021

1022-
np_X = []
1023-
# retrieve target lags
1024-
if "target" in self.lags:
1025-
if predictions:
1026-
series_matrix = np.concatenate(
1027-
[series_matrix, predictions[-1]], axis=1
1028-
)
1029-
# component-wise lags
1030-
if "target" in self.component_lags:
1031-
tmp_X = [
1032-
series_matrix[
1033-
:,
1034-
[lag - (shift + last_step_shift) for lag in comp_lags],
1035-
comp_i,
1036-
]
1037-
for comp_i, (comp, comp_lags) in enumerate(
1038-
self.component_lags["target"].items()
1039-
)
1040-
]
1041-
# values are grouped by component
1042-
np_X.append(
1043-
np.concatenate(tmp_X, axis=1).reshape(
1044-
len(series) * num_samples, -1
1045-
)
1046-
)
1047-
else:
1048-
# values are grouped by lags
1049-
np_X.append(
1050-
series_matrix[
1051-
:,
1052-
[
1053-
lag - (shift + last_step_shift)
1054-
for lag in self.lags["target"]
1055-
],
1056-
].reshape(len(series) * num_samples, -1)
1057-
)
1058-
# retrieve covariate lags, enforce order (dict only preserves insertion order for python 3.6+)
1059-
for cov_type in ["past", "future"]:
1060-
if cov_type in covariate_matrices:
1061-
# component-wise lags
1062-
if cov_type in self.component_lags:
1063-
tmp_X = [
1064-
covariate_matrices[cov_type][
1065-
:,
1066-
np.array(comp_lags) - self.lags[cov_type][0] + t_pred,
1067-
comp_i,
1068-
]
1069-
for comp_i, (comp, comp_lags) in enumerate(
1070-
self.component_lags[cov_type].items()
1071-
)
1072-
]
1073-
np_X.append(
1074-
np.concatenate(tmp_X, axis=1).reshape(
1075-
len(series) * num_samples, -1
1076-
)
1077-
)
1078-
else:
1079-
np_X.append(
1080-
covariate_matrices[cov_type][
1081-
:, relative_cov_lags[cov_type] + t_pred
1082-
].reshape(len(series) * num_samples, -1)
1083-
)
1084-
1085-
# concatenate retrieved lags
1086-
X = np.concatenate(np_X, axis=1)
1087-
# Need to split up `X` into three equally-sized sub-blocks
1088-
# corresponding to each timeseries in `series`, so that
1089-
# static covariates can be added to each block; valid since
1090-
# each block contains same number of observations:
1091-
X_blocks = np.split(X, len(series), axis=0)
1092-
X_blocks, _ = add_static_covariates_to_lagged_data(
1093-
X_blocks,
1094-
series,
1022+
# concatenate previous iteration forecasts
1023+
if "target" in self.lags and predictions:
1024+
series_matrix = np.concatenate([series_matrix, predictions[-1]], axis=1)
1025+
1026+
# extract and concatenate lags from target and covariates series
1027+
X = _create_lagged_data_autoregression(
1028+
target_series=series,
1029+
t_pred=t_pred,
1030+
shift=shift,
1031+
last_step_shift=last_step_shift,
1032+
series_matrix=series_matrix,
1033+
covariate_matrices=covariate_matrices,
1034+
lags=self.lags,
1035+
component_lags=self.component_lags,
1036+
relative_cov_lags=relative_cov_lags,
1037+
num_samples=num_samples,
10951038
uses_static_covariates=self.uses_static_covariates,
1096-
last_shape=self._static_covariates_shape,
1039+
last_static_covariates_shape=self._static_covariates_shape,
10971040
)
1098-
X = np.concatenate(X_blocks, axis=0)
10991041

11001042
# X has shape (n_series * n_samples, n_regression_features)
11011043
prediction = self._predict_and_sample(
@@ -1257,6 +1199,7 @@ def _optimized_historical_forecasts(
12571199
stride=stride,
12581200
overlap_end=overlap_end,
12591201
show_warnings=show_warnings,
1202+
verbose=verbose,
12601203
predict_likelihood_parameters=predict_likelihood_parameters,
12611204
**kwargs,
12621205
)
@@ -1273,6 +1216,7 @@ def _optimized_historical_forecasts(
12731216
stride=stride,
12741217
overlap_end=overlap_end,
12751218
show_warnings=show_warnings,
1219+
verbose=verbose,
12761220
predict_likelihood_parameters=predict_likelihood_parameters,
12771221
**kwargs,
12781222
)

0 commit comments

Comments
 (0)