cayleypy.train.PinballLoss
- class cayleypy.train.PinballLoss(tau: float = 0.5)[source]
Pinball (quantile) loss, which penalizes underestimation and overestimation differently.
A model trained with this loss predicts the
tau-quantile of the target distribution instead of its mean. Withtau > 0.5, underestimating a distance costs more than overestimating it by the same amount; withtau < 0.5, the other way round, which pushes predictions towards a lower bound on the true distance. Attau = 0.5this is exactly half of the mean absolute error.Example:
>>> import torch >>> from cayleypy.train import PinballLoss >>> loss = PinballLoss(0.9) >>> float(loss(torch.tensor([1.0, 3.0]), torch.tensor([2.0, 2.0]))) 0.5
- __init__(tau: float = 0.5)[source]
Initializes PinballLoss.
- Parameters:
tau – Quantile of the target distribution to predict. Must be strictly between 0 and 1.
Methods
__init__([tau])Initializes PinballLoss.
elementwise(predictions, targets)Computes pinball loss for every element.
- elementwise(predictions: Tensor, targets: Tensor) Tensor[source]
Computes pinball loss for every element.
- Parameters:
predictions – Predicted distances.
targets – Target distances, of the same shape as
predictions.
- Returns:
Tensor of the same shape as
predictions, with pinball losses -tau*(target-prediction)where the target is underestimated, and(1-tau)*(prediction-target)where it is overestimated.