gaussian_nll_loss
→Tensorgaussian_nll_loss(x: Tensor, target: Tensor, var: Tensor, full: bool = False, eps: float = 1e-06, reduction: str = 'mean')Gaussian negative log-likelihood for heteroscedastic regression.
Maximum-likelihood objective when the prediction is a distribution over the target rather than a point estimate. Training a network with two heads (one for , one for ) against this loss recovers calibrated predictive uncertainty — useful for active learning, decision-aware regression, and Bayesian deep ensembles.
The variance var is clamped below by eps to prevent
division by zero and runaway log-terms when the network
initially predicts near-zero variance.
Parameters
xTensortargetTensorx.varTensorx.fullbool= Falseepsfloat= 1e-06var for numerical stability
(default 1e-6).reductionstr= 'mean'"mean" (default), "sum", or "none".Returns
TensorScalar or full-shape per reduction.
Notes
Per-element loss (constant terms dropped):
The first term penalises over-confidence (small variance), the second term rewards accuracy weighted by precision. Together they give the model a clean trade-off: when it cannot reduce , increasing decreases the loss — this is what produces calibrated uncertainty estimates.
Examples
>>> import lucid
>>> from lucid.nn.functional import gaussian_nll_loss
>>> mu = lucid.tensor([0.0, 1.0])
>>> y = lucid.tensor([0.5, 1.0])
>>> var = lucid.tensor([1.0, 0.25])
>>> gaussian_nll_loss(mu, y, var)
Tensor(-0.2218...)