Backpropagation — Hidden Units, Weights, Biases and the Full Algorithm
On this page 10 headings
Trace the chain rule through one weight
Start with one linear neuron, h = wx + b, to isolate the chain rule. Set input 2, target 4, weight 1, bias 0, and loss ½(h − y)².
Forward pass and loss.
Find the loss gradient at the neuron output.
Pass it through the local derivatives.
Update with learning rate 0.1, then check the loss.
What changed? Backpropagation multiplies an incoming gradient by a local derivative. A sigmoid neuron adds its activation derivative to this chain.
Quick check: Why is the weight gradient −4 but the bias gradient −2?
The weight’s local derivative is the input x = 2; the bias’s local derivative is 1.
Swipe long formulas, tables or code sideways to see the rest.
Start here We know the gradient at the output: . Now we push it down the network. Three short formulas do all the work: one to pass blame from a layer to the hidden units below, one to go through the activation, and one to get the gradient for the weights and biases. Put them in a loop and you have backpropagation.
In a wide network, one hidden unit (layer i, unit j) feeds every pre-activation in the layer above. So its effect on the loss travels along many paths.
Multi-path chain rule: if p(z) depends on z through several intermediate values , then
Here: .
Since , we have . So
This is the dot product of the j-th column of with :
Stack all j into a vector:
(transpose of the weight matrix times the gradient of the layer above)
Since , each unit only depends on its own pre-activation:
As a vector:
⊙ means element-wise multiplication (multiply position by position).
Now we can compute for every layer: start from (known), , then , then down to layer 1.
Recall , so . Then , and
Lecture example — a 3 × 3 weight matrix
by row:
Row i uses ; column j uses . This is exactly an outer product.
(column vector times row vector matrix of the same shape as )
, so , and
Training loop
t ← 0; max_iterations ← 1000
initialise θ₀ = [W₁, …, W_L, b₁, …, b_L]
while t++ < max_iterations:
a₁, h₁, …, a_{L−1}, h_{L−1}, a_L, ŷ = forward_propagation(θ_t)
∇θ_t = backward_propagation(h₁ … h_{L−1}, a₁ … a_L, y, ŷ)
θ_{t+1} ← θ_t − η ∇θ_tForward propagation
for k = 1 to L−1:
a_k = b_k + W_k h_{k−1}
h_k = g(a_k)
a_L = b_L + W_L h_{L−1}
ŷ = O(a_L)Backward propagation
∇a_L L = −(e(y) − ŷ) # output gradient
for k = L down to 1:
∇W_k L = ∇a_k L · h_{k−1}ᵀ # weights
∇b_k L = ∇a_k L # biases
∇h_{k−1} L = W_kᵀ ∇a_k L # pass to layer below
∇a_{k−1} L = ∇h_{k−1} L ⊙ [… g′(a_{k−1,j}) …] # through activation( the last two lines are not needed — is the input x, which we don’t update.)
The only missing piece is g′.
Logistic:
tanh:
| z | tanh(z) | tanh′(z) | ||
|---|---|---|---|---|
| 0 | 0.5 | 0.25 (max) | 0 | 1 (max) |
| 0.5 | 0.6225 | 0.2350 | 0.4621 | 0.7864 |
Nice property: both derivatives use the output g(z) we already stored in the forward pass — no extra exponentials needed.
Network: 2 inputs → 2 sigmoid hidden units → 2 softmax outputs. All biases 0. , true class .
Forward:
Backward:
A numerical check (nudging each weight by and re-computing the loss) gives the same .
In one line: Backprop start with , then for each layer going down: .
Exam words: multi-path chain rule, , element-wise product (outer product), , forward propagation, backward propagation, .
