Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.gaussian_nll_loss

mindspore.ops.gaussian_nll_loss(x, target, var, full=False, eps=1e-6, reduction='mean')[source]

Gaussian negative log likelihood loss.

The target values are considered to be samples from a Gaussian distribution, where the expectation and variance are predicted by a neural network. For labels modeled on a Gaussian distribution, logits to record expectations, and the variance var (elements are all positive), the calculated loss is:

loss=12(log(max(var, eps))+(xtarget)2max(var, eps))+const.

where eps is used for stability of log. When full=True, a constant will be added to the loss. If the shape of var and logits are not the same (due to a homoscedastic assumption), their shapes must allow correct broadcasting.

Parameters
  • x (Tensor) – Tensor of shape (N,) or () where means any number of additional dimensions.

  • target (Tensor) – Tensor of shape (N,) or (), same shape as the x, or same shape as the x but with one dimension equal to 1 (to allow broadcasting).

  • var (Tensor) – Tensor of shape (N,) or (), same shape as x, or same shape as the x but with one dimension equal to 1, or same shape as the x but with one fewer dimension (to allow for broadcasting).

  • full (bool, optional) – Include the constant term in the loss calculation. When full=True, the constant term will be const=0.5log(2π). Default: False.

  • eps (float, optional) – Used to improve the stability of log function must be greater than 0. Default: 1e-6 .

  • reduction (str, optional) –

    Apply specific reduction method to the output: 'none' , 'mean' , 'sum' . Default: 'mean' .

    • 'none': no reduction will be applied.

    • 'mean': compute and return the mean of elements in the output.

    • 'sum': the output elements will be summed.

Returns

Tensor or Tensor scalar, the computed loss depending on reduction.

Raises
  • TypeError – If x, target or var is not a Tensor.

  • TypeError – If full is not a bool.

  • TypeError – If eps is not a float.

  • ValueError – If eps is not a float within (0, inf).

  • ValueError – If reduction is not one of "none" , "mean" , "sum" .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> import mindspore.common.dtype as mstype
>>> arr1 = np.arange(8).reshape((4, 2))
>>> arr2 = np.array([2, 3, 1, 4, 6, 4, 4, 9]).reshape((4, 2))
>>> x = Tensor(arr1, mstype.float32)
>>> var = Tensor(np.ones((4, 1)), mstype.float32)
>>> target = Tensor(arr2, mstype.float32)
>>> output = ops.gaussian_nll_loss(x, target, var)
>>> print(output)
1.4374993
Reference:

Nix, D. A. and Weigend, A. S., "Estimating the mean and variance of the target probability distribution", Proceedings of 1994 IEEE International Conference on Neural Networks (ICNN'94), Orlando, FL, USA, 1994, pp. 55-60 vol.1, doi: 10.1109/ICNN.1994.374138.