Core Module Documentation#
- class neuralprophet.time_net.DeepNet(d_inputs, d_outputs, d_hidden=32, num_hidden_layers=0)#
A simple, general purpose, fully connected network
- forward(x)#
This method defines the network layering and activation functions
- class neuralprophet.time_net.FlatNet(d_inputs, d_outputs)#
Linear regression fun
- forward(x)#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class neuralprophet.time_net.TimeNet(quantiles, config_trend=None, config_season=None, config_lagged_regressors: Optional[OrderedDict[str, LaggedRegressor]] = None, config_regressors=None, config_events: Optional[OrderedDict[str, Event]] = None, config_holidays=None, n_forecasts=1, n_lags=0, num_hidden_layers=0, d_hidden=None, id_list=['__df__'], nb_trends_modelled=1, nb_seasonalities_modelled=1)#
Linear time regression fun and some not so linear fun.
- A modular model that models classic time-series components
trend
seasonality
auto-regression (as AR-Net)
covariates (as AR-Net)
apriori regressors
events and holidays
by using Neural Network components. The Auto-regression and covariate components can be configured as a deeper network (AR-Net).
- all_covariates(covariates)#
Compute all covariate components.
- Parameters:
covariates (dict(torch.Tensor, float)) – dict of named covariates (keys) with their features (values) dims of each dict value: (batch, n_lags)
- Returns:
Forecast component of dims (batch, n_forecasts)
- Return type:
torch.Tensor
- all_seasonalities(s, meta)#
Compute all seasonality components.
- Parameters:
s (torch.Tensor, float) – dict of named seasonalities (keys) with their features (values) dims of each dict value (batch, n_forecasts, n_features)
meta (dict) –
- Metadata about the all the samples of the model input batch. Contains the following:
df_name
(list, str), time series ID corresponding to each sample of the input batch.
- Returns:
Forecast component of dims (batch, n_forecasts)
- Return type:
torch.Tensor
- property ar_weights#
sets property auto-regression weights for regularization. Update if AR is modelled differently
- auto_regression(lags)#
Computes auto-regessive model component AR-Net.
- Parameters:
lags (torch.Tensor, float) – Previous times series values, dims: (batch, n_lags)
- Returns:
Forecast component of dims: (batch, n_forecasts)
- Return type:
torch.Tensor
- compute_components(inputs, meta)#
This method returns the values of each model component.
Note
Time input is required. Minimum model setup is a linear trend.
- Parameters:
inputs (dict) –
Model inputs, each of len(df) but with varying dimensions
Note
Contains the following data:
- Model Inputs
time
(torch.Tensor , loat), normalized time, dims: (batch, n_forecasts)lags
(torch.Tensor, float), dims: (batch, n_lags)seasonalities
(torch.Tensor, float), dict of named seasonalities (keys) with their features (values), dims of each dict value (batch, n_forecasts, n_features)covariates
(torch.Tensor, float), dict of named covariates (keys) with their features (values), dims of each dict value: (batch, n_lags)events
(torch.Tensor, float), all event features, dims (batch, n_forecasts, n_features)``regressors``(torch.Tensor, float), all regressor features, dims (batch, n_forecasts, n_features)
- Returns:
Containing forecast coomponents with elements of dims (batch, n_forecasts)
- Return type:
dict
- covariate(lags, name)#
Compute single covariate component.
- Parameters:
lags (torch.Tensor, float) – Lagged values of covariate, dims: (batch, n_lags)
nam (str) – Mame of covariate, for attribution to corresponding model weights
- Returns:
Forecast component of dims (batch, n_forecasts)
- Return type:
torch.Tensor
- forward(inputs, meta=None)#
This method defines the model forward pass.
Note
Time input is required. Minimum model setup is a linear trend.
- Parameters:
inputs (dict) –
Model inputs, each of len(df) but with varying dimensions
Note
Contains the following data:
- Model Inputs
time
(torch.Tensor , loat), normalized time, dims: (batch, n_forecasts)lags
(torch.Tensor, float), dims: (batch, n_lags)seasonalities
(torch.Tensor, float), dict of named seasonalities (keys) with their features (values), dims of each dict value (batch, n_forecasts, n_features)covariates
(torch.Tensor, float), dict of named covariates (keys) with their features (values), dims of each dict value: (batch, n_lags)events
(torch.Tensor, float), all event features, dims (batch, n_forecasts, n_features)``regressors``(torch.Tensor, float), all regressor features, dims (batch, n_forecasts, n_features)
predict_mode
(bool), optional and only passed during prediction
meta (dict, default=None) –
Metadata about the all the samples of the model input batch.
Contains the following:
- Model Meta:
df_name
(list, str), time series ID corresponding to each sample of the input batch.
Note
The meta is sorted in the same way the inputs are sorted.
Note
The default None value allows the forward method to be used without providing the meta argument. This was designed to avoid issues with the library lr_finder https://github.com/davidtvs/pytorch-lr-finder while having
config_trend.trend_global_local="local"
. The turnaround consists on passing the same meta (dummy ID) to all the samples of the batch. Internally, this is equivalent to useconfig_trend.trend_global_local="global"
to find the optimal learning rate.
- Returns:
Forecast of dims (batch, n_forecasts, no_quantiles)
- Return type:
torch.Tensor
- get_covar_weights(name)#
sets property auto-regression weights for regularization. Update if AR is modelled differently
- get_event_weights(name)#
Retrieve the weights of event features given the name
- Parameters:
name (str) – Event name
- Returns:
Dict of the weights of all offsets corresponding to a particular event
- Return type:
OrderedDict
- get_reg_weights(name)#
Retrieve the weights of regressor features given the name
- Parameters:
name (string) – Regressor name
- Returns:
Weight corresponding to the given regressor
- Return type:
torch.tensor
- property get_trend_deltas#
trend deltas for regularization.
update if trend is modelled differently
- scalar_features_effects(features, params, indices=None)#
Computes events component of the model
- Parameters:
features (torch.Tensor, float) – Features (either additive or multiplicative) related to event component dims (batch, n_forecasts, n_features)
params (nn.Parameter) – Params (either additive or multiplicative) related to events
indices (list of int) – Indices in the feature tensors related to a particular event
- Returns:
Forecast component of dims (batch, n_forecasts)
- Return type:
torch.Tensor
- seasonality(features, name, meta=None)#
Compute single seasonality component.
- Parameters:
features (torch.Tensor, float) – Features related to seasonality component, dims: (batch, n_forecasts, n_features)
name (str) – Name of seasonality. for attribution to corresponding model weights.
meta (dict) –
- Metadata about the all the samples of the model input batch. Contains the following:
df_name
(list, str), time series ID corresponding to each sample of the input batch.
- Returns:
Forecast component of dims (batch, n_forecasts)
- Return type:
torch.Tensor
- trend(t, meta)#
Computes trend based on model configuration.
- Parameters:
t (torch.Tensor float) – normalized time, dim: (batch, n_forecasts)
meta (dict) –
- Metadata about the all the samples of the model input batch. Contains the following:
df_name
(list, str), time series ID corresponding to each sample of the input batch.
- Returns:
Trend component, same dimensions as input t
- Return type:
torch.Tensor
- neuralprophet.time_net.new_param(dims)#
Create and initialize a new torch Parameter.
- Parameters:
dims (list or tuple) – Desired dimensions of parameter
- Returns:
initialized Parameter
- Return type:
nn.Parameter