Activation functions and inductive bias

Part 0, Neural networks from absolute zero

Learning objectives

  • Name four activations (tanh, sine, swish, ReLU) and draw each with its first and second derivatives
  • Say how a network's second derivative is built from its activation's, by the chain rule
  • Explain why a ReLU network's second derivative is zero almost everywhere, and what that does to a wave equation's residual
  • Read the fits and the curvatures of four networks that differ only in their activation

The Activation Decides the Curvature

The activation is the one part of a neuron chosen before training, and it decides what the network's derivatives can be. For a fit almost any activation will do: two layers of 16 trained in the same way on the Marmousi2 column miss by 106 m/s RMS with tanh, 108 m/s with sine, 126 m/s with ReLU and 221 m/s with swish. A PINN asks more, because a wave equation's residual is built from the network's second derivatives, and those are made of the activation's. ReLU's second derivative is zero wherever it is defined, so the ReLU network's curvature is exactly zero at all 351 depths the kernel evaluates: a residual built on uzzu_{zz} would see nothing of it. The smooth activations have curvature to give.

Activations And CurvatureInteractive figure, enable JavaScript to interact.

Four Activations

Plate (a) draws each activation with its slope and its curvature. tanh⁑z\tanh z squashes to Β±1\pm 1 and its second derivative, βˆ’2tanh⁑z (1βˆ’tanh⁑2z)-2\tanh z\,(1 - \tanh^2 z), is a smooth wave either side of zero. sin⁑z\sin z never saturates; its second derivative is βˆ’sin⁑z-\sin z. Swish, z/(1+eβˆ’z)z/(1 + e^{-z}), is a smoothed ReLU, curved near zero. ReLU, max⁑(0,z)\max(0, z), is a corner: slope 0 then 1, and second derivative 0 everywhere but at the corner, where it is not defined. Goodfellow, Bengio and Courville (2016) call ReLU the default recommendation for modern feedforward networks, because it is so close to linear that it is easy to optimise. That closeness is what a PINN cannot use.

Four Networks

The four networks are the same: two layers of 16 (321 parameters), the same seed's Glorot start, Adam at a rate of 0.01 for 3000 steps at the column's depths every 10 m, the tanh one the book's training table's and the other three its group for Sections 0.1 to 0.5. Only the activation differs. The sine network has Glorot's start, not the special start of a SIREN (Part 2). The column is the window at x = 3600 m of the Marmousi2 model, a 2D acoustic, constant-density slice of a synthetic model, not field data; the choices are the book's own.

The Chain Rule Carries the Curvature

For one hidden layer, c(x)=k+βˆ‘jaj σ(wjx+bj)c(x) = k + \sum_j a_j\,\sigma(w_j x + b_j) with c=v/V0c = v/V_0 and x=z/Lx = z/L, and the chain rule gives

d2cdx2=βˆ‘jaj wj2 σ′′(wjx+bj).\frac{d^2 c}{dx^2} = \sum_j a_j\,w_j^2\,\sigma''(w_j x + b_j).

Each term is the activation's curvature at that neuron's score: a network inherits its activation's second derivative. With ReLU every term is zero away from the corners, and a deeper ReLU network is still straight between them. Plate (c) shows the network's d2c/dx2d^2 c/dx^2 along depth, computed exactly by the kernel's forward mode (Section 0.7), not by differences: its RMS is 56 for tanh, 52 for sine, 5.5 for swish and 0 for ReLU, in the network's own units. The tanh network curves hardest at 1490 m, where its fit bends round the column's largest step.

Why a PINN Cares

Part 1 trains a network u(z,t)u(z, t) on the 1D wave equation's residual uttβˆ’c(z)2uzzu_{tt} - c(z)^2 u_{zz} at many points. A ReLU network's uzzu_{zz} and uttu_{tt} are zero almost everywhere, so the residual reduces to zero minus zero wherever it is evaluated, whatever the network does, and the physics term cannot steer it. Sitzmann et al. (2020) proposed periodic activations, SIRENs, for networks that must represent fine detail and its derivatives, and applied them to Poisson, Helmholtz, wave and eikonal equations. The smooth activations, tanh above all and sine with the right start, are the PINN literature's usual choice.

What Comes Next

Section 0.4 goes back to Section 0.1's one neuron and maps the loss its training walks on.

References

  • Goodfellow, I., Bengio, Y. and Courville, A. (2016). Deep Learning, Chapter 6, Deep feedforward networks. MIT Press.
  • Sitzmann, V., Martel, J. N. P., Bergman, A. W., Lindell, D. B. and Wetzstein, G. (2020). Implicit neural representations with periodic activation functions. arXiv:2006.09661.

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