Testing on unseen designs

Surrogate against solver on designs the network never saw, inside and outside the training range.

Outcome: Compare surrogate and solver field by field on unseen designs; report the relative L2 error per design and where the error sits; measure how the error grows as a design leaves the training box; test a model without a solver: transform a case, undo the change on the output, compare.

Builds on A first field surrogate, Measuring error

Testing compares the surrogate with the solver on designs it was not trained on, field by field, not just on integrated numbers. The metrics of measuring error are reported per design: the RMSE over the surface, the largest local error, and the relative L2 error ∥y^−y∥/∥y∥\lVert \hat{y} - y \rVert / \lVert y \rVert, the number many papers quote.

A single average over all designs would hide that some are predicted far worse than others.

The test grid of Figure 4-5 has 45 designs over angle of attack and wing sweep, each run through both the surrogate and the solver. The training box is marked on each slider.

Cp -1.5 (suction)+1
Figure 4-5. Pressure on the aircraft at α 4°, sweep 28°: the surrogate’s Cp. Set the design and the view with the controls below.
Cp -1.5+1

Inside the training range: interpolation. RMSE over the surface 0.052 in CpC_p, largest ∣ΔCp∣|\Delta C_p| 0.72, relative L2 13.0 % along the cut at 40 % span.

-101200.51
solver surrogate−Cp (up) against chord position x/c · 40% span

−Cp-C_p along the chord at 40 % span, solver against surrogate: suction points up. Each line runs over the upper and lower surface, and the area inside the solver’s loop is close to the section’s lift.

At α\alpha 4°, Λ\Lambda 28°, in the middle of the training box, the surface RMSE is 0.052. At α\alpha 12°, Λ\Lambda 40°, outside both ranges, it is 0.210, about 4 times larger. Inside the box the model interpolates; outside, it extrapolates without warning. The error rises as α\alpha steps up from 8°, and the Error view shows it largest at the leading-edge suction peak and the wing tips, where CpC_p changes fastest.

Even in the middle of the training box, this small network is off by about 13 % (relative L2 error along the cut), the underfitting of Figure 4-4. A classical baseline does far better on these runs (see a first surrogate, end to end). The site keeps the network because it is small enough to explain and to run in the browser.

Errors against distance

The same test fits in a few lines for a scalar. Example 4-8 loads the network that Example 4-5 saved and prints one row per test run of the download, sorted by the distance to the nearest training run.

Example 4-8. Errors per test run against the distance to the training runs, in PyTorch
import numpy as np
import torch
from aircraft import MLP, load_runs, split_runs

d = load_runs()
train, val, test, in_box = split_runs(d)
X = np.column_stack([d["alpha"], d["sweep"]])
CL = d["CL"]
# The MLP and the scaling saved by the loop of 4.3.
ck = torch.load("cl_mlp.pt")1
model = MLP()
model.load_state_dict(ck["model"])
model.eval()
Xn = (X - np.array(ck["mu"])) / np.array(ck["sd"])
with torch.no_grad():
    out = model(torch.tensor(Xn, dtype=torch.float32))
pred = out.numpy()[:, 0] * ck["ys"] + ck["ym"]2

# Distance from each run to the nearest training run,
# in the standardised inputs.
diff = Xn[:, None, :] - Xn[None, train, :]
dist = np.linalg.norm(diff, axis=-1).min(axis=1)3
print("alpha sweep  box   CL    pred  |dCL|  dist")
for i in test[np.argsort(dist[test])]:4
    box = "in " if in_box[i] else "out"
    print(f"{X[i, 0]:5.0f} {X[i, 1]:5.0f}  {box} "
          f"{CL[i]:6.3f} {pred[i]:6.3f} "
          f"{abs(pred[i] - CL[i]):.3f} {dist[i]:5.2f}")
  1. The file of Example 4-5: the weights, and the statistics needed to scale a new design the same way.
  2. Back from standardised units to CLC_L.
  3. Broadcasting gives a (56, 36) table of distances from every run to every training run; min(axis=1) keeps the nearest. The distance is in the standardised inputs of Equation 4-5, so a degree of α\alpha and a degree of Λ\Lambda count by their spread in the training runs.
  4. The 12 test runs, nearest first.
Table 4-1. What Example 4-8 prints: the 12 test runs of the download, nearest to the training runs first, with the solver’s CLC_L, the network’s, and the distance in standardised inputs. The first four lie inside the training box.
α\alpha (°)Λ\Lambda (°)solvernetwork∣ΔCL∣|\Delta C_L|distance
0220.1430.1430.0000.23
2340.2880.2880.0000.27
4280.4570.4570.0000.39
8220.7900.7850.0050.53
10280.9270.9220.0050.83
-428-0.177-0.1780.0010.87
4160.4740.4730.0011.02
4400.4190.4210.0021.17
10220.9500.9330.0161.25
-416-0.186-0.1920.0061.43
12281.0821.0700.0111.54
12400.9901.0140.0231.77

Example 4-8 prints the rows of Table 4-1. The four runs inside the box are within 0.005 of the solver. Outside it the error grows, unevenly, with the distance: 0.001 to 0.005 for the four nearest, 0.006 to 0.023 for the three farthest. The network prints its number for α\alpha 12°, Λ\Lambda 40° as readily as for 4°, 28°. The distance in the last column is known before the solver runs, and limits and trust builds on it. Public benchmarks build the same distinction into their test sets: AirfRANS has separate tasks for interpolation and for extrapolation in Reynolds number and in angle of attack.

The solver is itself idealised: inviscid, with no stall, so at α\alpha 10° to 12° the test compares two predictions, and a real wing may be near stall there, where neither can follow it.

Tests that need no solver

Every test so far needed solver runs to compare with. A second kind needs none. Transform a case in a way whose effect on the answer is known, predict, undo the transformation on the output, and compare with the prediction on the original case. Software testing calls this metamorphic testing (Chen et al. 2018). For a flow surrogate the known relations come from the physics:

  • Rotate and translate the whole problem, free stream, gravity and ground included: pressures stay the same and velocities turn with the frame (symmetries).
  • Change the units, or scale every length and the speed so that the Reynolds number stays the same: CpC_p at corresponding points is unchanged, for a compressible flow if the Mach number is kept too (physical fields).
  • Reorder the points: nothing should change. Refine the mesh: the field at a given place should change no more than the solver’s own solution does.

Rotating the body under a fixed free stream is not one of these tests: it poses a different problem, and the answer should change. No floating-point result is exactly unchanged, so compare the change with the one caused by perturbing the inputs at rounding level. A model can pass every one of these tests and still be inaccurate: they check that its answers are consistent with each other, and only held-out solver runs measure its error (train, validation and test).

The surrogate’s main limit is the one the neural field lesson named: it knows one family of shapes. Limits and trust covers what to check before a surrogate is used for decisions; the next lesson builds one end to end.

Check yourself

  1. 1One relative L2 averaged over all test designs is reported. What can that single number hide?
  2. 2The training box is α −2° to 8°, Λ 20° to 36°. A test design has α 9°, Λ 30°. What kind of test is it?
  3. 3At α 10° to 12° the site compares its surrogate with its solver. Why is even the solver’s answer doubtful there?
Every length of a case is doubled and its free-stream speed halved, with the same fluid. Should the predicted Cp field change?

No. Re = ρVL/μ is unchanged (2L × V/2), so by dynamic similarity the Cp field at corresponding points is the same. A model whose prediction changes fails this test.

Why rotate the free stream with the body in this test, and not the body alone?

Rotating the body against a fixed free stream poses a different problem, whose answer should change. Rotating both is the same problem in another frame, so the prediction, rotated back, should not change.

Go further