gluonts.torch.model.tide package#
- class gluonts.torch.model.tide.TiDEEstimator(freq: str, prediction_length: int, context_length: Optional[int] = None, feat_proj_hidden_dim: Optional[int] = None, encoder_hidden_dim: Optional[int] = None, decoder_hidden_dim: Optional[int] = None, temporal_hidden_dim: Optional[int] = None, distr_hidden_dim: Optional[int] = None, num_layers_encoder: Optional[int] = None, num_layers_decoder: Optional[int] = None, decoder_output_dim: Optional[int] = None, dropout_rate: Optional[float] = None, num_feat_dynamic_proj: Optional[int] = None, num_feat_dynamic_real: int = 0, num_feat_static_real: int = 0, num_feat_static_cat: int = 0, cardinality: Optional[List[int]] = None, embedding_dimension: Optional[List[int]] = None, layer_norm: bool = False, lr: float = 0.001, weight_decay: float = 1e-08, patience: int = 10, scaling: Optional[str] = 'mean', distr_output: gluonts.torch.distributions.output.Output = gluonts.torch.distributions.studentT.StudentTOutput(beta=0.0), batch_size: int = 32, num_batches_per_epoch: int = 50, trainer_kwargs: Optional[Dict[str, Any]] = None, train_sampler: Optional[gluonts.transform.sampler.InstanceSampler] = None, validation_sampler: Optional[gluonts.transform.sampler.InstanceSampler] = None)[source]#
Bases:
gluonts.torch.model.estimator.PyTorchLightningEstimator
An estimator training the TiDE model form the paper https://arxiv.org/abs/2304.08424 extended for probabilistic forecasting.
This class is uses the model defined in
TiDEModel
, and wraps it into aTiDELightningModule
for training purposes: training is performed using PyTorch Lightning’spl.Trainer
class.- Parameters
freq – Frequency of the data to train on and predict.
prediction_length (int) – Length of the prediction horizon.
context_length – Number of time steps prior to prediction time that the model takes as inputs (default:
prediction_length
).feat_proj_hidden_dim – Size of the feature projection layer (default: 4).
encoder_hidden_dim – Size of the dense encoder layer (default: 4).
decoder_hidden_dim – Size of the dense decoder layer (default: 4).
temporal_hidden_dim – Size of the temporal decoder layer (default: 4).
distr_hidden_dim – Size of the distribution projection layer (default: 4).
num_layers_encoder – Number of layers in dense encoder (default: 1).
num_layers_decoder – Number of layers in dense decoder (default: 1).
decoder_output_dim – Output size of dense decoder (default: 4).
dropout_rate – Dropout regularization parameter (default: 0.3).
num_feat_dynamic_proj – Output size of feature projection layer (default: 2).
num_feat_dynamic_real – Number of dynamic real features in the data (default: 0).
num_feat_static_real – Number of static real features in the data (default: 0).
num_feat_static_cat – Number of static categorical features in the data (default: 0).
cardinality – Number of values of each categorical feature. This must be set if
num_feat_static_cat > 0
(default: None).embedding_dimension – Dimension of the embeddings for categorical features (default:
[16 for cat in cardinality]
).layer_norm – Enable layer normalization or not (default: False).
lr – Learning rate (default:
1e-3
).weight_decay – Weight decay regularization parameter (default:
1e-8
).patience – Patience parameter for learning rate scheduler (default: 10).
distr_output – Distribution to use to evaluate observations and sample predictions (default: StudentTOutput()).
scaling – Which scaling method to use to scale the target values (default: mean).
batch_size – The size of the batches to be used for training (default: 32).
num_batches_per_epoch – Number of batches to be processed in each training epoch (default: 50).
trainer_kwargs – Additional arguments to provide to
pl.Trainer
for construction.train_sampler – Controls the sampling of windows during training.
validation_sampler – Controls the sampling of windows during validation.
- create_lightning_module() lightning.pytorch.core.module.LightningModule [source]#
Create and return the network used for training (i.e., computing the loss).
- Returns
The network that computes the loss given input data.
- Return type
pl.LightningModule
- create_predictor(transformation: gluonts.transform._base.Transformation, module) gluonts.torch.model.predictor.PyTorchPredictor [source]#
Create and return a predictor object.
- Parameters
transformation – Transformation to be applied to data before it goes into the model.
module – A trained pl.LightningModule object.
- Returns
A predictor wrapping a nn.Module used for inference.
- Return type
- create_training_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.tide.lightning_module.TiDELightningModule, shuffle_buffer_length: Optional[int] = None, **kwargs) Iterable [source]#
Create a data loader for training purposes.
- Parameters
data – Dataset from which to create the data loader.
module – The pl.LightningModule object that will receive the batches from the data loader.
- Returns
The data loader, i.e. and iterable over batches of data.
- Return type
Iterable
- create_transformation() gluonts.transform._base.Transformation [source]#
Create and return the transformation needed for training and inference.
- Returns
The transformation that will be applied entry-wise to datasets, at training and inference time.
- Return type
- create_validation_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.tide.lightning_module.TiDELightningModule, **kwargs) Iterable [source]#
Create a data loader for validation purposes.
- Parameters
data – Dataset from which to create the data loader.
module – The pl.LightningModule object that will receive the batches from the data loader.
- Returns
The data loader, i.e. and iterable over batches of data.
- Return type
Iterable
- lead_time: int#
- prediction_length: int#
- class gluonts.torch.model.tide.TiDELightningModule(model_kwargs: dict, lr: float = 0.001, weight_decay: float = 1e-08, patience: int = 10)[source]#
Bases:
lightning.pytorch.core.module.LightningModule
A
pl.LightningModule
class that can be used to train aTiDEModel
with PyTorch Lightning.This is a thin layer around a (wrapped)
TiDEModel
object, that exposes the methods to evaluate training and validation loss.- Parameters
model_kwargs – Keyword arguments to construct the
TiDEModel
to be trained.lr – Learning rate.
weight_decay – Weight decay regularization parameter.
patience – Patience parameter for learning rate scheduler.
- class gluonts.torch.model.tide.TiDEModel(context_length: int, prediction_length: int, num_feat_dynamic_real: int, num_feat_dynamic_proj: int, num_feat_static_real: int, num_feat_static_cat: int, cardinality: List[int], embedding_dimension: List[int], feat_proj_hidden_dim: int, encoder_hidden_dim: int, decoder_hidden_dim: int, temporal_hidden_dim: int, distr_hidden_dim: int, decoder_output_dim: int, dropout_rate: float, num_layers_encoder: int, num_layers_decoder: int, layer_norm: bool, distr_output: gluonts.torch.distributions.output.Output, scaling: str)[source]#
Bases:
torch.nn.modules.module.Module
- Parameters
context_length – Number of time steps prior to prediction time that the model takes as inputs.
prediction_length – Length of the prediction horizon.
num_feat_dynamic_proj – Output size of feature projection layer.
num_feat_dynamic_real – Number of dynamic real features in the data.
num_feat_static_real – Number of static real features in the data.
num_feat_static_cat – Number of static categorical features in the data.
cardinality – Number of values of each categorical feature. This must be set if
num_feat_static_cat > 0
.embedding_dimension – Dimension of the embeddings for categorical features.
feat_proj_hidden_dim – Size of the feature projection layer.
encoder_hidden_dim – Size of the dense encoder layer.
decoder_hidden_dim – Size of the dense decoder layer.
temporal_hidden_dim – Size of the temporal decoder layer.
distr_hidden_dim – Size of the distribution projection layer.
decoder_output_dim – Output size of dense decoder.
dropout_rate – Dropout regularization parameter.
num_layers_encoder – Number of layers in dense encoder.
num_layers_decoder – Number of layers in dense decoder.
layer_norm – Enable layer normalization or not.
distr_output – Distribution to use to evaluate observations and sample predictions.
scaling – Which scaling method to use to scale the target values.
- describe_inputs(batch_size=1) gluonts.model.inputs.InputSpec [source]#
- forward(feat_static_real: torch.Tensor, feat_static_cat: torch.Tensor, past_time_feat: torch.Tensor, past_target: torch.Tensor, past_observed_values: torch.Tensor, future_time_feat: torch.Tensor) Tuple[Tuple[torch.Tensor, ...], torch.Tensor, torch.Tensor] [source]#
Define 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.
- loss(feat_static_real: torch.Tensor, feat_static_cat: torch.Tensor, past_time_feat: torch.Tensor, past_target: torch.Tensor, past_observed_values: torch.Tensor, future_time_feat: torch.Tensor, future_target: torch.Tensor, future_observed_values: torch.Tensor)[source]#
- training: bool#