ConfidencePenaltyLoss#
- class torch_uncertainty.losses.ConfidencePenaltyLoss(reg_weight=1, reduction='mean', eps=1e-06)[source]#
The Confidence Penalty loss.
Augments the standard cross-entropy loss with a regulariser that penalises low-entropy (over-confident) predictive distributions:
\[\mathcal{L} = \text{CE}(\mathbf{z}, y) + \lambda \left( \log C + \sum_{i=1}^{C} p_i \log(p_i + \varepsilon) \right),\]where \(\mathbf{p} = \mathrm{softmax}(\mathbf{z})\), \(C\) is the number of classes, \(\lambda\) is
reg_weight, and \(\varepsilon\) iseps. The regulariser equals the negative entropy of \(\mathbf{p}\) shifted by \(\log C\) so that it is non-negative.- Parameters:
reg_weight (
float) – The weight \(\lambda\) of the regularization term.reduction (
str|None) – Specifies the reduction to apply to the output:'none'|'mean'|'sum'. Defaults to'mean'.eps (
float) – A small value to avoid numerical instability. Defaults to1e-6.
References