gluonts.torch.model.deep_npts package#
- class gluonts.torch.model.deep_npts.DeepNPTSEstimator(freq: str, prediction_length: int, context_length: int, num_hidden_nodes: typing.Optional[typing.List[int]] = None, batch_norm: bool = False, use_feat_static_cat: bool = False, num_feat_static_real: int = 0, num_feat_dynamic_real: int = 0, cardinality: typing.Optional[typing.List[int]] = None, embedding_dimension: typing.Optional[typing.List[int]] = None, input_scaling: typing.Optional[typing.Union[typing.Callable, str]] = None, dropout_rate: float = 0.0, network_type: gluonts.torch.model.deep_npts._network.DeepNPTSNetwork = <class 'gluonts.torch.model.deep_npts._network.DeepNPTSNetworkDiscrete'>, epochs: int = 100, lr: float = 1e-05, batch_size: int = 32, num_batches_per_epoch: int = 100, cache_data: bool = False, loss_scaling: typing.Optional[typing.Union[typing.Callable, str]] = None)[source]#
Bases:
gluonts.model.estimator.Estimator
Construct a DeepNPTS estimator. This is a tunable extension of NPTS where the sampling probabilities are learned from the data. This is a global- model unlike NPTS.
Currently two variants of the model are implemented: (i) DeepNPTSNetworkDiscrete: the forecast distribution is a discrete distribution similar to NPTS and the forecasts are sampled from the observations in the context window. (ii) DeepNPTSNetworkSmooth: the forecast distribution is a smoothed mixture distribution where the components of the mixture are Gaussians centered around the observations in the context window. The mixing probabilities and the width of the Gaussians are learned. Here the forecast can contain values not observed in the context window.
- Parameters
freq – Frequency of the data to train on and predict
prediction_length (int) – Length of the prediction horizon
context_length – Number of steps to unroll the RNN for before computing predictions (default: None, in which case context_length = prediction_length)
num_hidden_nodes – A list containing the number of nodes in each hidden layer
batch_norm – Flag to indicate if batch normalization should be applied at every layer
use_feat_static_cat – Whether to use the
feat_static_cat
field from the data (default: False)num_feat_static_real – Number of static real features in the data set
num_feat_dynamic_real – Number of dynamic features in the data set. These features are added to the time series features that are automatically created based on the frequency
cardinality – Number of values of each categorical feature This must be set if
use_feat_static_cat == True
(default: None)embedding_dimension – Dimension of the embeddings for categorical features (default: [min(50, (cat+1)//2) for cat in cardinality])
input_scaling – The scaling to be applied to the target values. Available options: “min_max_scaling” and “standard_normal_scaling” (default: no scaling)
dropout_rate – Dropout regularization parameter (default: no dropout)
network_type – The network to be used: either the discrete version DeepNPTSNetworkDiscrete or the smoothed version DeepNPTSNetworkSmooth (default: DeepNPTSNetworkDiscrete)
- get_predictor(net: torch.nn.modules.module.Module, device='cpu') gluonts.torch.model.predictor.PyTorchPredictor [source]#
- input_transform() gluonts.transform._base.Transformation [source]#
- instance_splitter(instance_sampler, is_train: bool = True) gluonts.transform.split.InstanceSplitter [source]#
- lead_time: int#
- loss_scaling: Optional[Callable]#
- prediction_length: int#
- train(training_data: gluonts.dataset.Dataset, validation_data: Optional[gluonts.dataset.Dataset] = None, cache_data: bool = False) gluonts.torch.model.predictor.PyTorchPredictor [source]#
Train the estimator on the given data.
- Parameters
training_data – Dataset to train the model on.
validation_data – Dataset to validate the model on during training.
- Returns
The predictor containing the trained model.
- Return type
- train_model(training_data: gluonts.dataset.Dataset, cache_data: bool = False) gluonts.torch.model.deep_npts._network.DeepNPTSNetwork [source]#
- class gluonts.torch.model.deep_npts.DeepNPTSMultiStepNetwork(net: gluonts.torch.model.deep_npts._network.DeepNPTSNetwork, prediction_length: int, num_parallel_samples: int = 100)[source]#
Bases:
torch.nn.modules.module.Module
Implements multi-step prediction given a trained DeepNPTSNetwork model that outputs one-step-ahead forecast distribution.
- forward(feat_static_cat: torch.Tensor, feat_static_real: torch.Tensor, past_target: torch.Tensor, past_observed_values: torch.Tensor, past_time_feat: torch.Tensor, future_time_feat: torch.Tensor)[source]#
Generates samples from the forecast distribution.
- Parameters
feat_static_cat – Shape (-1, num_features).
feat_static_real – Shape (-1, num_features).
past_target – Shape (-1, context_length).
past_observed_values – Shape (-1, context_length).
past_time_feat – Shape (-1, context_length, self.num_time_features).
future_time_feat – Shape (-1, prediction_length, self.num_time_features).
- Returns
Tensor containing samples from the predicted distribution. Shape is (-1, self.num_parallel_samples, self.prediction_length).
- Return type
torch.Tensor
- training: bool#
- class gluonts.torch.model.deep_npts.DeepNPTSNetwork(context_length: int, num_hidden_nodes: List[int], cardinality: List[int], embedding_dimension: List[int], num_time_features: int, batch_norm: bool = False, input_scaling: Optional[Union[Callable, str]] = None, dropout_rate: float = 0.0)[source]#
Bases:
torch.nn.modules.module.Module
Base class implementing a simple feed-forward neural network that takes in static and dynamic features and produces num_hidden_nodes independent outputs. These outputs are then used by derived classes to construct the forecast distribution for a single time step.
Note that the dynamic features are just treated as independent features without considering their temporal nature.
- forward(feat_static_cat: torch.Tensor, feat_static_real: torch.Tensor, past_target: torch.Tensor, past_observed_values: torch.Tensor, past_time_feat: torch.Tensor)[source]#
- Parameters
feat_static_cat – Shape (-1, num_features).
feat_static_real – Shape (-1, num_features).
past_target – Shape (-1, context_length).
past_observed_values – Shape (-1, context_length).
past_time_feat – Shape (-1, context_length, self.num_time_features).
- training: bool#
- class gluonts.torch.model.deep_npts.DeepNPTSNetworkDiscrete(*args, use_softmax: bool = False, **kwargs)[source]#
Bases:
gluonts.torch.model.deep_npts._network.DeepNPTSNetwork
Extends DeepNTPSNetwork by implementing the output layer which converts the outputs from the base network into probabilities of length context_length. These probabilities together with the past values in the context window constitute the one-step-ahead forecast distribution. Specifically, the forecast is always one of the values observed in the context window with the corresponding predicted probability.
- Parameters
*args – Arguments to
DeepNPTSNetwork
.use_softmax – Flag indicating whether to use softmax or normalization for converting the outputs of the base network to probabilities.
kwargs – Keyword arguments to
DeepNPTSNetwork
.
- forward(feat_static_cat: torch.Tensor, feat_static_real: torch.Tensor, past_target: torch.Tensor, past_observed_values: torch.Tensor, past_time_feat: torch.Tensor) gluonts.torch.distributions.discrete_distribution.DiscreteDistribution [source]#
- Parameters
feat_static_cat – Shape (-1, num_features).
feat_static_real – Shape (-1, num_features).
past_target – Shape (-1, context_length).
past_observed_values – Shape (-1, context_length).
past_time_feat – Shape (-1, context_length, self.num_time_features).
- training: bool#
- class gluonts.torch.model.deep_npts.DeepNPTSNetworkSmooth(*args, **kwargs)[source]#
Bases:
gluonts.torch.model.deep_npts._network.DeepNPTSNetwork
Extends DeepNTPSNetwork by implementing the output layer which converts the outputs from the base network into a smoothed mixture distribution. The components of the mixture are Gaussians centered around the observations in the context window. The mixing probabilities as well as the width of the Gaussians are predicted by the network.
This mixture distribution represents the one-step-ahead forecast distribution. Note that the forecast can contain values not observed in the context window.
- forward(feat_static_cat: torch.Tensor, feat_static_real: torch.Tensor, past_target: torch.Tensor, past_observed_values: torch.Tensor, past_time_feat: torch.Tensor) torch.distributions.mixture_same_family.MixtureSameFamily [source]#
- Parameters
feat_static_cat – Shape (-1, num_features).
feat_static_real – Shape (-1, num_features).
past_target – Shape (-1, context_length).
past_observed_values – Shape (-1, context_length).
past_time_feat – Shape (-1, context_length, self.num_time_features).
- training: bool#