Machine learning building blocks
Huber loss
ml.huber-lossAlso called huber loss, huber, robust loss, huberloss
where
Mean loss that is quadratic for residuals up to δ and linear beyond, so outliers weigh less than in squared error. Matches torch.nn.HuberLoss with mean reduction.
Notation
targets
y ∈ ℝn
predictions
ŷ ∈ ℝn
threshold between the quadratic and linear parts
δ > 0 · default 1
number of entries
Size, at least 1
Result: the mean loss
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 1.3125
Given
Result
Given
Result
≈ 1.25
Common mistakes
Computes the smooth L1 loss
Smooth L1 with threshold β equals the Huber loss divided by β; the two agree only when δ = 1.
Fix: Multiply the smooth L1 loss by δ, or use torch.nn.HuberLoss(delta=δ).
Sums instead of averaging
The per-example losses are summed.
Fix: Divide by n, or use reduction='mean'.
Source
Huber 1964
Huber, Peter J. Robust Estimation of a Location Parameter. The Annals of Mathematical Statistics 35(1): 73-101, 1964. doi:10.1214/aoms/1177703732