fn
huber_loss
→Tensorhuber_loss(x: Tensor, target: Tensor, delta: float = 1.0, reduction: str = 'mean')Huber loss — robust regression with a tunable transition point.
Identical in shape to smooth_l1_loss but parameterised
by the slope-clip point rather than the
quadratic-region scale . Inside the
region the loss is quadratic; outside,
the gradient saturates at so a single huge
residual cannot dominate the update.
Originally proposed by Peter Huber (1964) as the maximum- likelihood estimator for a contaminated Gaussian model — i.e., "mostly Gaussian noise but with occasional outliers". Use it when you suspect a small fraction of your residuals come from a heavy-tailed distribution.
Parameters
xTensorPredicted values.
targetTensorTarget values; broadcast-compatible with
x.deltafloat= 1.0Threshold at which the loss transitions from quadratic to
linear (default
1.0).reductionstr= 'mean'"mean" (default), "sum", or "none".Returns
TensorScalar or full-shape, per reduction.
Notes
Per-element loss:
Unlike smooth_l1_loss, the quadratic region is not
rescaled by , so the loss magnitude itself
grows with .
Examples
>>> import lucid
>>> from lucid.nn.functional import huber_loss
>>> pred = lucid.tensor([0.0, 5.0])
>>> target = lucid.tensor([0.5, 0.0])
>>> huber_loss(pred, target, delta=1.0)
Tensor(2.3125)