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(config_trend=None, config_season=None, config_covar=None, config_regressors=None, config_events=None, config_holidays=None, n_forecasts=1, n_lags=0, num_hidden_layers=0, d_hidden=None)¶
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)¶
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)
- 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)¶
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 attributiun to corresponding model weights
- Returns
Forecast component of dims (batch, n_forecasts)
- Return type
torch.Tensor
- forward(inputs)¶
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)
- Returns
Forecast of dims (batch, n_forecasts)
- 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)¶
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 attributiun to corresponding model weights.
- Returns
Forecast component of dims (batch, n_forecasts)
- Return type
torch.Tensor
- trend(t)¶
Computes trend based on model configuration.
- Parameters
t (torch.Tensor float) – normalized time, dim: (batch, n_forecasts)
- 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