Quant Memo
Advanced

MC Dropout as Approximate Inference

Leaving dropout switched on at prediction time and running the same input through the network many times turns an ordinary regularization trick into a cheap way to measure how uncertain the model actually is.

Prerequisites: Dropout Regularization, Bayesian Neural Networks

Dropout is normally something you turn off at prediction time — during training it randomly silences a fraction of neurons to prevent overfitting, and once the network is trained, you switch it off so predictions are stable and repeatable. MC dropout does the opposite on purpose: it leaves dropout switched on at prediction time, runs the same input through the network many times, and looks at how much the answer moves around. That spread is not noise to be discarded — it is a usable estimate of how uncertain the model is about this particular input.

The analogy: asking a blindfolded panel the same question

Imagine asking the same question to the same panel of experts many times, but each time you randomly cover a different subset of their ears and notes, so each answer comes from a slightly different, incomplete version of the panel. On an easy, well-understood question, blocking out a random subset barely changes the group's answer — every version of the panel converges on the same conclusion. On a genuinely hard or unfamiliar question, blocking different subsets each time produces wildly different answers, because no consistent internal reasoning survives the disruption. MC dropout does exactly this to a neural network: each forward pass randomly disables a different subset of neurons, and the spread of the resulting predictions reveals how much the network's answer actually depends on which neurons happen to survive — a proxy for how confident it genuinely is.

Why this counts as approximate Bayesian inference

Gal & Ghahramani showed that running a network with dropout active at test time and averaging over many stochastic passes is mathematically equivalent to approximately sampling from a variational posterior over the network's weights — each dropout mask corresponds to a different sampled sub-network, and averaging over masks approximates averaging over a distribution of plausible weight settings, exactly what a Bayesian neural network would do by design, without ever needing to train one.

Worked example 1: computing predictive uncertainty by hand

A regression network with dropout p=0.5p=0.5 is run on the same input four times at test time, giving outputs y={2.1,1.8,2.4,1.5}y = \{2.1, 1.8, 2.4, 1.5\}. The predictive mean is the ordinary average:

yˉ=2.1+1.8+2.4+1.54=1.95\bar{y} = \frac{2.1+1.8+2.4+1.5}{4} = 1.95

The predictive variance (as an uncertainty estimate) is the sample variance of these four passes:

Var(y)=(2.11.95)2+(1.81.95)2+(2.41.95)2+(1.51.95)24=0.0225+0.0225+0.2025+0.20254=0.1125\text{Var}(y) = \frac{(2.1-1.95)^2+(1.8-1.95)^2+(2.4-1.95)^2+(1.5-1.95)^2}{4} = \frac{0.0225+0.0225+0.2025+0.2025}{4} = 0.1125

In words: the network's best guess is 1.951.95, and the spread across four differently-masked versions of itself, 0.11250.1125, is the model's estimate of how much confidence to place in that guess — more passes (30–100 in practice) give a smoother estimate of both numbers.

Worked example 2: comparing an easy input to an unfamiliar one

The same network, run 4 times on an input clearly inside its training distribution, gives y={4.02,3.98,4.01,3.99}y = \{4.02, 3.98, 4.01, 3.99\} — mean 4.04.0, variance 0.000170.00017: tiny spread, high confidence. Run 4 times on an input far outside anything it trained on, it gives y={4.02,1.5,6.8,3.0}y = \{4.02, 1.5, 6.8, 3.0\} — mean 3.833.83, variance 3.833.83: over 20,000 times larger. The point estimate alone (around 3.83.84.04.0 in both cases) would look almost identical; only the spread across repeated stochastic passes reveals that the second input is one the network genuinely does not understand.

familiar input unfamiliar input
Four dropout masks on the same familiar input agree closely (low predictive variance); four masks on an unfamiliar input scatter widely (high predictive variance).

Distribution · normal
-2.000.002.00μvalue →
Within ±1σ 68.3%mean μ 0.00std σ 1.00

Each MC dropout pass is one draw toward building a curve like this — narrow and tall when the passes agree, wide and flat when they don't; the width itself is the uncertainty estimate, not an afterthought.

Leaving dropout active at prediction time and running many stochastic forward passes on the same input approximates sampling from a Bayesian posterior over the network's weights. The mean of the passes is the prediction; the variance across passes is a cheap, retrofittable estimate of the model's uncertainty, with no retraining required.

What this means in practice

MC dropout is popular in production because it needs zero architecture changes — any network already trained with dropout layers can produce uncertainty estimates just by leaving those layers on at inference and running the forward pass 20–50 times, trading extra compute for a usable confidence signal, useful for flagging inputs a trading or risk model should not be trusted on.

The common confusion is treating MC dropout's variance as the complete picture of uncertainty. It only captures uncertainty that dropout's particular masking pattern can express through the trained architecture — this tends to underestimate uncertainty compared to a properly trained deep ensemble, and a network whose dropout rate was tuned purely for regularization (not for calibrated uncertainty) can produce spreads that are systematically too narrow or too wide relative to how wrong it actually turns out to be.

Related concepts

Practice in interviews

Further reading

  • Gal & Ghahramani, Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning (2016)
ShareTwitterLinkedIn