diff --git a/nbs/common.base_model.ipynb b/nbs/common.base_model.ipynb index fb3cc777f..26f160791 100644 --- a/nbs/common.base_model.ipynb +++ b/nbs/common.base_model.ipynb @@ -210,14 +210,20 @@ " self.input_size_backup = input_size\n", " self.n_samples = n_samples\n", " if self.RECURRENT:\n", - " if hasattr(loss, 'horizon_weight') and loss.horizon_weight is not None and h_train != h:\n", - " warnings.warn(f'Setting h_train={h} to match the horizon_weight length.') \n", + " if (\n", + " hasattr(loss, \"horizon_weight\")\n", + " and loss.horizon_weight is not None\n", + " and h_train != h\n", + " ):\n", + " warnings.warn(\n", + " f\"Setting h_train={h} to match the horizon_weight length.\"\n", + " )\n", " h_train = h\n", " self.h_train = h_train\n", " self.inference_input_size = inference_input_size\n", " self.rnn_state = None\n", " self.maintain_state = False\n", - " \n", + "\n", " with warnings.catch_warnings(record=False):\n", " warnings.filterwarnings('ignore')\n", " # the following line issues a warning about the loss attribute being saved\n", @@ -916,16 +922,16 @@ " # Set exogenous\n", " hist_exog_current = None\n", " if self.hist_exog_size > 0:\n", - " hist_exog_current = hist_exog[:, :self.input_size + tau - 1]\n", + " hist_exog_current = hist_exog[:, :self.input_size + tau]\n", "\n", " futr_exog_current = None\n", " if self.futr_exog_size > 0:\n", - " futr_exog_current = futr_exog[:, :self.input_size + tau - 1]\n", + " futr_exog_current = futr_exog[:, :self.input_size + tau]\n", "\n", " # First forecast step\n", " y_hat[:, tau], insample_y = self._validate_step_recurrent_single(\n", - " insample_y=insample_y[:, :self.input_size + tau - 1],\n", - " insample_mask=insample_mask[:, :self.input_size + tau - 1],\n", + " insample_y=insample_y[:, :self.input_size + tau],\n", + " insample_mask=insample_mask[:, :self.input_size + tau],\n", " hist_exog=hist_exog_current,\n", " futr_exog=futr_exog_current,\n", " stat_exog=stat_exog,\n", @@ -933,7 +939,7 @@ " )\n", "\n", " # Horizon prediction recursively\n", - " for tau in range(self.horizon_backup):\n", + " for tau in range(1, self.horizon_backup):\n", " # Set exogenous\n", " if self.hist_exog_size > 0:\n", " hist_exog_current = hist_exog[:, self.input_size + tau - 1].unsqueeze(1)\n", @@ -1015,16 +1021,16 @@ " # Set exogenous\n", " hist_exog_current = None\n", " if self.hist_exog_size > 0:\n", - " hist_exog_current = hist_exog[:, :self.input_size + tau - 1]\n", + " hist_exog_current = hist_exog[:, :self.input_size + tau]\n", "\n", " futr_exog_current = None\n", " if self.futr_exog_size > 0:\n", - " futr_exog_current = futr_exog[:, :self.input_size + tau - 1]\n", + " futr_exog_current = futr_exog[:, :self.input_size + tau]\n", "\n", " # First forecast step\n", " y_hat[:, tau], insample_y = self._predict_step_recurrent_single(\n", - " insample_y=insample_y[:, :self.input_size + tau - 1],\n", - " insample_mask=insample_mask[:, :self.input_size + tau - 1],\n", + " insample_y=insample_y[:, :self.input_size + tau],\n", + " insample_mask=insample_mask[:, :self.input_size + tau],\n", " hist_exog=hist_exog_current,\n", " futr_exog=futr_exog_current,\n", " stat_exog=stat_exog,\n", @@ -1032,7 +1038,7 @@ " )\n", "\n", " # Horizon prediction recursively\n", - " for tau in range(self.horizon_backup):\n", + " for tau in range(1, self.horizon_backup):\n", " # Set exogenous\n", " if self.hist_exog_size > 0:\n", " hist_exog_current = hist_exog[:, self.input_size + tau - 1].unsqueeze(1)\n", diff --git a/neuralforecast/common/_base_model.py b/neuralforecast/common/_base_model.py index 26d992133..aa80c181b 100644 --- a/neuralforecast/common/_base_model.py +++ b/neuralforecast/common/_base_model.py @@ -981,16 +981,16 @@ def _validate_step_recurrent_batch( # Set exogenous hist_exog_current = None if self.hist_exog_size > 0: - hist_exog_current = hist_exog[:, : self.input_size + tau - 1] + hist_exog_current = hist_exog[:, : self.input_size + tau] futr_exog_current = None if self.futr_exog_size > 0: - futr_exog_current = futr_exog[:, : self.input_size + tau - 1] + futr_exog_current = futr_exog[:, : self.input_size + tau] # First forecast step y_hat[:, tau], insample_y = self._validate_step_recurrent_single( - insample_y=insample_y[:, : self.input_size + tau - 1], - insample_mask=insample_mask[:, : self.input_size + tau - 1], + insample_y=insample_y[:, : self.input_size + tau], + insample_mask=insample_mask[:, : self.input_size + tau], hist_exog=hist_exog_current, futr_exog=futr_exog_current, stat_exog=stat_exog, @@ -998,7 +998,7 @@ def _validate_step_recurrent_batch( ) # Horizon prediction recursively - for tau in range(self.horizon_backup): + for tau in range(1, self.horizon_backup): # Set exogenous if self.hist_exog_size > 0: hist_exog_current = hist_exog[:, self.input_size + tau - 1].unsqueeze(1) @@ -1087,16 +1087,16 @@ def _predict_step_recurrent_batch( # Set exogenous hist_exog_current = None if self.hist_exog_size > 0: - hist_exog_current = hist_exog[:, : self.input_size + tau - 1] + hist_exog_current = hist_exog[:, : self.input_size + tau] futr_exog_current = None if self.futr_exog_size > 0: - futr_exog_current = futr_exog[:, : self.input_size + tau - 1] + futr_exog_current = futr_exog[:, : self.input_size + tau] # First forecast step y_hat[:, tau], insample_y = self._predict_step_recurrent_single( - insample_y=insample_y[:, : self.input_size + tau - 1], - insample_mask=insample_mask[:, : self.input_size + tau - 1], + insample_y=insample_y[:, : self.input_size + tau], + insample_mask=insample_mask[:, : self.input_size + tau], hist_exog=hist_exog_current, futr_exog=futr_exog_current, stat_exog=stat_exog, @@ -1104,7 +1104,7 @@ def _predict_step_recurrent_batch( ) # Horizon prediction recursively - for tau in range(self.horizon_backup): + for tau in range(1, self.horizon_backup): # Set exogenous if self.hist_exog_size > 0: hist_exog_current = hist_exog[:, self.input_size + tau - 1].unsqueeze(1)