LogNormalDistributionLoss#
- class pytorch_forecasting.metrics.distributions.LogNormalDistributionLoss(clamp_min: float = 1e-12, **kwargs)[source]#
Bases:
DistributionLossLog-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
ValueErrorwhen 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
ValueErrorwhen 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 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_actualtoself.clamp_minto avoidValueErrorfrom theLogNormaldistribution 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