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)

all_seasonalities(s)

Compute all seasonality components.

Parameters

s (dict(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)

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

(batch, n_forecasts)

Return type

forecast component of dims

compute_components(inputs)

This method returns the values of each model component.

Time input is required. Minimum model setup is a linear trend. :param inputs:

time (torch tensor float): normalized time

dims: (batch, n_forecasts)

lags (torch tensor, float): previous times series values.

dims: (batch, n_lags)

seasonalities (dict(torch tensor, float)): dict of named seasonalities (keys) with their features (values)

dims of each dict value: (batch, n_forecasts, n_features)

covariates (dict(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)

Returns

value

with elements of dims (batch, n_forecasts)

Return type

dict of forecast_component

covariate(lags, name)

Compute single covariate component.

Parameters
  • lags (torch tensor, float) – lagged values of covariate dims: (batch, n_lags)

  • name (str) – name of covariate. for attributiun to corresponding model weights.

Returns

forecast component of dims (batch, n_forecasts)

forward(inputs)

This method defines the model forward pass.

Time input is required. Minimum model setup is a linear trend. :param inputs:

time (torch tensor float): normalized time

dims: (batch, n_forecasts)

lags (torch tensor, float): previous times series values.

dims: (batch, n_lags)

seasonalities (dict(torch tensor, float)): dict of named seasonalities (keys) with their features (values)

dims of each dict value: (batch, n_forecasts, n_features)

covariates (dict(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)

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 (string) – Event name

Returns

Dict of the weights of all offsets corresponding to a particular event.

Return type

event_param_dict (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

weight (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 :param features: features (either additive or multiplicative) related to event component

dims: (batch, n_forecasts, n_features)

Parameters
  • 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)

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)

trend(t)

Computes trend based on model configuration.

Parameters

t (torch tensor float) – normalized time dimensions (batch, n_forecasts)

Returns

Trend component, same dimensions as input t

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