MQF2DistributionLoss#

class pytorch_forecasting.metrics.distributions.MQF2DistributionLoss(prediction_length: int, quantiles: List[float] = [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98], hidden_size: Optional[int] = 4, es_num_samples: int = 50, beta: float = 1.0, icnn_hidden_size: int = 20, icnn_num_layers: int = 2, estimate_logdet: bool = False)[source]#

Bases: DistributionLoss

Multivariate quantile loss based on the article Multivariate Quantile Function Forecaster.

Requires install of additional library: pip install pytorch-forecasting[mqf2]

Parameters
  • prediction_length (int) – maximum prediction length.

  • quantiles (List[float], optional) – default quantiles to output. Defaults to [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98].

  • hidden_size (int, optional) – hidden size per prediction length. Defaults to 4.

  • es_num_samples (int, optional) – Number of samples to calculate energy score. If None, maximum liklihood is used as opposed to energy score for optimization. Defaults to 50.

  • beta (float, optional) – between 0 and 1.0 to control how scale sensitive metric is (1=fully sensitive). Defaults to 1.0.

  • icnn_hidden_size (int, optional) – hidden size of distribution estimating network. Defaults to 20.

  • icnn_num_layers (int, optional) – number of hidden layers in distribution estimating network. Defaults to 2.

  • estimate_logdet (bool, optional) – if to estimate log determinant. Defaults to False.

Methods

loss(y_pred, y_actual)

Calculate negative likelihood

map_x_to_distribution(x)

Map the a tensor of parameters to a probability distribution.

rescale_parameters(parameters, target_scale, ...)

Rescale normalized parameters into the scale required for the output.

to_quantiles(y_pred[, quantiles])

Convert network prediction into a quantile prediction.

loss(y_pred: Tensor, y_actual: Tensor) Tensor[source]#

Calculate negative likelihood

Parameters
  • y_pred – network output

  • y_actual – actual values

Returns

metric value on which backpropagation can be applied

Return type

torch.Tensor

map_x_to_distribution(x: Tensor) Distribution[source]#

Map the a tensor of parameters to a probability distribution.

Parameters

x (torch.Tensor) – parameters for probability distribution. Last dimension will index the parameters

Returns

torch probability distribution as defined in the

class attribute distribution_class

Return type

distributions.Distribution

rescale_parameters(parameters: Tensor, target_scale: Tensor, encoder: BaseEstimator) Tensor[source]#

Rescale normalized parameters into the scale required for the output.

Parameters
  • parameters (torch.Tensor) – normalized parameters (indexed by last dimension)

  • target_scale (torch.Tensor) – scale of parameters (n_batch_samples x (center, scale))

  • encoder (BaseEstimator) – original encoder that normalized the target in the first place

Returns

parameters in real/not normalized space

Return type

torch.Tensor

to_quantiles(y_pred: Tensor, quantiles: Optional[List[float]] = None) Tensor[source]#

Convert network prediction into a quantile prediction.

Parameters
  • y_pred – prediction output of network

  • quantiles (List[float], optional) – quantiles for probability range. Defaults to quantiles as as defined in the class initialization.

Returns

prediction quantiles (last dimension)

Return type

torch.Tensor