Search

Search papers and lessons

Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles

Balaji Lakshminarayanan, Alexander Pritzel, Charles Blundell · 2016

Averaging a few ordinary networks, each trained with a proper scoring rule and adversarial examples, gives uncertainty estimates as good as approximate Bayesian neural networks.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Losses & regularization
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

A neural network that outputs one answer is usually too sure of itself. Lakshminarayanan, Pritzel and Blundell propose a recipe with three ingredients: train each network with a proper scoring rule so that its stated probabilities are honest, add Adversarial Training so the predictions change smoothly, and average several networks trained from different random starts. The method needs no change to the usual training code, and the authors report that it matches or beats approximate Bayesian neural networks on the uncertainty measures they test.

Builds on: Proper Scoring Rule, Maximum Likelihood Estimation, Ensemble Learning, Adversarial Training · Leads to: Uncertainty Quantification, Bayesian Neural Network (the baseline it competes with)

Why it mattered

The paper gave the field a strong non-Bayesian baseline for predictive uncertainty. Before it, the common route to honest uncertainty from a neural network was a Bayesian treatment, which needs a prior over weights, an approximate posterior and more compute. The discussion says it was surprising to the Bayesian deep learning community that a non-Bayesian, yet probabilistic, method could perform as well as Bayesian networks, and it hopes to encourage other non-Bayesian approaches.

The problem

Neural networks trained to be accurate tend to give overconfident predictions. Their top probability is often high even when they are wrong, and the failure is most dangerous on inputs unlike the training data. The paper frames the goal as two properties:

  • Calibration. Among the cases where the network says 0.8, about 80 percent should turn out to be correct. The paper measures this with proper scoring rules, the log predictive probability and the Brier score.
  • Robustness to dataset shift. On inputs from a different distribution, the network should say it is unsure instead of confidently wrong.

Two earlier options were in the way. A Bayesian neural network gives good uncertainty only if its approximation is good and its prior is reasonable, and it is harder to implement and slower to train. A single network trained by maximum likelihood is easy to train but tends to be overconfident. The paper asks for a method with the simplicity of the second and the uncertainty quality of the first.

How it works

Take a regression task with one input xx and one target yy. Each network outputs a predicted mean μθ(x)\mu_\theta(x) and a predicted variance σθ2(x)\sigma_\theta^2(x), which together describe a Gaussian over yy.

  1. Train one network with a proper score. The training loss is the negative log-likelihood of the observed target under the predicted Gaussian. For a single training point (xn,yn)(x_n, y_n) the paper writes it as −log⁡pθ(yn∣xn)=12log⁡σθ2(x)+(y−μθ(x))22σθ2(x)+constant.-\log p_\theta(y_n \mid x_n) = \tfrac{1}{2}\log \sigma_\theta^2(x) + \frac{(y - \mu_\theta(x))^2}{2\sigma_\theta^2(x)} + \text{constant}. Lower is better. Minimising this maximises the log score, which is proper. Check: a network that is far off must either widen its variance or pay a large squared-error term.
  2. Make the predictions smooth with adversarial examples. For each training input, build a nearby perturbed input x′=x+ϵ sign(∇xℓ)x' = x + \epsilon\,\mathrm{sign}(\nabla_x \ell), where ϵ\epsilon is 1 percent of the input range in each dimension. Train on the sum ℓ(θ,x,y)+ℓ(θ,x′,y)\ell(\theta, x, y) + \ell(\theta, x', y). This pushes the network to give the correct label high likelihood throughout a small neighbourhood of each training point. Check: the perturbation is small, so x′x' should look like xx to a human, and its label is still yy.
  3. Train M networks independently. The paper uses M=5M = 5 by default. Each network starts from different random weights and sees the whole training set in a different random order. Bagging was tried and made results worse in their experiments. Check: the networks do not talk to each other during training, so the five runs can happen in parallel on five machines.
  4. Average the predictions. The ensemble predicts the uniform mixture p(y∣x)=1M∑mpθm(y∣x)p(y \mid x) = \frac{1}{M}\sum_m p_{\theta_m}(y \mid x). For classification this averages the probability vectors. For regression, the mixture is summarised by a single Gaussian. Check: averaging probabilities keeps the total at 1, so the result is still a valid distribution.

A concrete instance of step 4. At one test point, three networks predict (μ,σ2)(\mu, \sigma^2) pairs of (2.0,0.5)(2.0, 0.5), (2.4,0.9)(2.4, 0.9) and (1.6,0.4)(1.6, 0.4). The ensemble mean is (2.0+2.4+1.6)/3=2.0(2.0 + 2.4 + 1.6)/3 = 2.0. The ensemble variance has two parts: the average of the individual variances, (0.5+0.9+0.4)/3=0.6(0.5 + 0.9 + 0.4)/3 = 0.6, plus the spread of the means, 13[(2.0−2.0)2+(2.4−2.0)2+(1.6−2.0)2]≈0.107\frac{1}{3}\bigl[(2.0-2.0)^2 + (2.4-2.0)^2 + (1.6-2.0)^2\bigr] \approx 0.107. The total is 0.7070.707, larger than the average member variance of 0.60.6, because the members disagree. The diagram shows how the pieces fit together.

flowchart LR
  D["training set"] --> N1["network 1<br/>scoring rule + adversarial"]
  D --> N2["network 2"]
  D --> NM["network M = 5"]
  N1 --> A["average the predictions"]
  N2 --> A
  NM --> A
  A --> U["mean and uncertainty"]

The math

Stage 1: the scoring rule

The paper defines a scoring rule S(pθ,(y,x))S(p_\theta, (y, x)) that is higher when the predicted distribution pθ(y∣x)p_\theta(y \mid x) is better, and a proper rule as one whose expected value is largest when pθ=qp_\theta = q, the true distribution. Training minimises L(θ)=−S(pθ,q)\mathcal{L}(\theta) = -S(p_\theta, q). The log likelihood, S=log⁡pθ(y∣x)S = \log p_\theta(y \mid x), is proper by Gibbs' inequality. The paper also notes that the Brier score, which is the squared error between a one-hot label and the predicted probability vector, is proper, so the common practice of training a classifier on squared error is justified. Step 1 of the walkthrough is this loss with a Gaussian pθp_\theta.

For the tiny instance: a training point with y=2y = 2, and a network predicting μ=1.5\mu = 1.5. Compare two variances. With σ2=0.25\sigma^2 = 0.25, the loss is 12ln⁡0.25+(2−1.5)22⋅0.25=−0.693+0.5=−0.193\tfrac{1}{2}\ln 0.25 + \frac{(2 - 1.5)^2}{2 \cdot 0.25} = -0.693 + 0.5 = -0.193 (dropping the constant). With σ2=1\sigma^2 = 1, it is 0+0.252=0.1250 + \frac{0.25}{2} = 0.125. The narrower variance has the lower loss because it is right about the spread. The constant is the same in both, so the ranking does not change.

Stage 2: adversarial smoothing

The fast gradient sign step is x′=x+ϵ sign(∇xℓ(θ,x,y))x' = x + \epsilon\,\mathrm{sign}(\nabla_x \ell(\theta, x, y)). The gradient points in the direction that raises the loss most per unit of max-norm change, so x′x' is the nearby input where a linear approximation of the loss rises fastest. Training on both xx and x′x' asks the predicted distribution to stay close to the label across the whole ϵ\epsilon-neighbourhood. The paper argues that this smooths the predictive distribution. Its experiments show gains on MNIST for every ensemble size, while on SVHN the gain is clear for a single network and fades as MM grows.

Stage 3: independent members

Each member mm has its own parameters θm\theta_m, and each is trained on the full data with its own random initialisation and shuffling. No term couples the members, which is why training parallelises trivially.

Stage 4: the mixture

The ensemble is the uniform mixture p(y∣x)=1M∑m=1Mpθm(y∣x)p(y \mid x) = \frac{1}{M}\sum_{m=1}^M p_{\theta_m}(y \mid x). For regression, each member is Gaussian with mean μm\mu_m and variance σm2\sigma_m^2, and the mixture is approximated by one Gaussian with

μ∗=1M∑m=1Mμm,σ∗2=1M∑m=1M(σm2+μm2)−μ∗2.\mu_* = \frac{1}{M}\sum_{m=1}^M \mu_m, \qquad \sigma_*^2 = \frac{1}{M}\sum_{m=1}^M \bigl(\sigma_m^2 + \mu_m^2\bigr) - \mu_*^2.

The second formula is the mixture variance: the average of each member's second moment σm2+μm2\sigma_m^2 + \mu_m^2, minus the square of the mean. Rearranged, it equals the average individual variance plus the spread of the means, which is the split used in the concrete instance above. The paper uses the Gaussian approximation so that quantiles and predictive probabilities are easy to compute.

Results

The paper reports regression on standard benchmark datasets using the protocol of Hernandez-Lobato and Adams: 20 train-test splits for most datasets, 5 for protein and a single split for Year Prediction MSD, with one hidden layer, 50 hidden units for the smaller datasets and 100 for the larger ones, and 5 networks in the ensemble. The table gives a subset of the numbers from its Table 1, with the authors' mean and standard deviation.

DatasetRMSE, PBPRMSE, MC-dropoutRMSE, Deep EnsemblesNLL, PBPNLL, MC-dropoutNLL, Deep Ensembles
Boston housing3.01 ± 0.182.97 ± 0.853.28 ± 1.002.57 ± 0.092.46 ± 0.252.41 ± 0.25
Energy1.80 ± 0.051.66 ± 0.192.09 ± 0.292.04 ± 0.021.99 ± 0.091.38 ± 0.22
Naval propulsion plant0.01 ± 0.000.01 ± 0.000.00 ± 0.00-3.73 ± 0.01-3.80 ± 0.05-5.63 ± 0.05
Yacht1.02 ± 0.051.11 ± 0.381.58 ± 0.481.63 ± 0.021.55 ± 0.121.18 ± 0.21

What this means. On NLL, the measure that depends on the predicted uncertainty, the ensemble is best or tied on most of the datasets in the table, and the gap is large on Energy and Naval. On RMSE, the ensemble is sometimes worse, for example on Yacht (1.58 against 1.02 for PBP). The authors attribute this to optimising NLL instead of squared error. The results are on small, standard benchmarks with one hidden layer, so they say little about large models by themselves.

For classification, the paper uses MNIST with a 3-hidden-layer MLP of 200 units per layer, and SVHN with a convolutional network. Its figures show that increasing MM improves accuracy, NLL and Brier score, and that the ensemble beats MC-dropout on all three. The text gives no table of numbers for these, so this lesson does not quote any. On out-of-distribution data (MNIST networks tested on NotMNIST letters), the predictive entropy of the ensemble rises faster with MM than MC-dropout's, so the ensemble is less confident on unseen classes. On a mix of MNIST and NotMNIST inputs, where the network is wrong on the unseen letters, the paper's accuracy-versus-confidence curves show that the ensemble is significantly more robust than MC-dropout: MC-dropout gives confident wrong answers that the ensemble does not.

Limits the paper itself states or implies. The ensemble has MM times as many parameters as one network, which matters for memory. The authors suggest distilling the ensemble into a simpler model for that reason. Adversarial training helps on some datasets and metrics but is not always necessary, and on SVHN its benefit fades as MM grows. The Gaussian likelihood for regression may be too restrictive for some targets; the paper points to mixture density networks as one extension.

Reading guide

The paper has a short main text and a long set of appendices. Read the sections in this order, with the prerequisite lessons each one needs.

Check yourself

QuestionWhy does the paper train each network with a proper scoring rule rather than just an accuracy-based loss?Show answer

A proper rule is maximised, on average, by the true predictive distribution, so the network is pushed to report honest probabilities. An accuracy-based loss only cares which label is top and gives no incentive to report calibrated confidence. The paper's calibration and uncertainty measures are proper scores, so training on one aligns the training objective with what is evaluated.

QuestionA network predicts mean 1.5 and variance 0.25 for a target that equals 2. Compute the variance-dependent part of the Gaussian loss, 12ln⁡σ2+(y−μ)22σ2\tfrac{1}{2}\ln\sigma^2 + \frac{(y-\mu)^2}{2\sigma^2}, ignoring the constant.Show answer

12ln⁡0.25=−0.693\tfrac{1}{2}\ln 0.25 = -0.693, and (2−1.5)22×0.25=0.250.5=0.5\frac{(2-1.5)^2}{2 \times 0.25} = \frac{0.25}{0.5} = 0.5. The total is −0.693+0.5=−0.193-0.693 + 0.5 = -0.193.

QuestionThree members of an ensemble predict means 2.0, 2.4 and 1.6 with variances 0.5, 0.9 and 0.4. What is the ensemble variance?Show answer

The average variance is (0.5+0.9+0.4)/3=0.6(0.5 + 0.9 + 0.4)/3 = 0.6. The spread of the means around 2.0 is 13(0+0.16+0.16)≈0.107\frac{1}{3}(0 + 0.16 + 0.16) \approx 0.107. The total is about 0.707. Using the formula 13∑(σm2+μm2)−μ∗2\frac{1}{3}\sum(\sigma_m^2 + \mu_m^2) - \mu_*^2 gives the same value.

QuestionApplied scenario: a team wants a model whose probabilities can be trusted on inputs unlike its training data, but cannot afford to run a Bayesian method. The paper's ensemble uses 5 networks. Name one cost the team should expect, and one reason the paper gives for why the members should be trained independently.Show answer

Cost: the ensemble has about five times as many parameters as one network, and prediction runs five networks, so memory and inference time both rise. Reason for independence: the paper uses random initialisation and shuffling instead of bagging, because bagging gave worse results for deep networks in their experiments, and independent training lets the members run in parallel.

Sources

Read the full paper

Balaji Lakshminarayanan, Alexander Pritzel, Charles Blundell, 2016. arXiv:1612.01474