3.1.9 · D4Neural Network Fundamentals

Exercises — Backpropagation algorithm derivation

2,473 words11 min readBack to topic

This is a self-test page for Backpropagation Algorithm Derivation. Every problem states its level (L1 Recognition → L5 Mastery). Try each one first, then open the collapsible solution. Numbers are checked in the vault's verify system, so trust them.

Throughout we reuse four equations, called BP1–BP4. So this page stands alone, here they are in full before any exercise uses them.

If any symbol looks unfamiliar, it is defined here before we use it — nothing is assumed.

Two number facts we lean on all page (memorise them):

Figure — Backpropagation algorithm derivation
Figure 1 — the 2-2-1 test network. Two butter-yellow input nodes on the left feed two mint hidden neurons (each storing a ), which feed one coral output neuron (). Lavender arrows are the weights ; coral arrows are . The grey arrow along the bottom marks the direction blame flows during backprop: output → inputs. Keep this picture in view for Exercises 3.x.


Level 1 — Recognition

Exercise 1.1 (L1)

Which of the four equations produces the gradient you actually feed to Gradient descent for a weight matrix, and which produces the starting error at the output layer?

Recall Solution

WHAT we're asked: just match names to jobs.

  • The gradient for a weight matrix is BP3: .
  • The starting error at the output is BP1: .

WHY: Gradient descent updates parameters (, ), so it needs BP3/BP4. But BP3 needs , and the whole chain has to start somewhere — that start is BP1 at the last layer, because the last layer is the only one that touches the loss directly.

Exercise 1.2 (L1)

In , name each of the three pieces in plain English.

Recall Solution
  • — "take the next layer's blame and route it backward through the weights, flipped." The flip (transpose) is because blame travels outputs→inputs.
  • — "elementwise gate," multiply position-by-position, no summing across.
  • — "how sensitive this neuron's output was to its own input at the value it actually saw." If the neuron was in a flat part of , this is near and it blocks the blame.

Level 2 — Application

Exercise 2.1 (L2)

Single sigmoid neuron: , target , MSE loss . Compute , then .

Recall Solution

Forward. . Backward, WHY these two factors: reaches only through , so chain rule gives .

  • (derivative of ).
  • . That is exactly BP1 for a one-neuron output layer.

Exercise 2.2 (L2)

A ReLU neuron with , and incoming blame from the layer above of . Find this neuron's .

Recall Solution

WHAT: apply BP2 for one neuron: . WHY the sign matters: ReLU when . Here , so: The neuron was "off," so it forwarded a constant ; changing its input changes nothing downstream, hence zero blame. This dead-zone is why very negative pre-activations kill gradients — see Vanishing and exploding gradients.


Level 3 — Analysis

Exercise 3.1 (L3)

Use the 2-2-1 network from Figure 1 (all values below repeated so you needn't flip back). Input , target , sigmoid, MSE. , , , . Compute the bias gradients and .

Recall Solution

WHY biases are easy: , so BP4 says the bias gradient equals the delta. No extra multiply. From the parent note's worked forward+backward pass:

Read it: the bias "absorbs" exactly the blame of its neuron, because a bias shifts one-for-one.

Exercise 3.2 (L3)

Same network. Take one gradient-descent step on with learning rate . Recall . Give the updated and say whether the output moved toward the target.

Recall Solution

Update rule (Gradient descent): . Did we improve? The gradient was negative, meaning "increasing decreases loss." We increased , so loss should drop. Concretely a larger raises , raises toward the target (we were at , target ). ✔ moves toward the target.

Figure — Backpropagation algorithm derivation
Figure 2 — why the gradient's sign sets the step direction. The lavender curve is the loss as a function of one weight . At the current weight (grey dot) the tangent (dashed coral) slopes downward to the right, i.e. the gradient is negative. The mint arrow shows the resulting move: step right (increase ) to slide downhill. This is exactly the negative-gradient in Exercise 3.2.


Level 4 — Synthesis

Exercise 4.1 (L4)

Build a small case where the sigmoid gate itself shrinks the gradient. A hidden neuron has . Its routed blame . Compute , and compare it to a neuron with receiving the same routed blame .

Recall Solution

BP2 for one neuron: .

  • Saturated neuron (): , .
  • Central neuron (): . The point: same incoming blame, but the saturated neuron passes back less. Stack many such layers and the product of tiny factors vanishes — that is Vanishing and exploding gradients in one line.

Figure — Backpropagation algorithm derivation
Figure 3 — the sigmoid slope is a bell. Mint curve: , peaking at when (coral dot, "fastest learning"). Far out at (lavender dot) the slope has collapsed to , so incoming blame is almost entirely blocked. Both flat tails cause vanishing gradients.


Level 5 — Mastery

Exercise 5.1 (L5)

Prove BP2 is dimension-forced. Layer has neurons, layer has neurons, so is . Given has length , show that only the transpose produces a length- result, and confirm elementwise-multiplying by (length ) is legal.

Recall Solution

Shapes are the whole proof.

  • maps activations of layer (length ) → pre-activations of layer (length ). A matrix that maps length- to length- is . ✔
  • Try : that is — but has length , not , so the inner dimensions ( vs ) don't match. Illegal. ✘
  • Try : that is . Inner dims match, output length . ✔
  • Now : has length (one per layer- neuron). Elementwise product of two length- vectors is length . ✔ Legal, and gives the required of length .

Conclusion: the transpose is not a stylistic choice — it is the only linear map that returns blame to the correct number of neurons. We say the forward map and the backward map are adjoints of each other: an "adjoint" is just the linear-algebra name for the transpose partner that sends a signal back through the reverse wiring. Forward pushes inputs→outputs; its adjoint pushes blame outputs→inputs.

Exercise 5.2 (L5)

Cross-entropy + sigmoid collapse. For a single output neuron with sigmoid and binary cross-entropy loss show that BP1 simplifies to (the messy cancels).

Recall Solution

Two pieces of BP1: .

  • Multiply: WHY this is beautiful: the that causes vanishing gradients in the sigmoid cancels exactly against the cross-entropy denominator. So the output layer never saturates its own learning signal — a strong reason to pair sigmoid with cross-entropy rather than MSE. Compare with Exercise 2.1, where MSE kept the factor alive. (See Loss functions (MSE, cross-entropy).)

Recall Quick self-check (cloze — hidden terms in

==...==) BP4 says the bias gradient equals the delta because . The backward pass uses because forward and backward maps are adjoints (transposes) of each other. For sigmoid + cross-entropy the output error collapses to ====. A neuron with very large passes back a tiny gradient because .

Why does the transpose (not ) appear in BP2?
Blame flows outputs→inputs (the adjoint direction), and only maps a length- delta back to length .
For sigmoid + MSE, what is ?
— the survives.
For sigmoid + cross-entropy, what is ?
— the cancels.