Skip to content

Commit

Permalink
Fix/nlinear normalization for multivariate series (#2072)
Browse files Browse the repository at this point in the history
* fix: properly slice x when normalizing the target features

* feat: updated changelog
  • Loading branch information
madtoinou authored Nov 18, 2023
1 parent 36a1c09 commit f196665
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
- Fixed a bug when using encoders with `RegressionModel` and series with a non-evenly spaced frequency (e.g. Month Begin). This raised an error during lagged data creation when trying to divide a pd.Timedelta by the ambiguous frequency. [#2034](https://github.com/unit8co/darts/pull/2034) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug when loading a `TorchForecastingModel` that was trained with a precision other than `float64`. [#2046](https://github.com/unit8co/darts/pull/2046) by [Freddie Hsin-Fu Huang](https://github.com/Hsinfu).
- Fixed broken links in the `Transfer learning` example notebook with publicly hosted version of the three datasets. [#2067](https://github.com/unit8co/darts/pull/2067) by [Antoine Madrona](https://github.com/madtoinou).
- Fixed a bug when using `NLinearModel` on multivariate series with covariates and `normalize=True`. [#2072](https://github.com/unit8co/darts/pull/2072) by [Antoine Madrona](https://github.com/madtoinou).

### For developers of the library:

Expand Down
4 changes: 3 additions & 1 deletion darts/models/forecasting/nlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def forward(
if self.normalize:
# get last values only for target features
seq_last = x[:, -1:, : self.output_dim].detach()
x = x - seq_last
# normalize the target features only (ignore the covariates)
x[:, :, : self.output_dim] = x[:, :, : self.output_dim] - seq_last

x = self.layer(x.view(batch, -1)) # (batch, out_len * out_dim * nr_params)
x = x.view(
Expand Down Expand Up @@ -174,6 +175,7 @@ def forward(

x = x.view(batch, self.output_chunk_length, self.output_dim, self.nr_params)
if self.normalize:
# model only forecasts target components, no need to slice
x = x + seq_last.view(seq_last.shape + (1,))
return x

Expand Down

0 comments on commit f196665

Please sign in to comment.