Auto-differentiation as a computational graph
Learning objectives
- Run the chain rule forwards through a network's graph, each node carrying its value and its first and second derivatives with respect to the input
- Read the slope and curvature of the column's fit at a depth, exact to rounding, in m/s per metre and per square metre
- Measure a central difference's error against its step and name its two sources, truncation and rounding
- Say why a PINN takes its residual's derivatives by automatic differentiation and not by differences, and what forward mode costs with more inputs
Derivatives Carried Forward
A PINN's loss holds derivatives of the network with respect to its inputs: the wave equation needs and . Forward-mode automatic differentiation gets them exactly, by carrying beside each node's value its first and second derivatives with respect to the input, through the same graph in the same pass: the chain rule applied forwards. On the book's 1-4-4-1 fit of the Marmousi column at 700 m it gives the fit's slope, 0.667 m/s per metre, and its curvature, 0.000996 m/s per square metre, exact to rounding. A central difference of the curvature is at best off, at a step of 0.1 m only, and at a step of 1 mm it is off.
The Graph and Its Tangents
Each node of the network computes and . Differentiating both with respect to the input , the depth over 1800 m, gives the rules forward mode follows,
starting from at the input. Each node now carries three numbers instead of one, and the output's three are , and . Baydin et al. (2018) describe forward mode as evaluating the function on dual numbers, truncated Taylor series with ; carrying the second derivative is the same idea taken one order further. Plate (a) shows what each node of the network carries at the chosen depth. The network's velocity is with = 1500 m/s, so and with = 1800 m.
What a Difference Can Do
A central difference, , needs only three values of the network, but it has two errors. Its truncation error, the higher derivatives it ignores, falls as : at 700 m a step of 100 m misses the curvature by and the slope by . Its rounding error grows as , with double precision's rounding unit, because the three values agree in nearly all their digits: at a step of 1 mm the curvature is off. The best step balances the two, 0.1 m for the curvature, off, and 1 cm for the slope, off, and the best step moves with the depth. Baydin et al. (2018) call numerical approximations of derivatives inherently ill-conditioned and unstable, for these two reasons.
What It Costs
Forward mode carries one channel for each derivative it is asked for. With one input that is three numbers a node: the value, the slope and the curvature. The 1D wave of Part 1 has two inputs, depth and time, and its residual needs and ; the book's kernel carries the value, the two first derivatives and the three second derivatives, the mixed among them, six numbers a node, and ten for the 2D wave's three inputs. Baydin et al. (2018) give the general rule: forward mode computes the full Jacobian of a function of inputs in evaluations, one for each input, which suits a network with few inputs, while backpropagation (Section 0.6) suits a loss with many parameters and one output. A PINN uses both: forward mode for the derivatives in its inputs, then reverse mode back through them for its parameters.
What Comes Next
Section 0.8 puts the gradients to work: four optimisers train one network on the column, step by step.
References
- Baydin, A. G., Pearlmutter, B. A., Radul, A. A. and Siskind, J. M. (2018). Automatic differentiation in machine learning: a survey. arXiv:1502.05767.