Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Dropout at test time
Dropout normally switches off random hidden units during training only. MC dropout keeps it on when predicting: run the same input through the network many times, each time with different units switched off, and look at how much the answers vary. If they vary a lot, treat the prediction as uncertain. It costs nothing extra to train. The demo shows twenty such passes; move the dropout rate and see that the spread follows the rate, not the data.
MC dropout is widely used in robotics and medical imaging because it needs no retraining; but benchmarks show its uncertainty degrades under distribution shift more than ensembles’, so treat it as a cheap baseline.
- 1. MC dropout keeps dropout on…
- 2. Its uncertainty is the…
- 3. It needs retraining of the network?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Predictive: with masks z_t, f̂(x) = (1/T) Σ_t f(x; θ ⊙ z_t); epistemic variance ≈ (1/T) Σ_t f_t² − f̂²; add the noise variance 1/τ for the predictive variance of y.
- Variational view (Gal and Ghahramani, 2016): each weight row is either M_i or 0, q(W) = Π mixtures of Bernoullis; with weight decay λ, the dropout loss approximates the ELBO for a Gaussian process-like model, and τ = (1 − p) l² / (2 N λ) links prior length scale l, dataset size N and noise precision τ.
- Choosing p: grid search on validation log-likelihood, or concrete dropout (Gal, Hron and Kendall, 2017), a continuous relaxation that learns p per layer.
- Classification: average the softmax outputs; uncertainty from predictive entropy or mutual information (BALD) between prediction and weights.
- Vision: Kendall and Gal (2017) combined MC dropout (epistemic) with a learned noise variance (aleatoric) for segmentation and depth.
- Evidence: in the benchmark of Ovadia et al. (2019), deep ensembles beat MC dropout under dataset shift; MC dropout’s uncertainty is often too small.
- 1. Concrete dropout learns…
- 2. BALD measures…
- 3. Under dataset shift, ensembles usually beat MC dropout per…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Using MC dropout
Exercise 1.
- One stochastic forward pass with inverted dropout.
- The MC dropout mean and std over T passes.
- The deterministic prediction.
Practice.
- In PyTorch, model.eval() turns dropout off: switch only the dropout modules back to train mode (BatchNorm must stay in eval mode).
- Use T = 20–100 passes; batch them by repeating the input to keep it fast.
- Tune p (or use concrete dropout) on validation NLL, not accuracy.
- For regression, add a noise term (fixed τ or a learned variance head) or intervals will be far too narrow.
- Check the uncertainty on shifted data and compare against a small ensemble before relying on it.
import torch
def enable_mc_dropout(model):
model.eval()
for m in model.modules():
if isinstance(m, torch.nn.Dropout): m.train() # dropout on, BatchNorm still in eval mode
enable_mc_dropout(model)
with torch.no_grad():
probs = torch.stack([model(x).softmax(-1) for _ in range(50)]) # T x batch x classes
mean = probs.mean(0)
entropy = -(mean * mean.clamp_min(1e-12).log()).sum(-1)
mutual_info = entropy + (probs * probs.clamp_min(1e-12).log()).sum(-1).mean(0) # BALD- 1. model.eval() in PyTorch…
- 2. Typical number of MC passes:
- 3. For regression intervals also add…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Which posterior? The Bernoulli variational family has a fixed shape: each weight is either kept (scaled) or zero with probability p. Optimising the ELBO moves the kept values M but not p (unless p is learned), so the predictive spread is set mostly by p and the size of the activations, not by how well the data constrain the weights. Osband (2016) pointed out that the dropout “posterior” does not concentrate as data grow, which a real posterior does at rate about 1/√n.
Where the spread is large. For one pass, f_t(x) = Σ_j (z_jt/(1 − p)) v_j a_j(x), so Var f(x) = (p/(1 − p)) Σ_j v_j² a_j(x)². The spread is large where hidden activations a_j(x) are large. ReLU activations grow linearly away from the data, so uncertainty grows far away; between two clusters the activations are not larger than at the clusters, so the spread is not larger either. Foong et al. (2020) proved a version of this for one hidden layer: the variance in the gap is bounded by that at the clusters’ edges.
The debate. Hron et al. (2018) showed that the Gaussian-dropout version of the variational objective is ill-posed (the KL is infinite), and Folgoc et al. (2021) argued MC dropout’s distribution is a poor posterior. It remains a useful, cheap heuristic.
- 1. The variance of one MC dropout pass is proportional to…
- 2. A real posterior's spread shrinks with data roughly like…
- 3. ReLU MC dropout uncertainty grows…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does MC dropout’s uncertainty track the data, or the dropout rate?
History.
- N. Srivastava et al., “Dropout” (2014).
- Y. Gal and Z. Ghahramani, “Dropout as a Bayesian approximation” (2016).
- I. Osband, “Risk versus uncertainty in deep learning: Bayes, bootstrap and the dangers of dropout” (2016).
- Y. Gal, J. Hron, A. Kendall, “Concrete dropout” (2017); A. Kendall and Y. Gal, “What uncertainties do we need in Bayesian deep learning for computer vision?” (2017).
- Y. Ovadia et al., “Can you trust your model’s uncertainty?” (2019).
Exercise 2. 1-50-1 ReLU network with inverted dropout on the hidden units, MSE + weight decay 10⁻⁴, 1500 full-batch Adam steps. Data: sin(3x) + N(0, 0.1²), x in [−1, −0.35] ∪ [0.35, 1]. MC predictive from 200 passes; std averaged over the data region (0.4–0.95), the gap (−0.15–0.15) and far away (1.6–2).
| dropout rate, 40 points | std data | std gap | std far | RMSE |
|---|---|---|---|---|
| 0.05 | 0.07 | 0.04 | 0.34 | 0.09 |
| 0.2 | 0.11 | 0.06 | 0.68 | 0.14 |
| 0.5 | 0.13 | 0.09 | 1.13 | 0.24 |
| p = 0.2 | std data |
|---|---|
| 10 points | 0.15 |
| 160 points | 0.14 |
- The rate sets the spread: std grows with p at every location.
- Far away the spread is large, because ReLU activations grow linearly.
- The gap is the opposite of what we want: less uncertain than the data region for every p (HMC on the BNN page was five times more uncertain there).
- No concentration: 16 times more data left the spread unchanged.
- Weight scaling ≈ MC mean: they differed by 0.005–0.008 on the data.
- Seeds 1 and 2: p = 0.2 std 0.19 and 0.16 on the data vs 0.08 and 0.07 in the gap; 10 vs 160 points: 0.08 vs 0.14 and 0.11 vs 0.17.
- Caveat: a small, shallow network; deeper networks and tuned p (concrete dropout) can do better, but the qualitative issues are reported widely.
MC dropout in AI, robotics and aerospace
- Collision prediction: Kahn et al. (2017) used MC dropout and bootstrapping to slow a robot down where collision predictions were uncertain.
- Medical imaging and remote sensing: MC dropout maps flag uncertain pixels in segmentation of scans and satellite images.
- Active learning: BALD with MC dropout picks the most informative samples to label (Gal, Islam and Ghahramani, 2017).
References
- Y. Gal, Z. Ghahramani (2016). “Dropout as a Bayesian approximation: representing model uncertainty in deep learning.” ICML.
- Y. Gal, J. Hron, A. Kendall (2017). “Concrete dropout.” NeurIPS.
- I. Osband (2016). “Risk versus uncertainty in deep learning: Bayes, bootstrap and the dangers of dropout.” NeurIPS Bayesian Deep Learning workshop.
- Y. Ovadia et al. (2019). “Can you trust your model’s uncertainty? Evaluating predictive uncertainty under dataset shift.” NeurIPS.
- A. Foong et al. (2020). “On the expressiveness of approximate inference in Bayesian neural networks.” NeurIPS.