# mlx.nn.losses.log_cosh_loss — MLX 0.0.7 documentation

Skip to main content
`Ctrl`+`K`

# mlx.nn.losses.log_cosh_loss

class mlx.nn.losses.log_cosh_loss(inputs: array, targets: array, reduction: str = 'none')

  Computes the log cosh loss between inputs and targets.

  Logcosh acts like L2 loss for small errors, ensuring stable gradients, and like the L1 loss for large errors, reducing sensitivity to outliers. This dual behavior offers a balanced, robust approach for regression tasks.

  \[\text{logcosh}(y_{\text{true}}, y_{\text{pred}}) = \frac{1}{n} \sum_{i=1}^{n} \log(\cosh(y_{\text{pred}}^{(i)} - y_{\text{true}}^{(i)}))\]
  Parameters:

    - inputs (array) – The predicted values.

    - targets (array) – The target values.

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

  Returns:

    The computed log cosh loss.

  Return type:

    array