Putting a surrogate to work
Many cheap evaluations can make design sweeps, uncertainty and sensitivity studies practical.
Outcome: Propagate input scatter through a surrogate by Monte Carlo; rank inputs by their effect with Sobol sensitivity indices.
Builds on Limits and trust
A trained and validated surrogate usually answers in a fraction of the solver's time, often milliseconds for a small scalar model. Reported times for a large model predicting millions of field points run from seconds (AB-UPT, on car aerodynamics) to about three minutes per case (GeoTransolver on the HiLiftAeroML aircraft, as timed in the AeroJEPA paper), plus any time to prepare the geometry. That can make four kinds of work practical:
- Design exploration. A surrogate sweeps far more variants than the solver budget allows, and finds the promising region before the budget is spent.
- Optimisation. The surrogate goes inside an optimiser (optimising on a surrogate). A differentiable surrogate also gives gradients with respect to the design.
- Uncertainty. Manufacturing tolerances or operating scatter are propagated by Monte Carlo, usually far too slow with a solver in the loop.
- Real time. Where the model is fast enough for the use and its inputs stay in the training range: interactive design tools, and digital twins that keep up with sensors on the real asset.
This lesson works through the third on the course’s aircraft, and the sensitivity of the output to each input.
Scatter of the output
Real inputs scatter: the angle of attack varies with gusts and trim, the sweep with manufacturing tolerance. The scatter of the lift in return follows from drawing many input samples from their distributions, evaluating each, and measuring the spread of the outputs. This is Monte Carlo propagation.
The error of a Monte Carlo mean falls as with the number of samples , so a mean and spread usually settle in hundreds to thousands of evaluations. Tail percentiles need far more: the metrology guide JCGM 101:2008 notes that a million samples can often give a 95 % interval whose length is correct to one or two significant digits. For scale, 100,000 samples are about eleven years for a one-hour solver run one at a time, and can be seconds to minutes for a small neural surrogate on a GPU (a graphics processor).
Sensitivity analysis
Sensitivity analysis asks which inputs drive the output's variation over the whole design range. A common measure is the Sobol indices (Sobol’ 2001).
DefinitionSobol indices
The first-order index of an input is the share of the output variance it causes on its own (with inputs that vary independently); the total index adds its interactions with the other inputs.
An input whose total index is near zero over the ranges studied can be fixed at a nominal value without losing much of the variance.
Estimating the indices also takes thousands of evaluations, which a surrogate can make practical. (They are a different tool from the Sobol sequence of sampling, by the same mathematician, though the indices are often estimated with Sobol samples.)
Both on the aircraft
Example 8-1 does both through a Gaussian process of as in Example 3-4, fitted to the 36 training runs of aircraft-runs.npz, the download of Example 2-2. The design point is at and sweep at , each normally distributed with that standard deviation.
import time
import numpy as np
from scipy import stats
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF
from aircraft import load_runs, scale_designs, split_runs
# The surrogate: a GP of CL fitted to the 36 training runs.
d = load_runs()
train, val, test, in_box = split_runs(d)
X, mu, sd = scale_designs(d, train)1
# Length scales between 0.05 and 100 standard deviations.
gp = GaussianProcessRegressor(1.0 * RBF([1.0, 1.0], (0.05, 100.0)),
alpha=1e-6, normalize_y=True)2
gp.fit(X[train], d["CL"][train])
def surrogate(alpha, sweep):
return gp.predict((np.c_[alpha, sweep] - mu) / sd)
# Monte Carlo: how much does CL scatter when alpha and
# sweep vary a little around a design point?
rng = np.random.default_rng(0)
t = time.perf_counter()
alpha = rng.normal(4.0, 0.3, 100_000) # flight scatter
sweep = rng.normal(28.0, 0.5, 100_000) # tolerance
cl = surrogate(alpha, sweep)3
dt = time.perf_counter() - t
print(f"CL = {cl.mean():.3f} +/- {cl.std():.3f}, "
f"95 % above {np.quantile(cl, 0.05):.3f} "
f"({dt:.2f} s)")
# Sobol indices: which input drives the variance of CL
# over the whole design box? SciPy passes the samples as
# columns: x[0] is every alpha, x[1] every sweep.
res = stats.sobol_indices(
func=lambda x: surrogate(x[0], x[1]),
n=2**14,4
# alpha uniform in [-2, 8], sweep in [20, 36]
dists=[stats.uniform(-2, 10), stats.uniform(20, 16)],5
# rng= needs SciPy 1.15+; older versions: random_state=.
rng=rng,
)
print("first order", res.first_order.round(3))
print("total", res.total_order.round(3))
- Both inputs are standardised as in Example 4-5, so one starting length scale suits both;
surrogateapplies the same scaling. - This
alphais scikit-learn’s small value added to the kernel’s diagonal for numerical stability, not the angle of attack. - One call evaluates all 100,000 samples at once, as arrays: the surrogate is vectorised.
nmust be a power of 2. The function is evaluated times for inputs, here 65,536.stats.uniformtakes a start and a width, not the two ends:uniform(-2, 10)covers [−2, 8].
Example 8-1 prints CL = 0.457 +/- 0.024, 95 % above 0.418, the mean, the standard deviation and the 5th percentile of the samples, and its timing, a fraction of a second on a laptop. The solver’s own run at , (test run 46 of the download) gives at the centre.
The Sobol lines print first order [0.998 0.001] and total [0.999 0.002]: over the whole design box, explains about 99.8 % of the variance of and sweep about 0.1 % (Equation 8-1).
That compares the two ranges, not the two inputs: ’s wide range dominates, yet at fixed going from 20° to 36° of sweep still lowers the surrogate’s by about 8 %, from 0.470 to 0.434.