gluonts.torch.distributions.mqf2 module#
- class gluonts.torch.distributions.mqf2.MQF2Distribution(picnn: torch.nn.modules.module.Module, hidden_state: torch.Tensor, prediction_length: int, is_energy_score: bool = True, es_num_samples: int = 50, beta: float = 1.0, threshold_input: float = 100.0, validate_args: bool = False)[source]#
Bases:
torch.distributions.distribution.Distribution
Distribution class for the model MQF2 proposed in the paper
Multivariate Quantile Function Forecaster
by Kan, Aubet, Januschowski, Park, Benidis, Ruthotto, Gasthaus- Parameters
picnn – A SequentialNet instance of a partially input convex neural network (picnn)
hidden_state – hidden_state obtained by unrolling the RNN encoder shape = (batch_size, context_length, hidden_size) in training shape = (batch_size, hidden_size) in inference
prediction_length – Length of the prediction horizon
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
validate_args – Sets whether validation is enabled or disabled For more details, refer to the descriptions in torch.distributions.distribution.Distribution
- property batch_shape: torch.Size#
Returns the shape over which parameters are batched.
- energy_score(z: torch.Tensor) torch.Tensor [source]#
Computes the (approximated) energy score sum_i ES(g,z_i), where ES(g,z_i) =
-1/(2*es_num_samples^2) * sum_{w,w’} ||w-w’||_2^beta + 1/es_num_samples * sum_{w’’} ||w’’-z_i||_2^beta, w’s are samples drawn from the quantile function g(., h_i) (gradient of picnn), h_i is the hidden state associated with z_i, and es_num_samples is the number of samples drawn for each of w, w’, w’’ in energy score approximation
- Parameters
z – A batch of time series with shape (batch_size, context_length + prediction_length - 1)
- Returns
Tensor of shape (batch_size * context_length,)
- Return type
loss
- property event_dim: int#
- property event_shape: Tuple#
Returns the shape of a single sample (without batching).
- log_prob(z: torch.Tensor) torch.Tensor [source]#
Computes the log likelihood log(g(z)) + logdet(dg(z)/dz), where g is the gradient of the picnn.
- Parameters
z – A batch of time series with shape (batch_size, context_length + prediciton_length - 1)
- Returns
Tesnor of shape (batch_size * context_length,)
- Return type
loss
- quantile(alpha: torch.Tensor, hidden_state: Optional[torch.Tensor] = None) torch.Tensor [source]#
Generates the predicted paths associated with the quantile levels alpha.
- Parameters
alpha – quantile levels, shape = (batch_shape, prediction_length)
hidden_state – hidden_state, shape = (batch_shape, hidden_size)
- Returns
predicted paths of shape = (batch_shape, prediction_length)
- Return type
results
- rsample(sample_shape: torch.Size = torch.Size([])) torch.Tensor [source]#
Generates the sample paths.
- Parameters
sample_shape – Shape of the samples
- Returns
Tesnor of shape (batch_size, *sample_shape, prediction_length)
- Return type
sample_paths
- stack_sliding_view(z: torch.Tensor) torch.Tensor [source]#
Auxiliary function for loss computation.
Unfolds the observations by sliding a window of size prediction_length over the observations z Then, reshapes the observations into a 2-dimensional tensor for further computation
- Parameters
z – A batch of time series with shape (batch_size, context_length + prediction_length - 1)
- Returns
Unfolded time series with shape (batch_size * context_length, prediction_length)
- Return type
Tensor
- class gluonts.torch.distributions.mqf2.MQF2DistributionOutput(prediction_length: int, is_energy_score: bool = True, threshold_input: float = 100.0, es_num_samples: int = 50, beta: float = 1.0)[source]#
Bases:
gluonts.torch.distributions.distribution_output.DistributionOutput
- distr_cls#
- distribution(picnn: torch.nn.modules.module.Module, hidden_state: torch.Tensor, loc: Optional[torch.Tensor] = 0, scale: Optional[torch.Tensor] = None) gluonts.torch.distributions.mqf2.MQF2Distribution [source]#
Construct the associated distribution, given the collection of constructor arguments and, optionally, a scale tensor.
- Parameters
distr_args – Constructor arguments for the underlying Distribution type.
loc – Optional tensor, of the same shape as the batch_shape+event_shape of the resulting distribution.
scale – Optional tensor, of the same shape as the batch_shape+event_shape of the resulting distribution.
- classmethod domain_map(hidden_state: torch.Tensor) Tuple [source]#
Converts arguments to the right shape and domain. The domain depends on the type of distribution, while the correct shape is obtained by reshaping the trailing axis in such a way that the returned tensors define a distribution of the right event_shape.
- property event_shape: Tuple#
Shape of each individual event contemplated by the distributions that this object constructs.
- class gluonts.torch.distributions.mqf2.TransformedMQF2Distribution(base_distribution: gluonts.torch.distributions.mqf2.MQF2Distribution, transforms: List[torch.distributions.transforms.AffineTransform], validate_args: bool = False)[source]#
Bases:
torch.distributions.transformed_distribution.TransformedDistribution