A first field surrogate
A network that takes a point and a design and returns the field value at that point.
Outcome: Explain a coordinate network: one point and the design in, the field value out; add Fourier features to a small MLP, and test whether they help on a given dataset; train a neural field on a point-wise table, and know its limits.
Builds on Overfitting and regularisation, Physical fields
So far the networks mapped a design to a few numbers. With the location added to the inputs, a network predicts a field: a neural field (or coordinate network).
DefinitionNeural field
Evaluated at all the surface points of a run with the same and , it gives the pressure on the whole aircraft. Anywhere else on the surface it gives a value too, though no detail finer than the training data and the network can represent.
It trains on the point-wise table: each minibatch is a random set of points from random training runs, and the loss is the mean squared error on . The loop of Example 4-5 applies, with a minibatch of points in place of designs.
Fourier features
A plain MLP tends to learn smooth, slowly varying functions first, its spectral bias (Rahaman et al. 2019), and to struggle with sharp features, such as the suction peak at a wing’s leading edge. A common remedy is to feed it sines and cosines of the coordinates at several frequencies, called Fourier features (Tancik et al. 2020). The network then combines ready-made oscillations instead of building them from scratch. The site uses fixed frequencies doubling at each step (octaves), the positional encoding of Mildenhall et al. 2020. They do not always help: on the download’s runs they lower the error over the surface but not at the suction peaks (an exercise of a first surrogate, end to end).
The site’s model takes as inputs the point’s position (3 values, scaled by 0.25), its surface normal (3), the normalised angle of attack and sweep (2) and 24 Fourier features of the position: 32 numbers. Three hidden layers of 48 SiLU neurons, one output, 6,337 parameters. In the browser the same weights run in a graphics shader, once per vertex, whenever a slider moves.
The site’s network was trained this way on 36 runs: 3,000 steps of 512 surface points, with Adam and the learning rate decaying along a cosine from to , in a loop written in TypeScript so that it can also run in the browser. Targets are clipped to between −3 and 1.2, and the site’s per-design errors are measured against the clipped values.
In Figure 4-4 the curves stay together, ending at an RMSE of 0.057 and 0.058, so this model does not overfit.
Both are high, however: about 16 % of the standard deviation of in the training data (0.36, clipped as in training). This small network underfits, limited by its size and its 3,000 steps: a larger model or longer training is the remedy, and regularisation would likely make it worse.
A neural field like this is small and cheap to evaluate. It can be queried at any point (though a finer query adds no information), and the points are independent, so evaluation parallelises easily on a GPU.
Its limit is the same independence: each point is predicted on its own, without looking at its neighbours. The model knows the geometry only through coordinates and a few design parameters, so it covers one parametric family of shapes and generalises poorly to new ones.
Models that read the geometry itself come next: grids, meshes and point clouds, then neural operators, which generalise the idea of querying any point: the trunk network of DeepONet is a coordinate network of this kind.
Example 4-7 adds the network to aircraft.py, then evaluates it, untrained, on the 2,000 points of the download’s first run.
# Add to aircraft.py, with its other imports at the top:
import math
def fourier(x, octaves=4):
# sin and cos of each coordinate at π, 2π, 4π, 8π.
k = 2.0 ** torch.arange(octaves) * math.pi1
# (..., 3, octaves)
xk = x[..., None] * k2
sc = torch.cat([torch.sin(xk), torch.cos(xk)], dim=-1)
return sc.flatten(-2)3
class NeuralField(nn.Module):
def __init__(self, width=48):
super().__init__()
# 3 + 3 + 2 + 24 = 32 inputs.
n_in = 3 + 3 + 2 + 3 * 2 * 4
self.net = nn.Sequential(
nn.Linear(n_in, width), nn.SiLU(),
nn.Linear(width, width), nn.SiLU(),
nn.Linear(width, width), nn.SiLU(),
nn.Linear(width, 1))
def forward(self, xyz, normal, design):
# One row per point.
f = [xyz, normal, design, fourier(xyz)]
return self.net(torch.cat(f, dim=-1))4
# Then, next to aircraft.py: run 0, all 2,000 points.
import torch
from aircraft import (NeuralField, load_runs, scale_designs,
split_runs)
d = load_runs()
train, _, _, _ = split_runs(d)
Xn, _, _ = scale_designs(d, train)
T = lambda a: torch.tensor(a, dtype=torch.float32)
xyz, normal = T(d["xyz"][0]), T(d["normal"][0])
# The scaling of 4.3, the same design for every point.
design = T(Xn[0]).expand(2000, 2)5
torch.manual_seed(0)
print(NeuralField()(0.25 * xyz, normal, design).shape)
- Broadcasting:
x[..., None]has the shape(…, 3, 1)andkhas the shape(4,), so every coordinate is multiplied by every frequency. flatten(-2)merges the last two axes,(…, 3, 8)into(…, 24): the 24 Fourier features.- All inputs of a point side by side on the last axis: 3 + 3 + 2 + 24 = 32 numbers per row.
expandrepeats the run’s two design values on all 2,000 rows without copying them.
Example 4-7 prints torch.Size([2000, 1]): one per point. The project script of a first surrogate trains this network on 1,024 points per step and tests it.