mindspore/docs/api/api_python/nn/mindspore.nn.GaussianNLLLos...

37 lines
2.3 KiB
ReStructuredText
Raw Normal View History

2022-10-17 14:24:17 +08:00
mindspore.nn.GaussianNLLLoss
=============================
.. py:class:: mindspore.nn.GaussianNLLLoss(*, full=False, eps=1e-6, reduction='mean')
服从高斯分布的负对数似然损失。
目标值被认为是高斯分布的采样,其中期望和方差通过神经网络来预测。对于以高斯分布为模型的张量 `labels` 和记录期望的张量 `logits` ,以及均为正数的方差张量 `var` 来说计算的loss为
.. math::
\text{loss} = \frac{1}{2}\left(\log\left(\text{max}\left(\text{var},
\ \text{eps}\right)\right) + \frac{\left(\text{logits} - \text{labels}\right)^2}
{\text{max}\left(\text{var}, \ \text{eps}\right)}\right) + \text{const.}
其中,:math:`eps` 用于 :math:`log` 的稳定性。在默认情况下,常数部分被忽略,除非 :math:`full=True`。如果 :math:`var`:math:`logits` 的shape不一致出于同方差性的假设那么它必须最后一个维度是1或者具有更少的维度其他维度相同来获得正确的广播。
参数:
- **full** (bool) - 指定损失函数中的常数部分。如果为True则常数为 :math:`const = 0.5*log(2*pi)`。默认值False。
- **eps** (float) - 用于提高log的稳定性。默认值1e-6。
- **reduction** (str) - 指定应用于输出结果的计算方式,'none'、'mean'、'sum',默认值:'mean'。
输入:
- **logits** (Tensor) - shape为 :math:`(N, *)`:math:`(*)``*` 代表着任意数量的额外维度。
- **labels** (Tensor) - shape为 :math:`(N, *)`:math:`(*)`。和 `logits` 具有相同shape或者相同shape但有一个维度为1以允许广播
- **var** (Tensor) - shape为 :math:`(N, *)`:math:`(*)`。和 `logits` 具有相同shape或者相同shape但有一个维度为1或者少一个维度以允许广播
2022-10-22 14:26:45 +08:00
2022-10-17 14:24:17 +08:00
返回:
Tensor或Tensor scalar根据 :math:`reduction` 计算的loss。
异常:
- **TypeError** - `logits` 不是Tensor。
- **TypeError** - `labels` 不是Tensor。
- **TypeError** - `full` 不是bool。
- **TypeError** - `eps` 不是float。
- **ValueError** - `eps` 不是在[0, inf)区间的float。
- **ValueError** - `reduction` 不是"none"、"mean"或者"sum"。