Backpropagation is not a special algorithm for neural nets. It is reverse-mode
automatic differentiation applied to one particular composite function: a scalar
loss L stacked on top of a layered network. A forward pass evaluates the
network and caches each activation; a backward pass then pushes the loss gradient
through those cached values, layer by layer, reusing the same weights the forward
pass used. One backward sweep costs about one forward pass and returns
∂L/∂θ for every parameter at once, which is exactly why
training deep nets, and the policy and value networks of deep reinforcement
learning, is tractable.12
The two passes
Write the network with pre-activations zl and activations
al. The forward pass is
a0=x,zl=Wlal−1+bl,al=σ(zl),
ending in a scalar loss L(aL,y). Define the error at layer
l as δl=∂L/∂zl. The chain
rule gives it a recurrence that runs from the output back to the input,
δL=∇aL⊙σ′(zL),δl=((Wl+1)⊤δl+1)⊙σ′(zl),
and the parameter gradients fall out of each δl directly,
∇WlL=δl(al−1)⊤,∇blL=δl.
The transpose (Wl+1)⊤ sends the error backward along the same edges
the forward pass used, σ′(zl) is the local derivative of the
nonlinearity, and the outer product with the cached al−1 turns a
layer's error into its weight gradient. Nothing here is a heuristic; it is the
chain rule, evaluated in the order that shares work.
A 2-2-1 network, by hand
Take two inputs, two tanh hidden units, one linear output, and the
single-sample squared-error loss L=21(a2−y)2 (the 21
makes ∂L/∂a2=a2−y). Fix the weights, input, and target:
One SGD step W←W−η∇WL with η=0.5 drives this
sample's loss from 0.0446 down to 0.0003 on the next forward pass.
Backpropagation through a 2-2-1 netinteractive
stateloss = n/aepoch = 0
1 forward · layer 1 ← next
2 forward · layer 2 + loss
3 backward · output
4 backward · hidden
5 apply · SGD update
press Step
Step through the forward and backward passes to see the numbers.
The same 2-2-1 network, computed live. Step forward (blue) to fill z and a at each layer, then backward (red) to compute the output error, the hidden error, and the weight gradients, with the substituted arithmetic in the panel. Apply runs one SGD update at eta = 0.5, and the loss-per-epoch trace shows the loss dropping. Auto loops through forward, backward, and update.
Why it scales
The backward recurrence touches each weight exactly once and reuses activations
already cached in the forward pass, so computing the full gradient costs the same
order as a single evaluation of the network, independent of how many parameters
there are. That is the reverse-mode payoff: differentiate a scalar output with
respect to millions of inputs in one sweep. Stack it with SGD and you can fit
deep networks, and because a policy or value network is just another composite
function ending in a scalar objective, the identical machinery is what makes deep
reinforcement learning trainable.