Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions nbs/common.base_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -916,24 +922,24 @@
" # 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",
" y_idx=y_idx,\n",
" )\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",
Expand Down Expand Up @@ -1015,24 +1021,24 @@
" # 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",
" y_idx=y_idx,\n",
" )\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",
Expand Down
20 changes: 10 additions & 10 deletions neuralforecast/common/_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,24 +981,24 @@ 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,
y_idx=y_idx,
)

# 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)
Expand Down Expand Up @@ -1087,24 +1087,24 @@ 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,
y_idx=y_idx,
)

# 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)
Expand Down