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 1/N1/\sqrt{N} with the number of samples NN, 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.

Si=Var⁡(E[Y∣Xi])Var⁡(Y)ST,i=E[Var⁡(Y∣X∼i)]Var⁡(Y)\begin{aligned} S_i &= \frac{\operatorname{Var}\big(\mathbb{E}[Y \mid X_i]\big)}{\operatorname{Var}(Y)} \\[6pt] S_{T,i} &= \frac{\mathbb{E}\big[\operatorname{Var}(Y \mid X_{\sim i})\big]}{\operatorname{Var}(Y)} \end{aligned}
(8-1)
YY is the output, XiX_i input ii, and X∼iX_{\sim i} all the inputs except XiX_i.

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 CLC_L 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 α\alpha at 4.0∘±0.3∘4.0^\circ \pm 0.3^\circ and sweep at 28.0∘±0.5∘28.0^\circ \pm 0.5^\circ, each normally distributed with that standard deviation.

Example 8-1. Monte Carlo and Sobol indices through a Gaussian process of the aircraft’s lift, with NumPy, SciPy and scikit-learn
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))
  1. Both inputs are standardised as in Example 4-5, so one starting length scale suits both; surrogate applies the same scaling.
  2. This alpha is scikit-learn’s small value added to the kernel’s diagonal for numerical stability, not the angle of attack.
  3. One call evaluates all 100,000 samples at once, as arrays: the surrogate is vectorised.
  4. n must be a power of 2. The function is evaluated n(d+2)n(d + 2) times for dd inputs, here 65,536.
  5. stats.uniform takes 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 α=4∘\alpha = 4^\circ, Λ=28∘\Lambda = 28^\circ (test run 46 of the download) gives CL=0.457C_L = 0.457 at the centre.

The Sobol lines print first order [0.998 0.001] and total [0.999 0.002]: over the whole design box, α\alpha explains about 99.8 % of the variance of CLC_L and sweep about 0.1 % (Equation 8-1).

That compares the two ranges, not the two inputs: α\alpha’s wide range dominates, yet at fixed α=4∘\alpha = 4^\circ going from 20° to 36° of sweep still lowers the surrogate’s CLC_L by about 8 %, from 0.470 to 0.434.

Check yourself

  1. 1Monte Carlo through the surrogate gives a CL scatter of ± 0.01. The surrogate’s validation error in CL is 0.02. What follows?
  2. 2An input’s first-order Sobol index is near zero, but its total index is large. Can it be fixed at a nominal value?
  3. 3The sampled manufacturing tolerance extends beyond the surrogate’s training range. What do the Monte Carlo statistics describe?
Why is Monte Carlo with 100,000 samples practical with a small surrogate and not with the solver?

A small surrogate’s call can take microseconds to milliseconds, so 10⁵ samples take seconds to minutes. A large field model at 10 s per design would need about 12 days. With a solver at an hour per run, one at a time, it would take over eleven years.

A first-order Sobol index of 0.9 for α means what?

About 90 % of the output variance over the chosen input ranges comes from α acting alone.

Exercises

  1. Exercise 8-1. After the Monte Carlo of the lesson’s listing, compute the GP’s RMSE on the 8 validation runs (split == 1). Is the spread of CL larger than that error, and what does the Watch out of the lesson then say about the result?

    Answer

    The listing’s GP is off by about 3 × 10⁻⁵ in RMSE on the validation runs (largest error about 4 × 10⁻⁵), far below the spread of ± 0.024, so the spread is resolved. The Watch out still asks for the slopes to be checked against the solver at a few designs, since the validation error does not measure them.

Go further