Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Why networks learn the big picture first
When a neural network learns a curve, it gets the broad shape right first and the small wiggles much later, sometimes never. This is called spectral bias. For a physics problem the wiggles can be the important part: a small ripple in a solution can carry a large share of its curvature. One fix is to give the network waves as inputs, sines and cosines of the position, so wiggles are easy to build. A second difficulty is that a PINN’s loss has several parts, the equation and the edges, and one part can drown out the other unless we weigh them well. The demo shows a network fitting a wiggly solution with and without wave inputs.
Neural fields that store 3D scenes, such as NeRF, rely on the same Fourier-feature trick to capture sharp edges and fine texture.
- 1. Spectral bias means networks learn…
- 2. Fourier features give the network…
- 3. Loss balancing is about…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Spectral bias (Rahaman et al., 2019): networks trained by gradient descent fit low-frequency components of a target first; high frequencies converge much more slowly.
- Neural tangent kernel (NTK): for small learning rates the network’s outputs evolve as du/dt = −K(u − y) with K = J Jᵀ (B4-5). An error component along an eigenvector of K with eigenvalue κ decays like e^(−κt). For tanh and ReLU networks the large eigenvalues belong to smooth functions.
- Fourier features (Tancik et al., 2020): replace x by γ(x) = [cos 2πBx, sin 2πBx] with random B ~ N(0, σ²). The scale σ sets which frequencies are easy; too large a σ produces noisy fits, especially for PINNs whose residuals contain (2πB)² from second derivatives.
- PINN-specific stiffness: the residual involves u″, so a component a·sin kπx contributes a(kπ)² to it; fine scales dominate the residual while being slow to learn.
- Loss balancing:
- Learning-rate annealing (Wang, Teng and Perdikaris, 2021): λ ← αλ + (1 − α)·max|∇L_r| / mean|∇L_b|.
- NTK weights (Wang, Yu and Perdikaris, 2022): weights from the traces of the NTK blocks of each term.
- Others: SoftAdapt, ReLoBRaLo, self-adaptive per-point weights (McClenny and Braga-Neto, 2023), or non-dimensionalising so all terms are of order 1.
- 1. Under the NTK picture, an error along an eigenvector with eigenvalue κ decays like…
- 2. Fourier features sample B from…
- 3. A component a·sin kπx contributes to u″ a term of size…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Measuring spectral bias
Exercise 1.
- Plain and Fourier-feature encodings and the Jacobian of a one-layer tanh network.
- The empirical NTK K = J Jᵀ and the Rayleigh quotient vᵀKv/vᵀv as the learning speed of an error shape v.
- The sine coefficient of an error and the adaptive λ update.
Practice.
- Look at the error, not only the loss: plot the error’s spectrum; a stalled high-frequency part is the signature of spectral bias.
- Choose σ from the physics: frequencies up to the finest scale you expect; try two or three values. With second-order PDEs, prefer a modest σ.
- Non-dimensionalise first: many balancing problems disappear when the equation and boundary terms are of order 1.
- Sweep λ over decades and log both terms; adaptive rules are a starting point, not a guarantee — check λ’s history.
- Other remedies: sine activations (SIREN), multi-scale or multi-stage training, curriculum over the frequency or coefficient, second-order optimisers (J2-1).
- Tools: PirateNets and jaxpi (Wang et al.) bundle Fourier features, adaptive weights and causal training; DeepXDE supports feature transforms and loss weights.
import torch
class FourierPINN(torch.nn.Module):
def __init__(self, m=8, sigma=1.0, width=32):
super().__init__()
self.register_buffer("B", sigma * torch.randn(1, m)) # fixed random frequencies
self.net = torch.nn.Sequential(torch.nn.Linear(2 * m, width), torch.nn.Tanh(), torch.nn.Linear(width, 1))
def forward(self, x):
z = 2 * torch.pi * x @ self.B
return self.net(torch.cat([torch.cos(z), torch.sin(z)], dim=-1))- 1. A stalled high-frequency part of the error indicates…
- 2. SIREN networks use…
- 3. Before tuning λ, it helps to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Training dynamics in the kernel regime. With gradient flow on L = ½‖u − y‖², the outputs obey du/dt = −J Jᵀ (u − y) = −K(u − y). Writing the error in the eigenvectors of K, each component decays at its own rate κ_i. In Exercise 1 the plain network’s kernel reduced an error shaped like sin πx 294 times faster than one shaped like sin 8πx. With Fourier features of scale σ = 2 the ratio was 10; with σ = 1 it was 152, so σ has to reach the frequencies in the solution.
Why Fourier features work. With γ(x) = [cos 2πBx, sin 2πBx], the kernel becomes approximately stationary, K(x, x′) ≈ k(x − x′), and its spectrum is shaped by the distribution of B. Frequencies near |B| get large eigenvalues and are learned fast. The cost: the network now finds high-frequency fits easy, so with too few collocation points or too large σ it can fit noise or satisfy the residual with wiggles.
Balancing terms. L = L_r + λL_b. If ∇L_r is much larger than ∇L_b, a first-order optimiser follows the residual and neglects the boundary; the learning-rate-annealing rule raises λ until max|∇L_r| ≈ λ·mean|∇L_b|. That compares a maximum with a mean, so it tends to overshoot: in Exercise 2 it raised λ to 20 000–300 000, where the boundary term dominated and the residual was poorly fitted (error 0.1). Of the fixed values λ = 1, 100 and 10 000, λ = 100 was best for the Fourier PINN. Rules based on the NTK or on the loss values behave differently; none removes the need to look at both terms.
- 1. In the kernel regime, du/dt equals…
- 2. Fourier features make the NTK approximately…
- 3. The max/mean λ rule tends to…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much do Fourier features and adaptive loss weights help a PINN with a fine-scale solution?
History.
- N. Rahaman et al. (2019) documented spectral bias; A. Jacot, F. Gabriel and C. Hongler (2018) introduced the neural tangent kernel that explains it.
- M. Tancik et al. (2020), “Fourier features let networks learn high frequency functions in low dimensional domains”, and V. Sitzmann et al. (2020), SIREN, made high-frequency neural fields practical.
- S. Wang, Y. Teng and P. Perdikaris (2021) diagnosed unbalanced gradients in PINNs and proposed learning-rate annealing; S. Wang, H. Wang and P. Perdikaris (2021) applied Fourier features to multi-scale PDEs; S. Wang, X. Yu and P. Perdikaris (2022) analysed PINNs with the NTK.
- A. Krishnapriyan et al. (2021) showed failure modes on convection and reaction problems and proposed curriculum training.
Exercise 2. Exact solution sin πx + 0.1 sin 8πx on [0, 1] with zero boundary values. Networks: one tanh layer of width 32 on the plain input or on 8 Fourier features (B ~ N(0, 1)). Regression: Adam on 128 points, error amplitudes of the slow and fast parts. PINN: 64 collocation points, Adam 2000 steps with a decaying learning rate, relative L2 error. Values rounded to one significant figure.
| regression error, slow / fast part | 100 steps | 500 steps | 2000 steps |
|---|---|---|---|
| plain | 0.1 / 0.1 | 0.001 / 0.09 | below 0.0001 / 0.09 |
| Fourier features | 0.0008 / 0.009 | below 0.0001 / below 0.0001 | below 0.0001 / below 0.0001 |
| PINN error | λ = 1 | λ = 100 | λ = 10 000 | adaptive |
|---|---|---|---|---|
| plain | 0.09 | 0.09 | 0.2 | 0.1 (λ ≈ 20 000) |
| Fourier features | 0.03 | 0.0001 | 0.001 | 0.1 (λ ≈ 300 000) |
- Spectral bias is real and large. The plain network’s fine-scale error barely moved from 0.1 to 0.09 in 2000 steps while the smooth part converged. Its NTK learned sin πx 294 times faster than sin 8πx.
- Fourier features fixed it in regression and gave a PINN 900 times more accurate with the same budget.
- λ matters as much as the features. With λ = 1 the boundary was too weak (error 0.03); with 10 000 the residual suffered (0.001).
- The adaptive rule overshot. It raised λ far beyond the best value and gave errors of 0.1. An adaptive rule must be checked like any other hyperparameter.
- σ must fit the problem. With σ = 2 the NTK gap shrank further, but on seed 2 the Fourier PINN failed (error 0.4 at λ = 100), whereas σ = 1 gave 0.0005.
- Seeds 1 and 2: plain PINN with λ = 100 0.03 and 0.04; Fourier with λ = 100 0.0001 and 0.0005; adaptive λ about 200 000 and 20 000 (plain), 600 000 and 400 000 (Fourier), with errors 0.4, 0.2 (plain) and 0.1, 0.03 (Fourier).
Spectral bias and loss balancing in practice
- Turbulence and boundary layers: fine scales matter most; multi-scale Fourier features and sequential training in time are used for Navier–Stokes PINNs.
- Neural fields: NeRF and signed-distance networks for 3D shapes use positional encoding (Fourier features) to capture detail; the same encodings are used to represent fields in weather and medical imaging.
- Multi-physics: coupled equations with different units make balancing essential; non-dimensionalisation and per-equation adaptive weights are standard.
- Operator learning: Fourier neural operators (J4-3) work directly in frequency space, avoiding much of the spectral bias of pointwise networks.
References
- N. Rahaman et al. (2019). “On the spectral bias of neural networks.” ICML.
- A. Jacot, F. Gabriel and C. Hongler (2018). “Neural tangent kernel: convergence and generalization in neural networks.” NeurIPS.
- M. Tancik et al. (2020). “Fourier features let networks learn high frequency functions in low dimensional domains.” NeurIPS.
- S. Wang, Y. Teng and P. Perdikaris (2021). “Understanding and mitigating gradient flow pathologies in physics-informed neural networks.” SIAM Journal on Scientific Computing.
- S. Wang, X. Yu and P. Perdikaris (2022). “When and why PINNs fail to train: a neural tangent kernel perspective.” Journal of Computational Physics.
- A. Krishnapriyan et al. (2021). “Characterizing possible failure modes in physics-informed neural networks.” NeurIPS.