Calibrated uncertainty
Ensembles and conformal prediction give error bars, and a calibration test checks them on held-out runs.
Outcome: Tell epistemic from aleatoric uncertainty; get error bars from a deep ensemble and test their calibration; compute split-conformal intervals and say what they do not cover.
Builds on Limits and trust, Gaussian processes
The project’s network gave no warning outside the box, where the GP’s on the POD coefficients was about 13 times its value on the validation runs (a first surrogate, end to end); an ensemble of networks gives one, and this lesson tests it, then turns to a method with guaranteed coverage under one stated condition.
Two kinds of uncertainty
Epistemic uncertainty means the model does not know, because there was little or no data near this input. It shrinks with more runs near that input, and for a smooth deterministic solver it is usually what matters most. Aleatoric uncertainty is scatter that the inputs do not explain: two near-identical crash designs can fold differently, and nominally equal parts differ in a test. More runs do not remove it. Part of the scatter in simulation data is only numerical, such as a short averaging window, and that part falls with longer runs, not with more of them.
Deep ensembles
A Gaussian process (Example 3-4) gives an epistemic estimate directly: with common kernels its grows away from the data, and a noise term adds the aleatoric part. A plain neural network gives no such estimate, so it has to be added.
The same network trained several times, here five, from different random initial weights, is a deep ensemble (Lakshminarayanan, Pritzel and Blundell 2017). The members tend to agree near the data and to disagree away from it, though they can also agree and all be wrong. The mean is the prediction and the spread the uncertainty, at the cost of five trainings and five evaluations. MC dropout (Monte Carlo dropout: dropout kept on at prediction time, and repeated; Gal and Ghahramani 2016) is cheaper, but its spread depends on the dropout rate, which is a modelling choice. A large comparison of such methods under dataset shift, on classification benchmarks (Ovadia et al. 2019), found deep ensembles best on most metrics, MC dropout included; for a regression surrogate, the comparison has to be made on held-out runs.
import numpy as np
import torch
from torch import nn
from aircraft import MLP, load_runs, scale_designs, split_runs
d = load_runs()
train, val, test, in_box = split_runs(d)
# alpha and sweep, scaled as in 4.3.
D = torch.tensor(scale_designs(d, train)[0])
CL = torch.tensor(d["CL"])[:, None]
x, y = D[train], CL[train] # the 36 training runs
def train_one(seed):
# Different initial weights for each member.
torch.manual_seed(seed)1
net = MLP()
opt = torch.optim.Adam(net.parameters(), lr=1e-2)
for _ in range(500):
opt.zero_grad()
nn.functional.mse_loss(net(x), y).backward()
opt.step()
return net
# Try range(2): a spread from two members is itself rough.
ensemble = [train_one(s) for s in range(5)]
# Test runs 46 (4 deg, 28 deg, inside) and 55 (10 deg, 22 deg, outside).
x_new = D[[46, 55]]
with torch.no_grad():
preds = torch.stack([net(x_new) for net in ensemble])2
print(preds.mean(0).squeeze()) # the predictions3
print(preds.std(0).squeeze()) # the spread
print(CL[[46, 55]].squeeze()) # the solver
- Each member is the
MLPof Example 4-5, on the same scaled inputs, trained on the 36 training runs with its own rate and number of steps. The only difference between members is the seed, hence the initial weights: training here is full-batch, with no shuffling or dropout. predshas shape (members, designs, outputs) = (5, 2, 1).- Mean and spread over the members, axis 0.
stdis the sample standard deviation: PyTorch divides by by default.
tensor([0.4567, 0.9421]) tensor([0.0003, 0.0045]) tensor([0.4566, 0.9498])
In the original deep-ensembles method of Lakshminarayanan, Pritzel and Blundell, each member also predicts a variance and is trained with the Gaussian negative log-likelihood (in PyTorch, nn.GaussianNLLLoss) instead of the squared error, so the ensemble also covers scatter in the data.
Example 7-6 prints means of 0.4567 and 0.9421 against the solver’s 0.4566 and 0.9498, and spreads of about 0.0003 and 0.0045. Outside the box the spread is about sixteen times larger, but the error there, 0.0077, is still about 1.7 times the spread: the spread flags the run and understates its error. On a response with a regime change the members could all agree and be wrong.
Calibration
DefinitionCalibrated
The check: for several levels (50 %, 80 %, 90 %, 95 %), the share of held-out runs inside is counted. Plotted against the nominal level, the points of a calibrated model lie on the diagonal.
A correction fitted on held-out runs holds for designs like those runs. In one comparison of a Gaussian-process head, MC dropout and a deep ensemble on a car-aerodynamics surrogate (Tangsali et al. 2026, on DrivAerStar), the authors report that rescaling on validation runs brought interval coverage close to nominal for the body style trained on, and that on new body styles the error grew faster than the uncertainty.
Split conformal prediction
Conformal prediction gives any surrogate intervals with a coverage guarantee, on one condition stated below, using held-out runs. A calibration set of runs, used neither to train nor to tune the model, is kept aside, and the absolute residual is computed on each. For a target coverage of (for example 90 %, ; alpha in the code), is a slightly conservative quantile of these residuals. The interval for a new design is . The recipe and both bounds below follow the tutorial of Angelopoulos and Bates 2021.
# Run after the ensemble listing, in the same session:
# its mean is the surrogate.
def predict(X):
with torch.no_grad():
return torch.stack([net(X) for net in ensemble]).mean(0)
# Calibrate on the 8 validation runs.
r = np.sort((CL[val] - predict(D[val])).abs().numpy().ravel())
n = len(r)
def q_hat(alpha):
k = int(np.ceil((n + 1) * (1 - alpha)))1
# The k-th smallest residual; too few runs: no interval.
return r[k - 1] if k <= n else np.inf2
print(q_hat(0.1), round(float(q_hat(0.2)), 5))
q = q_hat(0.2) # aim for 80 % coverage
err = (CL[test] - predict(D[test])).abs().numpy().ravel()
inside = err <= q3
box = in_box[test]
print(inside[box].sum(), "of", box.sum(), "in the box,",
inside[~box].sum(), "of", (~box).sum(), "outside")
- Python counts from 0, so the -th smallest residual is
r[k - 1]. - Whether each test run's solver value lies within of the prediction: the observed coverage, counted inside and outside the box. The box is the course’s training box of
split_runs, angle of attack from −2° to 8° and sweep from 20° to 36°.
inf 0.00072 3 of 4 in the box, 1 of 8 outside
Example 7-7 prints an infinite 90 % interval: with eight calibration runs the rank 9 is beyond the last residual. At 80 %, is the largest of the 8 residuals, 0.00072. It covers 3 of the 4 test runs inside the box and 1 of the 8 outside, which are not exchangeable with the calibration runs (below).
Figure 7-2 shows the same procedure on 40 calibration runs of a toy problem, where the intervals and their coverage can be seen at every level.
Does a 95 % band cover the runs beyond x = 1 as well as those inside the training range?
The guarantee: if the new design and the calibration designs are exchangeable (their joint distribution does not change when they are reordered, as when all are drawn independently in the same way), the interval contains the true value with probability at least . With continuous residuals it is also at most :
Both bounds are averages over new designs and calibration sets. No assumption about the model or the noise is needed.
On one calibration set, coverage is itself random: with 40 calibration runs, as in Figure 7-2, it typically lands within about 5 percentage points of the target, which is why the figure can show 96 % for a 90 % target.
Limits of the guarantee:
- Nothing outside the calibration distribution. A design beyond the training range is not exchangeable with the calibration runs, and coverage can collapse, as Figure 7-2 shows. Runs chosen by active learning are not exchangeable with new designs either, so they cannot serve as calibration runs.
- Coverage on average, not for every design. The interval has the same width everywhere; where the error varies across designs, it is too wide in easy regions and too narrow in hard ones. Scaling the residuals by an ensemble's spread gives intervals that adapt.
- One quantity at a time. A whole field needs a conformalised summary (the maximum error, or the error in lift), or a method built for functions (Ma, Azizzadenesheli and Anandkumar 2024).
The next unit uses these error bars for choosing the next simulation where the model is least sure. Winovich et al. (2026) do so on academic 2D PDEs, with an operator network that outputs its own standard deviation in place of an ensemble.