Fourier feature embeddings

Part 2, Architectures for PINNs

Learning objectives

  • Build a Fourier-feature layer: sines and cosines of the depth at frequencies drawn once at a scale σ\sigma, a wavelength of L/σL/\sigma
  • Show that with it Section 0.9's network misses 0.6 % of the band from 125 m to 250 m in Section 0.9's 3000 steps, where it missed 83 %
  • Read a fit at the depths between its training depths and see a too-large scale ring there
  • Choose the scale by the error between the samples

Sines at a Scale

Fourier features hand a network sines and cosines of its input at frequencies drawn once from a normal distribution of spread σ\sigma, and with them Section 0.9's small network learns the column's short wavelengths in Section 0.9's 3000 steps: at σ=3\sigma = 3, a wavelength of 600 m, it misses 0.6 % of the band from 125 m to 250 m, where the plain network missed 83 %, and is 5.9 m/s RMS from the column against 106 m/s. The scale is a dial with a failure at each end. Too small a scale leaves the spectral bias; too large a one fits the training depths to a few metres per second and rings between them: at σ=100\sigma = 100 the fit is 0.1 m/s RMS at the training depths and 779 m/s between them.

Fourier Features ScaleInteractive figure, enable JavaScript to interact.

The Layer

The first layer is fixed: γ(z^)=[sin⁡2πbjz^,cos⁡2πbjz^]\gamma(\hat z) = [\sin 2\pi b_j \hat z, \cos 2\pi b_j \hat z] for j=1,…,16j = 1, \ldots, 16, with z^=z/L\hat z = z/L the depth over the book's scale of 1800 m and the frequencies bjb_j drawn from N(0,σ2)N(0, \sigma^2) by the book's generator from one seed. A frequency bjb_j is a wavelength of L/∣bj∣L/|b_j|, so the scale is a wavelength of L/σL/\sigma: 1800 m at σ=1\sigma = 1, 180 m at σ=10\sigma = 10, 18 m at σ=100\sigma = 100. Behind it are Section 0.9's two tanh layers of 16, its seed and its 3000 Adam steps; the layer adds 496 parameters, 817 in all, and its frequencies are not trained.

Too Small, Too Large

At σ=1\sigma = 1 the band from 125 m to 250 m is 4.2 % missed and the wavelengths shorter than 125 m 41 %; at σ=3\sigma = 3 0.6 % and 23 %; at σ=10\sigma = 10 0.6 % and 21 %. Past that the fit comes apart between the samples. The column is trained at 176 depths every 10 m and read at 351 every 5 m, so every other depth read is one the network never saw. At σ=10\sigma = 10 the fit is 1.2 m/s RMS at the training depths and 7.6 m/s between them; at σ=30\sigma = 30 2.8 m/s and 248 m/s; at σ=100\sigma = 100 0.1 m/s and 779 m/s. The shortest sines at the last two scales, 23 m and 7 m, are near or under twice the samples' spacing: between two samples nothing says where such a sine goes.

Choosing the Scale

The book picks the scale whose fit is closest to the column between the training depths: σ=3\sigma = 3, 4.7 m/s RMS there and 7.0 m/s at them. That is a rule for any embedding: choose the scale for the wavelengths the data can hold, and score it where the network was not trained. Rahaman et al. (2019) showed networks biased towards low frequency functions; a Fourier layer hands the network short wavelengths from its first step, and the samples decide how short is safe. Tancik et al. (2020) introduced the mapping: it lets a network learn high frequency functions in low-dimensional domains, and by neural tangent kernel theory it makes the network's effective kernel stationary with a bandwidth that can be tuned, as σ\sigma is tuned here.

What Comes Next

Section 2.3 puts the sines inside the network instead: SIREN, whose every layer is a sine and whose first layer's frequencies are set by its initialisation.

References

  • Rahaman, N., Baratin, A., Arpit, D., Draxler, F., Lin, M., Hamprecht, F. A., Bengio, Y. and Courville, A. (2019). On the spectral bias of neural networks. arXiv:1806.08734.
  • Tancik, M., Srinivasan, P. P., Mildenhall, B., Fridovich-Keil, S., Raghavan, N., Singhal, U., Ramamoorthi, R., Barron, J. T. and Ng, R. (2020). Fourier features let networks learn high frequency functions in low dimensional domains. arXiv:2006.10739.

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.