Skip to content

Commit

Permalink
feat: restrict input forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
AzulGarza committed Apr 25, 2024
1 parent 1e0b0a8 commit 603c666
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
15 changes: 13 additions & 2 deletions nbs/nixtla_client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,23 @@
" # - we dont have exogenous regegressors\n",
" # - and we dont want to produce pred intervals\n",
" # - no add history\n",
" restrict_input = self.finetune_steps == 0 and X_df is None and self.level is not None and not add_history\n",
" restrict_input = self.finetune_steps == 0 and X_df is None and not add_history\n",
" if restrict_input:\n",
" # add sufficient info to compute\n",
" # conformal interval\n",
" main_logger.info('Restricting input...')\n",
" new_input_size = 3 * self.input_size + max(self.model_horizon, self.h)\n",
" if self.level is not None:\n",
" # @AzulGarza\n",
" # this is an old opinionated decision\n",
" # about reducing the data sent to the api\n",
" # to reduce latency when\n",
" # a user passes level. since currently the model\n",
" # uses conformal prediction, we can change a minimum\n",
" # amount of data if the series are too large\n",
" new_input_size = 3 * self.input_size + max(self.model_horizon, self.h)\n",
" else:\n",
" # we only want to forecast\n",
" new_input_size = self.input_size\n",
" Y_df = Y_df.groupby(\"unique_id\").tail(new_input_size)\n",
" if X_df is not None:\n",
" X_df = X_df.groupby(\"unique_id\").tail(\n",
Expand Down
20 changes: 13 additions & 7 deletions nixtla/nixtla_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,17 +559,23 @@ def forecast(
# - we dont have exogenous regegressors
# - and we dont want to produce pred intervals
# - no add history
restrict_input = (
self.finetune_steps == 0
and X_df is None
and self.level is not None
and not add_history
)
restrict_input = self.finetune_steps == 0 and X_df is None and not add_history
if restrict_input:
# add sufficient info to compute
# conformal interval
main_logger.info("Restricting input...")
new_input_size = 3 * self.input_size + max(self.model_horizon, self.h)
if self.level is not None:
# @AzulGarza
# this is an old opinionated decision
# about reducing the data sent to the api
# to reduce latency when
# a user passes level. since currently the model
# uses conformal prediction, we can change a minimum
# amount of data if the series are too large
new_input_size = 3 * self.input_size + max(self.model_horizon, self.h)
else:
# we only want to forecast
new_input_size = self.input_size
Y_df = Y_df.groupby("unique_id").tail(new_input_size)
if X_df is not None:
X_df = X_df.groupby("unique_id").tail(
Expand Down

0 comments on commit 603c666

Please sign in to comment.