Fourier feature embeddings
Learning objectives
- Build a Fourier-feature layer: sines and cosines of the depth at frequencies drawn once at a scale , a wavelength of
- 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 , and with them Section 0.9's small network learns the column's short wavelengths in Section 0.9's 3000 steps: at , 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 the fit is 0.1 m/s RMS at the training depths and 779 m/s between them.
The Layer
The first layer is fixed: for , with the depth over the book's scale of 1800 m and the frequencies drawn from by the book's generator from one seed. A frequency is a wavelength of , so the scale is a wavelength of : 1800 m at , 180 m at , 18 m at . 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 the band from 125 m to 250 m is 4.2 % missed and the wavelengths shorter than 125 m 41 %; at 0.6 % and 23 %; at 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 the fit is 1.2 m/s RMS at the training depths and 7.6 m/s between them; at 2.8 m/s and 248 m/s; at 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: , 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 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.