poisson_nll_loss(input: Tensor, target: Tensor, log_input: bool = True, full: bool = False, size_average: bool | None = None, eps: float = 1e-08, reduce: bool | None = None, reduction: Reduction = 'mean')Poisson negative log-likelihood loss for count regression.
The maximum-likelihood objective when targets are non-negative
integer counts modelled as .
Standard for forecasting tasks (web clicks, event counts,
biological cell counts) where the variance scales with the
mean. Unlike mse_loss, this loss respects the
heteroscedasticity inherent in count data.
Parameters
inputTensorPredicted Poisson rate: by default
(
log_input=True), the rate itself with
log_input=False. A bool or integer input is computed in the
default floating dtype, which a float16 target does not narrow.targetTensorObserved counts that broadcast with
input; a shape that does not
raises ValueError. A bool target is RuntimeError beside a bool
input and under full; a bool input is, with log_input=False.log_ inputbool= TrueWhether
input is (default) or
. The log-form avoids exponentiating an
unbounded prediction in inner loops.fullbool= FalseInclude the Stirling approximation term
in the loss, where
target > 1 (at 0 and 1 the true
is 0). Has no effect on gradients (constant in
input) but yields the correct log-likelihood value.epsfloat= 1e-08Small constant added before when
log_input=False (default 1e-8).reductionstr= 'mean'"mean" (default), "sum", or "none".size_ averagestr= 'mean'"mean" (default), "sum", or "none".reducestr= 'mean'"mean" (default), "sum", or "none".Returns
TensorScalar or full-shape per reduction.
Notes
Per-element loss (constant-in- terms dropped):
Gradient w.r.t. is (log-input form) or (rate form). Both push toward in expectation.
Examples
>>> import lucid
>>> from lucid.nn.functional import poisson_nll_loss
>>> log_lam = lucid.tensor([0.0, 1.0, 2.0])
>>> y = lucid.tensor([1.0, 2.0, 5.0])
>>> poisson_nll_loss(log_lam, y, log_input=True)
tensor(-0.2976)