PinballLoss#

class torch_uncertainty.losses.PinballLoss(quantile=0.5, reduction='mean')[source]#

The Pinball loss for quantile regression.

Also known as the quantile loss or check loss, the pinball loss at quantile level \(\tau \in (0, 1)\) is:

\[\begin{split}\mathcal{L}_\tau(y, \hat{y}) = \max\!\left(\tau\,(y - \hat{y}),\,(\tau - 1)\,(y - \hat{y})\right) = \begin{cases} \tau\,(y - \hat{y}) & \text{if } y \geq \hat{y}, \\ (1 - \tau)\,(\hat{y} - y) & \text{if } y < \hat{y}. \end{cases}\end{split}\]

For \(\tau = 0.5\) the loss coincides with the mean absolute error (MAE) scaled by \(\tfrac{1}{2}\).

Parameters:
  • quantile (float) – The quantile level \(\tau \in (0, 1)\). Defaults to 0.5.

  • reduction (str | None) – Specifies the reduction to apply to the output. Must be one of 'none', 'mean' or 'sum'. Defaults to "mean".

References

[1] Koenker, R., & Bassett Jr, G. (1978). Regression quantiles. Econometrica,.

forward(predictions, targets)[source]#

Compute the pinball loss.

Parameters:
  • predictions (Tensor) – The predicted quantile values.

  • targets (Tensor) – The target values.

Return type:

Tensor