Skip to content

Commit

Permalink
[Minor] Structure component configurations to be more consistent (#1645)
Browse files Browse the repository at this point in the history
* remove double features map

* remove empty features map init

* add n_forecasts to config_model

* rename n_forecasts in forecaster to config_model.n_forecasts and remove n_lags/n_forecasts from TimeNet init

* remove features_map, add pass of config_ar to TimeDataset

* remove features_map, add pass of config_ar to TimeDataset

* reset predict_component stacker after seaonal predict

* keep self.n_forecasts for now

* fixes

* remove unused TimeDataset args

* fix predict_steps

* fix predict_steps

* fixes

* fix seasonal_componetns

* rename autoregression

* fix n_forecasts references

* ruff

* replace model_config.n_forecasts with config_model.n_forecasts

* move component configs to new file

* separation of config_components

* fix imports

* fix comp imports

* fix config imports

* fix

* fix typos

* fix lagged_reg

* fox

* fix reg

* fut

* standardize regressors

* create add functions for regressors

* d

* remove unused import
  • Loading branch information
ourownstory authored Sep 4, 2024
1 parent ca0952f commit 773b67a
Show file tree
Hide file tree
Showing 25 changed files with 646 additions and 720 deletions.
2 changes: 2 additions & 0 deletions docs/source/code/forecaster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Core Module Documentation
:maxdepth: 1

configure.py <configure>
configure_components.py <configure_components>
df_utils.py <df_utils>
event_utils.py <event_utils>
plot_forecast_plotly.py <plot_forecast_plotly>
Expand All @@ -14,6 +15,7 @@ Core Module Documentation
plot_model_parameters_matplotlib.py <plot_model_parameters_matplotlib>
time_dataset.py <time_dataset>
time_net.py <time_net>
utils_time_dataset.py <utils_time_dataset>
utils.py <utils>

.. automodule:: neuralprophet.forecaster
Expand Down
2 changes: 2 additions & 0 deletions docs/source/code/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Code Documentation

forecaster.py (NeuralProphet) <forecaster>
configure.py <configure>
configure_components.py <configure_components>
time_dataset.py <time_dataset>
time_net.py <time_net>
torch_prophet.py <torch_prophet>
Expand All @@ -23,6 +24,7 @@ Code Documentation
plot_model_parameters_plotly.py <plot_model_parameters_plotly>
plot_model_parameters_matplotlib.py <plot_model_parameters_matplotlib>
utils.py <utils>
utils_time_dataset.py <utils_time_dataset>
df_utils.py <df_utils>
hdays_utils.py <hdays_utils>
plot_utils.py <plot_utils>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"source": [
"if \"google.colab\" in str(get_ipython()):\n",
" # uninstall preinstalled packages from Colab to avoid conflicts\n",
" !pip uninstall -y torch notebook notebook_shim tensorflow tensorflow-datasets prophet torchaudio torchdata torchtext torchvision \n",
" !pip uninstall -y torch notebook notebook_shim tensorflow tensorflow-datasets prophet torchaudio torchdata torchtext torchvision\n",
" !pip install git+https://github.com/ourownstory/neural_prophet.git # may take a while\n",
" #!pip install neuralprophet # much faster, but may not have the latest upgrades/bugfixes\n",
"\n",
Expand Down Expand Up @@ -787,7 +787,7 @@
"outputs": [],
"source": [
"df = pd.read_csv(data_location + \"air_passengers.csv\")\n",
"future = m.make_future_dataframe(df, periods=3) # periods=m.n_forecasts, n_historic_predictions=False"
"future = m.make_future_dataframe(df, periods=3) # periods=m.config_model.n_forecasts, n_historic_predictions=False"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,62 +344,6 @@
"df_local = df_local[[\"ds\", \"y\"]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import neuralprophet.configure as configure"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from dataclasses import dataclass, field\n",
"# from typing import Callable, List, Optional\n",
"# from typing import OrderedDict as OrderedDictType\n",
"# from typing import Type, Union\n",
"# from collections import OrderedDict\n",
"\n",
"# @dataclass\n",
"# class Regressor:\n",
"# reg_lambda: Optional[float]\n",
"# normalize: str\n",
"# mode: str\n",
"\n",
"# @dataclass\n",
"# class ConfigFutureRegressors:\n",
"# model: str\n",
"# regressors: OrderedDict = field(init=False) # contains SeasonConfig objects\n",
"\n",
"# def __post_init__(self):\n",
"# self.regressors = OrderedDictType[str, Regressor]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# ConfigFutureRegressors(\n",
"# model='linear',\n",
"# ) # Opti"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# m.config_regressors"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/自回归.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ m = NeuralProphet(
weekly_seasonality=False,
daily_seasonality=False
)
m.highlight_nth_step_ahead_of_each_forecast(step_number=m.n_forecasts)
m.highlight_nth_step_ahead_of_each_forecast(step_number=m.config_model.n_forecasts)
```

您可以指定任何小于或等于`n_forecasts`的值到`step_number`参数。一旦你这样做,指标将看起来像下面。
Expand Down
6 changes: 3 additions & 3 deletions neuralprophet/components/future_regressors/neural_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def __init__(self, config, id_list, quantiles, n_forecasts, device, config_trend
if self.regressors_dims is not None:
# Regresors params
self.regressor_nets = nn.ModuleDict({})
self.regressors_layers = config.regressors_layers
self.layers = config.layers
# one net per regressor. to be adapted to combined network
for regressor in self.regressors_dims.keys():
# Nets for both additive and multiplicative regressors
regressor_net = nn.ModuleList()
# This will be later 1 + static covariates
d_inputs = 1
for d_hidden_i in self.regressors_layers:
for d_hidden_i in self.layers:
regressor_net.append(nn.Linear(d_inputs, d_hidden_i, bias=True))
d_inputs = d_hidden_i
# final layer has input size d_inputs and output size equal to no. of quantiles
Expand Down Expand Up @@ -77,7 +77,7 @@ def regressor(self, regressor_input, name):
Forecast component of dims (batch, n_forecasts, num_quantiles)
"""
x = regressor_input
for i in range(len(self.regressors_layers) + 1):
for i in range(len(self.layers) + 1):
if i > 0:
x = nn.functional.relu(x)
x = self.regressor_nets[name][i](x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def __init__(self, config, id_list, quantiles, n_forecasts, device, config_trend
if self.regressors_dims is not None:
# Regresors params
self.regressor_nets = nn.ModuleDict({})
self.regressors_layers = config.regressors_layers
self.layers = config.layers
# Combined network
for net_i, size_i in Counter([x["mode"] for x in self.regressors_dims.values()]).items():
# Nets for both additive and multiplicative regressors
regressor_net = nn.ModuleList()
# This will be later size_i(1 + static covariates)
d_inputs = size_i
for d_hidden_i in self.regressors_layers:
for d_hidden_i in self.layers:
regressor_net.append(nn.Linear(d_inputs, d_hidden_i, bias=True))
d_inputs = d_hidden_i
# final layer has input size d_inputs and output size equal to no. of quantiles
Expand Down Expand Up @@ -79,7 +79,7 @@ def regressors(self, regressor_inputs, mode):
Forecast component of dims (batch, n_forecasts, num_quantiles)
"""
x = regressor_inputs
for i in range(len(self.regressors_layers) + 1):
for i in range(len(self.layers) + 1):
if i > 0:
x = nn.functional.relu(x)
x = self.regressor_nets[mode][i](x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def __init__(self, config, id_list, quantiles, n_forecasts, device, config_trend
if self.regressors_dims is not None:
# Regresors params
self.regressor_nets = nn.ModuleDict({})
self.regressors_layers = config.regressors_layers
self.layers = config.layers
# Combined network
for net_i, size_i in Counter([x["mode"] for x in self.regressors_dims.values()]).items():
# Nets for both additive and multiplicative regressors
regressor_net = nn.ModuleList()
# This will be later size_i(1 + static covariates)
d_inputs = size_i
for d_hidden_i in self.regressors_layers:
for d_hidden_i in self.layers:
regressor_net.append(nn.Linear(d_inputs, d_hidden_i, bias=True))
d_inputs = d_hidden_i
# final layer has input size d_inputs and output size equal to no. of quantiles
Expand Down Expand Up @@ -80,7 +80,7 @@ def regressors(self, regressor_inputs, mode):
Forecast component of dims (batch, n_forecasts, num_quantiles)
"""
x = regressor_inputs
for i in range(len(self.regressors_layers) + 1):
for i in range(len(self.layers) + 1):
if i > 0:
x = nn.functional.relu(x)
x = self.regressor_nets[mode][i](x)
Expand Down
2 changes: 1 addition & 1 deletion neuralprophet/components/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_trend(config, n_forecasts, quantiles, id_list, num_trends_modelled, devi
Parameters
----------
config : configure.Trend
config : configure_components.Trend
n_forecasts : int
number of steps to forecast. Aka number of model outputs
quantiles : list
Expand Down
Loading

0 comments on commit 773b67a

Please sign in to comment.