mlx.nn.losses.log_cosh_loss

目錄

mlx.nn.losses.log_cosh_loss#

class log_cosh_loss(inputs: array, targets: array, reduction: Literal['none', 'mean', 'sum'] = 'none')#

計算輸入與目標之間的 log cosh 損失。

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)}))\]
參數:
  • 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'.

回傳:

The computed log cosh loss.

回傳型別:

array