Predicting Distributions, Not Points
Heteroscedastic regression, mixture density networks and proper scoring rules.
A point prediction hides what a decision needs: how noisy the target is here, whether two very different outcomes are both likely, how far away the 95th percentile lies. Train the network to output a whole distribution and you gain all of that, along with three new problems: the variance can cheat, a mixture can collapse, and you need a score that cannot be gamed.
What you’ll learn
- Derive the heteroscedastic Gaussian negative log-likelihood, its gradients and the optimal variance, and explain the inverse-variance pitfall and the β-NLL remedy.
- Build a mixture density network for multimodal targets and write its loss stably with log-sum-exp.
- Define proper and strictly proper scoring rules, compare the log score, the CRPS and the pinball loss, and prove that the pinball loss is minimized by a quantile.
- Separate aleatoric from epistemic uncertainty, and explain why recasting regression as classification over bins can train better.
Learning the noise level
In heteroscedastic regression the noise level depends on the input. Give the network two outputs, a mean and a variance , kept positive by predicting or applying a softplus, and minimize the Gaussian negative log-likelihood (Nix & Weigend, 1994):
Differentiate with respect to both outputs:
Averaging over given and setting the derivative with respect to to zero gives the optimal variance: the expected squared error of the mean head. With the mean at , it is the true conditional variance.
The mean's gradient is the squared-error gradient divided by : every point's pull on the mean is weighted by its inverse predicted variance. That is the source of the pitfall below.
A network predicts in a region it fits badly and in a region it fits well. Under the Gaussian NLL, how many times more does a unit of squared error pull on the mean in the well-fit region?
Show the answer
16 ×
The weights are : against , a ratio of . The badly fit region, where the mean most needs to move, gets the weakest gradient.
The pitfall. Seitzer et al. (2022) showed that this weighting can trap training. If some region is hard to fit early on, the network raises there, which shrinks that region's gradient, so it stays badly fit, so stays high: a self-reinforcing loop that they describe as effectively undersampling the badly predicted points. The result can be a stable but poor fit of the mean, even on a simple sinusoid that squared error fits easily. Their remedy, β-NLL, multiplies each point's loss by its predicted variance raised to the power , with the gradient stopped through that factor so it acts as a per-point learning rate:
.detach() in PyTorch). is the plain NLL; gives the mean exactly the squared-error gradient while still learning a variance; weights points by instead of , which Seitzer et al. found the best trade-off between accuracy and log-likelihood.import torch.nn.functional as F
mu, log_var = model(x).unbind(-1) # two outputs per example
var = log_var.exp()
nll = F.gaussian_nll_loss(mu, y, var) # mean of 0.5*(log var + (y-mu)^2/var)
beta = 0.5 # beta-NLL: reweight by detached var**beta
per_point = 0.5 * (log_var + (y - mu) ** 2 / var)
loss = (var.detach() ** beta * per_point).mean()Multimodal targets: mixture density networks
A Gaussian, however wide, has one mode. Many problems have several right answers for the same input: the joint angles that put a robot arm's hand at a given point (elbow up or elbow down), the next pen stroke in handwriting, the future positions of a car at a junction. A squared-error network predicts the conditional mean, which can be an impossible average of the valid answers. Bishop's (1994) mixture density network outputs a whole mixture:
Mixture outputs need care: a component can shrink its variance onto a single training point and drive the likelihood to infinity (put a floor on ), components can collapse onto one mode or go unused, and the gradient of the mixing weights is weak early in training. The idea travels well. Graves (2013) generated handwriting with a recurrent network whose outputs were a mixture over pen offsets, and PixelCNN++ (Salimans et al., 2017) modeled 8-bit pixel values with a mixture of discretized logistic distributions.
For one input, the target is or with equal probability. A network trained with squared error and a two-component mixture density network both see plenty of such data. What do they predict?
- Both predict or , whichever they saw last
- The squared-error network predicts , a value never observed; the MDN puts weight on components near and
- Both predict
- The squared-error network predicts ; the MDN predicts
Show the answer
B. The squared-error network predicts , a value never observed; the MDN puts weight on components near and
Squared error is minimized by the conditional mean, . The mixture likelihood is maximized by matching the actual distribution: two narrow components at with equal weights.
Scoring a predictive distribution
| Score | Definition | Properties |
|---|---|---|
| log score | , with the predicted density | strictly proper; looks only at the density at the outcome; infinite if , so it punishes overconfident tails hard |
| CRPS | , with independent | strictly proper for distributions with a finite mean; in the units of ; reduces to absolute error for a point forecast; closed forms for Gaussians and mixtures |
| pinball (quantile) loss | with | scores a single quantile ; minimized by the -quantile; |
| "linear" score | improper: its expected value rewards concentrating mass where is highest, not reporting honestly |
Let have a continuous distribution function . The expected loss of reporting is
Differentiate with respect to : moving up by saves on every outcome above it and costs on every outcome below:
is convex with exactly where . So a network trained with learns the conditional -quantile, being the median (absolute error), and several heads with different give prediction intervals.
For some input the target is . A network is trained with the pinball loss at . What does it predict for this ?
Show the answer
1.28
The 0.9-quantile of a standard normal, . Expected pinball loss there is about , and it rises on either side (about at ).
Two kinds of uncertainty, and regression by classification
Everything so far models aleatoric uncertainty, the noise in the data itself, which no amount of data removes. Epistemic uncertainty is uncertainty about the model, which shrinks with more data; a single network's predicted says nothing about it, and can be confidently wrong far from the training data. Kendall and Gal (2017) model both in one Bayesian framework. A simple and strong practical recipe is the deep ensemble (Lakshminarayanan, Pritzel & Blundell, 2017): train networks from different seeds with a proper scoring rule and average their predictive distributions. By the law of total variance, the mixture's variance splits into the two kinds:
Regression as classification. Instead of a parametric density, cut the range of into bins and predict a softmax over them, trained with cross-entropy. WaveNet (van den Oord et al., 2016) did this for audio: it compressed 16-bit samples with the -law , , into 256 levels and predicted a categorical distribution over them, which can take any shape. For a continuous target, the scalar is spread over bins: two-hot splits it between the two neighboring bins, and HL-Gauss integrates a Gaussian centered on the target over each bin, a form of label smoothing in target space; the prediction is the expected bin center, for bin centers .
Farebrother et al. (2024) replaced the squared-error loss used to train deep reinforcement learning value functions with HL-Gauss cross-entropy and found better performance and scaling across Atari, robotic manipulation, chess and a language-agent task, attributing the gains mainly to robustness to noisy and non-stationary targets. Plausible reasons: the gradient is bounded whatever the target's magnitude, a categorical output can be multimodal or skewed, and the smoothed targets regularize like label smoothing.
Key takeaways
- Heteroscedastic regression predicts and with the Gaussian NLL; the optimal variance is the expected squared residual, and the mean's gradient is weighted by .
- That weighting can lock in poor fits of hard regions; β-NLL reweights each point by a detached , with a good trade-off and giving squared-error gradients for the mean.
- Mixture density networks output for multimodal targets, with a log-sum-exp loss and a floor on the variances.
- Strictly proper scoring rules (log score, CRPS, Brier) are uniquely minimized by the true distribution; the pinball loss is minimized by the -quantile, and the CRPS integrates it over all quantiles.
- Variance heads capture aleatoric uncertainty; ensembles add epistemic uncertainty through disagreement. Regression recast as classification over bins (WaveNet, HL-Gauss) can train more robustly.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A network learns and with the Gaussian NLL. Holding the mean head fixed, which variance minimizes the expected loss at ?
- , whatever the data
- , the expected squared error of the mean head
- , since a smaller variance always gives a higher likelihood
Show the answer
B. , the expected squared error of the mean head
Setting gives the expected squared residual. If the mean head is right, this is the true conditional variance.
In β-NLL, what does do to the gradient that reaches the mean head?
- It becomes the plain squared-error gradient , while a variance is still learned
- It is divided by
- It becomes zero, so only the variance is learned
- It is unchanged from the ordinary NLL
Show the answer
A. It becomes the plain squared-error gradient , while a variance is still learned
The detached factor multiplies , giving ; at the inverse-variance weighting disappears.
A model is trained with the pinball loss at . What does it estimate?
- The conditional mean minus one tenth of a standard deviation
- The probability that exceeds its median
- The conditional 0.1-quantile of
- The conditional 0.9-quantile of
Show the answer
C. The conditional 0.1-quantile of
The expected loss has derivative , which is zero at : the 0.1-quantile. Underestimates (positive residuals) cost only per unit, overestimates , so the prediction sits low.
Which of these is not a proper scoring rule for a predictive density and outcome ?
- The log score
- The CRPS
- The linear score
- The Brier score, for binary outcomes
Show the answer
C. The linear score
The expected linear score is minimized by concentrating where the true density is largest, not by . The other three are strictly proper.
Further reading
- D. A. Nix & A. S. Weigend, "Estimating the mean and variance of the target probability distribution," IEEE International Conference on Neural Networks (1994).
- C. M. Bishop, "Mixture density networks," Technical Report NCRG/94/004, Aston University (1994).
- T. Gneiting & A. E. Raftery, "Strictly proper scoring rules, prediction, and estimation," Journal of the American Statistical Association 102 (2007).
- A. Kendall & Y. Gal, "What uncertainties do we need in Bayesian deep learning for computer vision?," NeurIPS (2017).
- M. Seitzer, A. Tavakoli, D. Antic & G. Martius, "On the pitfalls of heteroscedastic uncertainty estimation with probabilistic neural networks," ICLR (2022).
- J. Farebrother et al., "Stop regressing: Training value functions via classification for scalable deep RL," ICML (2024); arXiv:2403.03950.