poisson_nll_loss

paddle.nn.functional. poisson_nll_loss ( input, label, log_input=True, full=False, epsilon=1e-08, reduction='mean', name=None ) [source]

Poisson negative log likelihood loss. See more detail in PoissonNLLLoss .

Parameters
  • input (Tensor) – Input tensor, expectation of underlying Poisson distribution. The shape of input tensor should be (N, *) or (*) where (*) denotes any number of extra dimensions. It’s data type should be float16, bfloat16, float32, float64.

  • label (Tensor) – Label tensor, random sampled from Poisson distribution \(label \sim \text{Poisson}(input)\). The shape of input tensor should be (N, *) or (*), same shape as the input tensor. It’s data type should be float16, bfloat16, float32, float64.

  • log_input (bool, optional) – Whether to the treat input tensor as log input. If True the loss is computed as, \(\exp(\text{input}) - \text{label} * \text{input}\) . If False then loss is \(\text{input} - \text{label} * \log(\text{input}+\text{epsilon})\) . Default: True.

  • full (bool, optional) – Whether to compute full loss. If True, the Stirling approximation term is added. If False, the Stirling approximation is dropped. Default: False.

  • epsilon (float, optional) – A small value to avoid evaluation of \(\log(0)\) when log_input=False. epsilon > 0. Default: 1e-8.

  • reduction (str, optional) – Indicate how to reduce the loss, the candidates are 'none' | 'mean' | 'sum'. If reduction is 'mean', the reduced mean loss is returned; if reduction is 'sum', the reduced sum loss is returned; if reduction is 'none', no reduction will be applied. Default is 'mean'.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Examples

>>> import paddle
>>> import paddle.nn.functional as F
>>> paddle.seed(2023)

>>> input = paddle.randn([5, 2], dtype=paddle.float32)
>>> label = paddle.randn([5, 2], dtype=paddle.float32)
>>> loss = F.poisson_nll_loss(input, label, log_input=True, reduction='none')
>>> print(loss)
Tensor(shape=[5, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[ 1.09998012,  3.68829036],
        [ 1.95291090,  0.69603068],
        [-0.39289063, -2.03713036],
        [ 4.52518702,  1.28625548],
        [ 3.94454789,  0.53521496]])
>>> loss = F.poisson_nll_loss(input, label, reduction='mean')
>>> print(loss)
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
       1.52983975)