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)}))\]