fn
poisson_nll_loss
→Tensorpoisson_nll_loss(x: Tensor, target: Tensor, log_input: bool = True, full: bool = False, eps: float = 1e-08, reduction: str = '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
xTensorPredicted Poisson rate. By default (
log_input=True)
treated as for numerical stability;
set log_input=False to pass the rate
directly.targetTensorObserved counts, broadcast-compatible with
x.log_inputbool= TrueWhether
x is (default) or
. The log-form avoids exponentiating an
unbounded prediction in inner loops.fullbool= FalseInclude the Stirling approximation term
in the loss. Has no effect on gradients (constant in
x) but yields the correct log-likelihood value. Not
currently added — kept for API parity.epsfloat= 1e-08Small constant added before when
log_input=False (default 1e-8).reductionstr= '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.7299...)