Fourier Neural Operator (FNO)¶
One of the most popular neural operator architectures is the Fourier
Neural Operator, or FNO. This notebook demonstrates the use of FourierLayer
and
FourierNeuralOperator
in continuiti.
The FNO architecture was proposed in Z. Li et al., 2020 and gained a lot of attention because it is computationally very efficient. However, due to the Fast Fourier Transform (FFT) being used, it is in general restricted to simple geometries like rectangles.
1D¶
Let's start with a simple one-dimensional function training a single FourierLayer
on it.
# Input function
u_func = lambda x: torch.exp(-x**2)*10
# Target function
v_func = lambda y: torch.exp(-y**2)*2*10 * (-y)
def get_equidistant(N):
return torch.arange(-N/2, N/2) / N * torch.pi * 2
num_sensors = 31
num_evaluations = 31
x = get_equidistant(num_sensors)
y = get_equidistant(num_evaluations)
u = u_func(x)
v = v_func(y)
Dataset¶
Fourier Layer¶
We instantiate the Fourier layer with the shapes determined by the dataset.
Training¶
We can evaluate the trained FourierLayer
with any other resolution, e.g., to
plot the output function an a finer resolution.
Modes¶
In the same way as the FourierLayer
allows you to change the number of
evaluation points of \(y\) for each forward pass, the dimensionality of the input
\(u\) can also be changed.
In the case of \(u\) being larger than what was specified during initialization,
the FourierLayer
removes the high frequencies (or modes). In case
\(u\) is smaller, zero-values large frequencies are added.
Per default, the Fourier layer considers as many modes as are suggested by
the shapes.u.num
parameter. However, it can be set to any other value and
determines the number of weights in the layer.
2D¶
The FourierLayer also works on multi-dimensional data and we demonstrate
these capabilities along with the multi-layer FourierNeuralOperator
(FNO) in
the following.
Note
The definitions of multivariate_normal_2d
and double_multivariate_normal_2d
are hidden for readability, but both functions are visualized below.
Dataset¶
Fourier Neural Operator¶
Let's use an FNO! It contains depth
many FourierLayers
with a latent
dimension of width
.
Training¶
Created: 2024-08-20