Huber loss (source code)

= Huber loss
{c}
{title2=$\rho_k(u)$}
{wiki}

The Huber loss is quadratic near zero and linear beyond a fixed cutoff; its derivative is the clipped Huber score.

For threshold $k>0$, the <Huber loss> is the <loss function>
$$
\rho_k(u)=\begin{cases}\tfrac12u^2,&|u|\leq k,\\k|u|-\tfrac12k^2,&|u|>k.\end{cases}
$$
The subtraction $k^2/2$ makes the values meet at $|u|=k$; the slopes also meet, so the <Huber loss> is continuously <differentiable> with <Huber score> as its <derivative>. It is a <convex function>, since that <derivative> is a <monotone function>. These quadratic and linear pieces define the original clipped location criterion.<Robust Estimation of a Location Parameter by Peter J. Huber>[§1, printed p. 75: piecewise criterion; §4(iii), printed p. 79: corresponding location estimator]{ref}

\Image[/huber-loss-and-score.png]
{title=<Huber loss> and <Huber score> for threshold $k=2$}
{description=Original curves compare the <Huber loss> with $u^2/2$ and $2|u|$, then compare the <Huber score> with the linear score $u$ and $2\operatorname{sgn}(u)$. The dashed vertical lines mark $u=\pm2$.}

For $k=2$, $\rho_2(1)=1/2$, $\rho_2(2)=2$, and $\rho_2(5)=8$, whereas the squared criterion $u^2/2$ at $u=5$ is $12.5$. Increasing a standardized difference from $5$ to $6$ raises the <Huber loss> by $2$, but raises the squared criterion by $5.5$. The compromise preserves quadratic sensitivity to small differences while limiting the slope for large ones. This makes the <Huber loss> useful when ordinary observations should retain their detailed distances yet isolated <outliers> should exert limited pull.

For a fixed finite dataset and scale, taking $k$ large enough that every difference from the <sample mean> lies within $ks$ recovers that <sample mean>. Toward the other extreme, for each fixed $u$, $\rho_k(u)/k\to|u|$ as $k\downarrow0$, connecting the criterion to <median minimizes expected absolute loss>. The normalization is essential: putting $k=0$ into the unscaled <Huber loss> gives zero everywhere, not a usable <median> criterion.