Huber at a Residual of Ten

PyTorch's HuberLoss with delta = 1 is, per element,

ℓ(a)={0.5 a2∣a∣<δδ (∣a∣−0.5 δ)otherwise\ell(a) = \begin{cases} 0.5,a^2 & |a| < \delta \ \delta,(|a| - 0.5,\delta) & \text{otherwise} \end{cases}

One outlier in the batch has residual a=10a = 10; a typical point has a=0.5a = 0.5. Compare ℓ\ell and dℓ/dad\ell/da against plain squared error 0.5a20.5a^2 at both residuals.

A

Outlier: Huber 5050 with gradient 1010, the same as squared error, since δ=1\delta = 1 only changes the loss for residuals below 1.

B

Outlier: Huber 9.59.5 with gradient 11, squared error 5050 with gradient 1010, so the outlier pulls the fit ten times less hard under Huber. Typical point: both give 0.1250.125 with gradient 0.50.5, identical, because ∣a∣<δ|a| < \delta.

C

Outlier: Huber 1010 with gradient 11, squared error 5050 with gradient 1010. Typical point: identical under both losses.

D

Outlier: Huber 9.59.5 with gradient 1010: the linear branch caps the loss value, but the gradient still scales with the residual.