5.6.8Machine Learning (Aerospace Applications)

Backpropagation — chain rule, gradient computation

1,775 words8 min readdifficulty · medium6 backlinks

WHY does backprop exist?

WHY it works: derivatives of a composition factor into a product of local derivatives (chain rule). If we cache each layer's output during the forward pass, each local derivative is cheap and we multiply them together going backward.


WHAT is the chain rule (the engine)


Deriving backprop from scratch

Take a tiny 1-neuron-per-layer net (all scalars for clarity):

z1=w1x+b1,a1=σ(z1),z2=w2a1+b2,y^=z2,L=12(y^t)2.z_1 = w_1 x + b_1,\quad a_1=\sigma(z_1),\quad z_2=w_2 a_1 + b_2,\quad \hat y=z_2,\quad L=\tfrac12(\hat y - t)^2.

Step 1 — forward pass (cache everything). Compute z1,a1,z2,y^,Lz_1,a_1,z_2,\hat y,L and store them. Why this step? Backward local derivatives (like σ(z1)\sigma'(z_1)) need the cached activations; recomputing them would waste work.

Step 2 — seed the output gradient. Ly^=y^t.\frac{\partial L}{\partial \hat y} = \hat y - t. Why this step? L=12(y^t)2dL/dy^=(y^t)L=\tfrac12(\hat y-t)^2 \Rightarrow dL/d\hat y = (\hat y - t). This scalar is the "error signal" we propagate.

Step 3 — push through layer 2. Define δ2L/z2=L/y^1=(y^t)\delta_2 \equiv \partial L/\partial z_2 = \partial L/\partial\hat y \cdot 1 = (\hat y - t). Lw2=δ2z2w2=δ2a1,Lb2=δ2.\frac{\partial L}{\partial w_2}= \delta_2\,\frac{\partial z_2}{\partial w_2}=\delta_2\, a_1,\qquad \frac{\partial L}{\partial b_2}=\delta_2. Why this step? z2=w2a1+b2z_2=w_2 a_1+b_2, so z2/w2=a1\partial z_2/\partial w_2=a_1, z2/b2=1\partial z_2/\partial b_2=1. A weight's gradient = (error at its output) × (its input).

Step 4 — cross the nonlinearity. Backprop the error into a1a_1, then into z1z_1: La1=δ2w2,δ1Lz1=La1σ(z1)=δ2w2σ(z1).\frac{\partial L}{\partial a_1}=\delta_2\, w_2,\qquad \delta_1\equiv\frac{\partial L}{\partial z_1}=\frac{\partial L}{\partial a_1}\,\sigma'(z_1)=\delta_2\, w_2\,\sigma'(z_1). Why this step? Error flows back through the weight w2w_2 (transpose direction) and gets modulated by the local slope σ(z1)\sigma'(z_1).

Step 5 — layer 1 gradients. Lw1=δ1x,Lb1=δ1.\frac{\partial L}{\partial w_1}=\delta_1 x,\qquad \frac{\partial L}{\partial b_1}=\delta_1. Same pattern as Step 3 — that's the recursion.


The general recursion (vector/matrix form)

For layer \ell with z()=W()a(1)+b()z^{(\ell)}=W^{(\ell)}a^{(\ell-1)}+b^{(\ell)}, a()=σ(z())a^{(\ell)}=\sigma(z^{(\ell)}):


Worked example (numbers)

Let x=1, t=0x=1,\ t=0, w1=0.5, b1=0, w2=2, b2=0w_1=0.5,\ b_1=0,\ w_2=2,\ b_2=0, σ=\sigma= ReLU (so σ(z)=1\sigma'(z)=1 for z>0z>0).

  • Forward: z1=0.5z_1=0.5, a1=0.5a_1=0.5, z2=1.0z_2=1.0, y^=1\hat y=1, L=12(1)2=0.5L=\tfrac12(1)^2=0.5.
  • δ2=y^t=1\delta_2=\hat y-t=1. → L/w2=δ2a1=0.5\partial L/\partial w_2=\delta_2 a_1=0.5, L/b2=1\partial L/\partial b_2=1. Why: gradient of w2w_2 = error(1) × its input a1a_1(0.5).
  • δ1=δ2w2σ(z1)=121=2\delta_1=\delta_2 w_2 \sigma'(z_1)=1\cdot 2\cdot 1=2. → L/w1=δ1x=2\partial L/\partial w_1=\delta_1 x=2, L/b1=2\partial L/\partial b_1=2. Why: error(1) travels back through w2w_2(×2), slope is 1, then × input xx(1).

Common mistakes (steel-manned)


Feynman

Recall Explain to a 12-year-old

Imagine a line of people passing a wrong answer back down a hallway. The last person sees how wrong the answer is (that's the error). They whisper to the person behind them how much their choice mattered — bigger doors (weights) pass more blame, and a sleepy person (a unit that's "off") passes almost none. By the time the whisper reaches the front, everyone knows exactly how much to change. Doing it backwards means we only whisper once instead of asking every person "what if you'd chosen differently?"


Active recall

Backprop is fundamentally which calculus rule applied backward?
The chain rule (multivariable), reusing cached forward values.
Formula for a weight-matrix gradient in layer ℓ?
L/W()=δ()a(1)\partial L/\partial W^{(\ell)} = \delta^{(\ell)} a^{(\ell-1)\top} (error × input, outer product).
How does the error signal δ propagate from layer ℓ+1 to ℓ?
δ()=(W(+1)δ(+1))σ(z())\delta^{(\ell)} = (W^{(\ell+1)\top}\delta^{(\ell+1)}) \odot \sigma'(z^{(\ell)}).
Why transpose WW and not invert it during backprop?
The derivative of a linear map WaWa w.r.t. aa is WW^\top; backprop is differentiation, not inversion.
At a node whose output feeds several paths, how do you combine gradients?
Sum the gradients over all outgoing paths (multivariable chain rule).
Why must you cache activations in the forward pass?
Backward local derivatives (e.g. σ(z)\sigma'(z), inputs aa) need those cached values; recomputing wastes work.
Seed gradient for MSE loss L=12(y^t)2L=\tfrac12(\hat y - t)^2?
L/y^=y^t\partial L/\partial \hat y = \hat y - t.
What does σ(z)\odot \sigma'(z) do physically?
Scales each unit's incoming error by its own activation slope; saturated units pass ~0 error.
Bias gradient in a layer equals what?
L/b()=δ()\partial L/\partial b^{(\ell)} = \delta^{(\ell)} (since z/b=1\partial z/\partial b = 1).
Why is backprop essential for aerospace ML (e.g. surrogate aerodynamic models)?
It makes training deep nets on huge CFD/flight datasets computationally feasible by getting all gradients in one sweep.

Connections

  • Gradient Descent — backprop supplies the gradients it consumes.
  • Chain Rule — the mathematical engine.
  • Computational Graphs — the structure backprop traverses.
  • Activation Functions — supply the σ(z)\sigma'(z) factors.
  • Vanishing Gradients — caused by repeated small σ\sigma' products.
  • Automatic Differentiation — reverse-mode AD is generalized backprop.
  • Neural Network Surrogate Models (CFD) — aerospace use case.

Concept Map

needs grad per weight

too slow O#weights passes

derivatives of composition factor

solves

one backward sweep O 1 passes

reused by

multivariable sum over paths

seeds

pushed backward

weight grad = error x input

cross nonlinearity via sigma prime

used by

Composed function L = fN...f1 x

Gradient descent training

Naive perturb each weight

Chain rule

Backpropagation

Efficient gradients

Forward pass caches activations

Gradients fan-in at shared nodes

Error signal delta at output

Local derivatives per layer

Weight gradients

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Backpropagation ka core idea bilkul simple hai: neural network ek badi composed function hai (function ke andar function ke andar function), aur hume har weight ke liye gradient chahiye taaki gradient descent se training ho sake. Agar hum har weight ko thoda-thoda badal ke poora network dobara chalayein, toh millions of weights ke liye ye kaam bahut slow ho jaata. Backprop chain rule ko ulta (backward) lagaakar sirf ek forward aur ek backward pass mein saare gradients nikaal deta hai — isliye deep learning practical bana.

Kaise? Forward pass mein hum har layer ke zz aur activation aa ko cache kar lete hain. Phir output pe error signal δ=y^t\delta = \hat y - t banate hain, aur usko peeche ki taraf bhejte hain. Har layer cross karte waqt teen cheezein hoti hain: error ko WW^\top se multiply karo (transpose, kyunki forward mein WW se multiply hua tha — inverse nahi, transpose!), phir activation ka slope σ(z)\sigma'(z) se multiply karo, aur weight ka gradient nikaalne ke liye us error ko us weight ke input se multiply karo. Yaad rakho: har weight ka gradient = uska error out × uska signal in.

Common galti: log σ(z)\sigma'(z) multiply karna bhool jaate hain, ya W1W^{-1} lene lagte hain — dono galat. Aur jahan ek node kai jagah jaata hai, wahan saare paths ke gradients add karne padte hain (multivariable chain rule).

Aerospace mein ye kyun important hai? Jab hum CFD ya flight-test ke huge data pe neural network surrogate model train karte hain (jaise drag/lift predict karna bina full simulation ke), tab backprop hi hai jo lakhon parameters ko efficiently tune karta hai. Iske bina modern ML aerospace design loops chal hi nahi sakte.

Go deeper — visual, from zero

Test yourself — Machine Learning (Aerospace Applications)

Connections