callcut.training.TverskyLoss🔗
- class callcut.training.TverskyLoss(alpha=0.5, beta=0.5, smooth=1.0)[source]🔗
Tversky loss with adjustable false positive/negative penalties.
Generalization of Dice loss that allows separate weighting of false positives and false negatives. Useful when recall is more important than precision (or vice versa).
The Tversky index is:
\[\begin{split}TI = \\frac{TP}{TP + \\alpha \\cdot FP + \\beta \\cdot FN}\end{split}\]- Parameters:
Attributes
Methods
forward(logits, targets)Compute Tversky loss.
Notes
alpha = beta = 0.5recovers Dice lossalpha = beta = 1.0recovers Tanimoto coefficientbeta > alphafavors recall (fewer missed calls)alpha > betafavors precision (fewer false alarms)
Examples
>>> # Favor recall (fewer missed calls) >>> loss_fn = TverskyLoss(alpha=0.3, beta=0.7) >>> loss = loss_fn(logits, targets)