gluonts.torch.model.mqf2.distribution module#

class gluonts.torch.model.mqf2.distribution.MQF2Distribution(picnn: PICNN, hidden_state: 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: 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: Size#

Returns the shape over which parameters are batched.

energy_score(z: Tensor) 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: Size#

Returns the shape of a single sample (without batching).

log_prob(z: Tensor) 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

loss(z: Tensor) Tensor[source]#
quantile(alpha: Tensor, hidden_state: Optional[Tensor] = None) 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: Size = torch.Size([])) 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: Tensor) 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.model.mqf2.distribution.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: DistributionOutput

distr_cls#

alias of MQF2Distribution

distribution(picnn: Module, hidden_state: Tensor, scale: Optional[Tensor] = None) 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: 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 compatible with the output object.

class gluonts.torch.model.mqf2.distribution.TransformedMQF2Distribution(base_distribution: MQF2Distribution, transforms: List[AffineTransform], is_energy_score: bool = True, validate_args: bool = False)[source]#

Bases: TransformedDistribution

energy_score(y: Tensor) Tensor[source]#
log_prob(y: Tensor) Tensor[source]#

Scores the sample by inverting the transform(s) and computing the score using the score of the base distribution and the log abs det jacobian.

loss(z: Tensor) Tensor[source]#
repeat_scale(scale: Tensor) Tensor[source]#
scale_input(y: Tensor) Tuple[Tensor, Tensor][source]#