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')#

计算输入和目标之间的对数cosh损失。

Logcosh 对于小误差表现得像 L2 损失,确保梯度稳定;对于大误差则像 L1 损失,减少对离群值的敏感度。这种双重特性为回归任务提供了一种均衡、鲁棒的方法。

\[\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) – 预测值。

  • targets (array) – 目标值。

  • reduction (str, optional) – 指定应用于输出的归约方式:'none'(无)| 'mean'(平均)| 'sum'(求和)。默认值:'none'

返回值:

计算得到的对数cosh损失。

返回类型:

array