mlx.nn.losses.huber_loss#

huber_loss(inputs: array, targets: array, delta: float = 1.0, reduction: Literal['none', 'mean', 'sum'] = 'none') array#

Computes the Huber loss between inputs and targets.

\[\begin{split}l_{\delta}(a) = \left\{ \begin{array}{ll} \frac{1}{2} a^2 & \text{for } |a| \leq \delta, \\ \delta \left( |a| - \frac{1}{2} \delta \right) & \text{otherwise.} \end{array} \right.\end{split}\]
Parameters:
  • inputs (array) – The predicted values.

  • targets (array) – The target values.

  • delta (float, optional) – The threshold at which to change between L1 and L2 loss. Default: 1.0.

  • reduction (str, optional) – Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. Default: 'none'.

Returns:

The computed Huber loss.

Return type:

array