LogNormalDistributionLoss#

class pytorch_forecasting.metrics.distributions.LogNormalDistributionLoss(clamp_min: float = 1e-12, **kwargs)[source]#

Bases: DistributionLoss

Log-normal loss.

Requirements for original target normalizer:
  • normalized target in log space

Parameters:

clamp_min (float, optional) – Minimum value to clamp targets to before computing log-prob, preventing ValueError when targets contain zeros. Defaults to 1e-12.

Initialize LogNormalDistributionLoss.

Parameters:
  • clamp_min (float, optional) – Minimum value to clamp targets to before computing log-prob, preventing ValueError when targets contain zeros. Defaults to 1e-12.

  • **kwargs – Additional keyword arguments passed to DistributionLoss.

Methods

loss(y_pred, y_actual)

Calculate negative log-likelihood.

map_x_to_distribution(x)

Map network output to a LogNormal distribution.

rescale_parameters(parameters, target_scale, ...)

Rescale normalized parameters into the scale required for the output.

distribution_class#

alias of LogNormal

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

Calculate negative log-likelihood.

Clamps y_actual to self.clamp_min to avoid ValueError from the LogNormal distribution when targets contain zeros.

Parameters:
  • y_pred (torch.Tensor) – Network output.

  • y_actual (torch.Tensor) – Actual values.

Returns:

Metric value on which backpropagation can be applied.

Return type:

torch.Tensor

map_x_to_distribution(x: Tensor) LogNormal[source]#

Map network output to a LogNormal distribution.

Parameters:

x (torch.Tensor) – Network output tensor with loc and scale parameters.

Returns:

LogNormal distribution parameterised by x.

Return type:

distributions.LogNormal

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