gluonts.torch.model.mqf2 package#
- class gluonts.torch.model.mqf2.MQF2MultiHorizonEstimator(freq: str, prediction_length: int, context_length: Optional[int] = None, num_layers: int = 2, hidden_size: int = 40, lr: float = 0.001, weight_decay: float = 1e-08, dropout_rate: float = 0.1, num_feat_dynamic_real: int = 0, num_feat_static_cat: int = 0, num_feat_static_real: int = 0, cardinality: Optional[List[int]] = None, embedding_dimension: Optional[List[int]] = None, scaling: bool = True, lags_seq: Optional[List[int]] = None, time_features: Optional[List[Callable[[PeriodIndex], ndarray]]] = None, num_parallel_samples: int = 100, batch_size: int = 32, num_batches_per_epoch: int = 50, trainer_kwargs: Optional[Dict[str, Any]] = {}, icnn_hidden_size: int = 20, icnn_num_layers: int = 2, is_energy_score: bool = True, es_num_samples: int = 50, beta: float = 1.0, threshold_input: float = 100.0, estimate_logdet: bool = False)[source]#
Bases:
DeepAREstimatorEstimator class for the model MQF2 proposed in the paper
Multivariate Quantile Function Forecasterby Kan, Aubet, Januschowski, Park, Benidis, Ruthotto, Gasthaus.This is the multi-horizon (multivariate in time step) variant of MQF2
This class is based on gluonts.torch.model.deepar.estimator.DeepAREstimator
- 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_layers – Number of RNN layers
hidden_size – Hidden state size of RNN
lr – Learning rate (default:
1e-3).weight_decay – Weight decay regularization parameter (default:
1e-8).dropout_rate – Dropout regularization parameter
num_feat_dynamic_real – Number of dynamic real-valued features
num_feat_static_cat – Number of static categorial features
num_feat_static_real – Number of static real-valued features
cardinality – Number of values of each categorical feature
embedding_dimension – Dimension of the embeddings for categorical features
scaling – Whether to automatically scale the target values (default: true)
lags_seq – Indices of the lagged target values to use as inputs of the RNN (default: None, in which case these are automatically determined based on freq)
time_features – Time features to use as inputs of the RNN (default: None, in which case these are automatically determined based on freq)
num_parallel_samples – Number of evaluation samples per time series to increase parallelism during inference. This is a model optimization that does not affect the accuracy (default: 100)
icnn_hidden_size – Hidden layer size of the input convex neural network (icnn)
icnn_num_layers – Number of layers of the input convex neural network (icnn)
is_energy_score – If True, use energy score as objective function otherwise use maximum likelihood as objective function (normalizing flows)
es_num_samples – Number of samples drawn to approximate the energy score
beta – Hyperparameter of the energy score (power of the two terms)
threshold_input – Clamping threshold of the (scaled) input when maximum likelihood is used as objective function this is used to make the forecaster more robust to outliers in training samples
estimate_logdet – When maximum likelihood is used as the objective function, specify whether to use the logdet estimator introduced in the paper
Convex potential flows: Universal probability distributions with optimal transport and convex optimizationIf True, the logdet estimator (can be numerically unstable) is used otherwise, the logdet is directly computed
- create_lightning_module() MQF2MultiHorizonLightningModule[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
- class gluonts.torch.model.mqf2.MQF2MultiHorizonLightningModule(model_kwargs: dict, lr: float = 0.001, weight_decay: float = 1e-08, patience: int = 10)[source]#
Bases:
LightningModuleLightningModule class for the model MQF2 proposed in the paper
Multivariate Quantile Function Forecasterby Kan, Aubet, Januschowski, Park, Benidis, Ruthotto, Gasthaus.This is the multi-horizon (multivariate in time step) variant of MQF2
This class is based on gluonts.torch.model.deepar.lightning_module.DeepARLightningModule
- Parameters:
model_kwargs – Keyword arguments to construct the
MQF2MultiHorizonModelto be trained.loss – Distribution loss.
lr – Learning rate.
weight_decay – Weight decay during training.
patience – Patience parameter for learning rate scheduler, default:
10.
- class gluonts.torch.model.mqf2.MQF2MultiHorizonModel(freq: str, context_length: int, prediction_length: int, num_feat_dynamic_real: int, num_feat_static_real: int, num_feat_static_cat: int, cardinality: List[int], distr_output: Optional[MQF2DistributionOutput] = None, embedding_dimension: Optional[List[int]] = None, num_layers: int = 2, hidden_size: int = 40, dropout_rate: float = 0.1, lags_seq: Optional[List[int]] = None, scaling: bool = True, num_parallel_samples: int = 100, icnn_hidden_size: int = 20, icnn_num_layers: int = 2, is_energy_score: bool = True, threshold_input: float = 100, es_num_samples: int = 50, estimate_logdet: bool = False)[source]#
Bases:
DeepARModel- forward(feat_static_cat: Tensor, feat_static_real: Tensor, past_time_feat: Tensor, past_target: Tensor, past_observed_values: Tensor, future_time_feat: Tensor, num_parallel_samples: Optional[int] = None) Tensor[source]#
Generates the predicted sample paths.
- Parameters:
feat_static_cat – Static categorical features (batch_size, num_feat_static_cat)
feat_static_real – Static real-valued features (batch_size, num_feat_static_real)
past_time_feat – Past time features (batch_size, history_length, num_features)
past_target – Past target values (batch_size, history_length)
past_observed_values – Indicator whether or not the values were observed (batch_size, history_length)
future_time_feat – Future time features (batch_size, prediction_length, num_features)
num_parallel_samples – Number of parallel sample paths generated for each time series
- Returns:
Sample paths (batch_size, num_parallel_samples, prediction_length)
- Return type:
sample_paths
- loss(feat_static_cat: ~torch.Tensor, feat_static_real: ~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, future_only: bool = False, aggregate_by=<built-in method mean of type object>) Tensor[source]#
- output_distribution(picnn: SequentialNet, hidden_state: Tensor, scale: Optional[Tensor] = None, inference: bool = False) Distribution[source]#
Returns the MQF2Distribution instance.
- Parameters:
picnn – A SequentialNet instance of a partially input convex neural network (picnn)
hidden_state – RNN hidden state (batch_size, context_length, hidden_size)
scale – scaling of the data (batch_size, 1)
inference – If True, pass only the last hidden state to the forecaster for prediction Otherwise, pass all the hidden states to train the forecaster
- Returns:
MQF2 parametrized by hidden_state
- Return type:
MQF2Distribution instance