5.6.8 · D4Machine Learning (Aerospace Applications)

Exercises — Backpropagation — chain rule, gradient computation

2,422 words11 min readBack to topic

Throughout, one tiny scalar network is reused so the numbers stay checkable:

Here is the input number, is the target (the "right answer" we wanted), (read "y-hat") is the network's guess, and is the loss — a single number measuring how wrong the guess is. The letters (weights) and (biases) are the tunable knobs. The symbol (read "sigma") is the activation function, a bend applied to a number; is its slope at . The Greek (read "delta") is the error signal at a node: , i.e. "how much the loss changes if this node's pre-activation value nudges."

Figure — Backpropagation — chain rule, gradient computation

Look at the figure above: the orange arrows run left-to-right (the forward pass, computing the guess), the magenta arrows run right-to-left (the backward pass, carrying ). Every exercise below is one journey along those arrows.


Level 1 — Recognition

Recall Solution L1.1

The chain rule. For nested (composed) functions, sensitivities multiply: if wiggles by a tiny amount, wiggles by times that, then wiggles by times that, and so on. Chaining these scalings gives A sum appears only when reaches through several separate paths (the multivariable chain rule); a straight chain is one path, so it is a pure product. See Chain Rule.

Recall Solution L1.2

Differentiate with respect to : the and the power-2 cancel, leaving It is the seed because it is the very first number of the backward pass — the "how wrong are we, and in which direction" quantity that every later gradient is grown from.

Recall Solution L1.3

The forward step multiplies inputs by the matrix (a linear map). The derivative of a linear map with respect to its input is the transpose (rows and columns swapped), not the inverse. Backprop is differentiation, and differentiating a linear map transposes it; nothing here undoes/inverts anything.


Level 2 — Application

Use with . ReLU (Rectified Linear Unit) is : it passes positives unchanged and clamps negatives to . Its slope is for and for . See Activation Functions.

Recall Solution L2.1

Walk the orange arrows of Figure 1:

Recall Solution L2.2

Seed then chain. Since , , so Because : and . Hence Read it as error out × signal in: the gradient of is its downstream error () times its own input ().

Recall Solution L2.3

Error flows back through and is scaled by the local slope . Since , : Then with and :


Level 3 — Analysis

Recall Solution L3.1

Forward: , so , , , . Backward: . Even the seed is zero. And the slope because . So All layer-1 gradients vanish. The ReLU is in its flat region — the unit is "dead." No error can pass a zero slope, so learning stalls for . This is a baby case of Vanishing Gradients.

Recall Solution L3.2

The chain rule factors into a product of local derivatives. Each is computed once and reused for every weight feeding that node: is built from (already known), and every weight's gradient is . So one backward sweep reuses cached quantities and touches each edge once — total work is proportional to the number of edges, i.e. one forward pass' worth. The naïve finite-difference method instead re-runs the whole net per weight: passes. This reuse is exactly what Automatic Differentiation mechanises. See Computational Graphs.

Recall Solution L3.3

The value influences along two independent paths. The multivariable chain rule says total sensitivity is the sum of per-path sensitivities — each path's contribution is (weight on that path) × (error at that path's target). Look at Figure 2: the two magenta arrows meet at and their blames add.

Figure — Backpropagation — chain rule, gradient computation

Level 4 — Synthesis

Recall Solution L4.1

Forward: . ReLU clamps: . Then , , . Backward: ; slope (since ); . The weight gradient is the outer product "error × input": , and . Every gradient is zero — again a dead unit. This shows the vector rule reproduces the scalar logic elementwise.

Recall Solution L4.2

Forward: , so ; , , . Backward: . , . (positive), so . Vector weight gradient (outer product): Notice each component is (the corresponding input) — the weight touching the bigger input () gets the bigger gradient.

Recall Solution L4.3

Update rule : Sanity: with still, new , new . Since , the loss decreased — gradient descent stepped downhill, as intended.


Level 5 — Mastery

Recall Solution L5.1

Forward: , . Then , , . Backward: . Local slope . Saturation: as , or , so . Since carries a factor , the gradient is throttled toward — the classic sigmoid Vanishing Gradients problem. The peak slope is only , so even at best sigmoids shrink error by per layer.

Recall Solution L5.2

With the sigmoid net, (since ). , . Numerically the slope estimate , matching L5.1's to five decimals. ✓ Central vs forward: the central formula's error shrinks like (the odd, first-order error terms cancel by symmetry), while a one-sided forward difference errs like . So the central estimate is far more accurate for the same .

Recall Solution L5.3

  • : geometrically — vanishing gradients; deep front layers barely learn.
  • : — error passes intact, the healthy regime that skip-connections and careful initialisation try to engineer.
  • : exploding gradients; updates blow up unless clipped. This single product is the reason depth is delicate, and why surrogate nets for aerodynamic data (Neural Network Surrogate Models (CFD)) need normalisation and residual paths to stay in the band.

Active recall

Zero-output-or-slope?
The zero slope ; it blocks the error signal regardless of the output value.
Why outer product for the weight gradient?
The gradient must match the weight's shape; entry is , giving the outer product .
What governs vanish/survive/explode across depth?
The product of per-layer factors with : vanish, survive, explode.

Connections