Backpropagation
Source: Unit 2 §8
Backpropagation iteratively compares the network's prediction to the actual target and modifies the weights to minimise the loss - working backwards from the output layer, through each hidden layer, to the first hidden layer.
- For each training tuple, the weights are modified to minimise the loss between the prediction and the target.
- The modifications flow output → hidden → … → first hidden, which is where the "back" in backpropagation comes from.
The loss function
For a single output unit, the error as a function of the weight vector is:
For multiple output units , sum over the outputs as well:
The stochastic approximation updates per example rather than summing over the whole training set first.
The chain-rule derivation
Take a simple chain of single neurons and look at the last layer . We want to know how sensitive the cost is to each weight, that is . A tiny nudge in nudges , which nudges , which changes . Chain them together:
| Term | Comes from | Value |
|---|---|---|
∂E/∂a(L) | E = (a(L) − y)² | **2(a(L) − y)** |
∂a(L)/∂z(L) | a(L) = σ(z(L)) | **σ'(z(L))** |
∂z(L)/∂w(L) | z = w·a(L−1) + b | **a(L−1)** |
Multiplying the three:
- The bias derivative is almost identical. Replace with , which is 1, giving .
- Generalise over examples by averaging the per-example gradients.
- Keep iterating the chain rule backwards to get the sensitivity to the earlier weights , and so on.
Full multi-neuron notation
With many neurons per layer, the indices arrive:
- is the activation of the j-th neuron in layer ; is the k-th neuron in layer .
- is the weight on the edge connecting the k-th neuron in layer to the j-th neuron in layer .
- The cost for a multi-output layer is .
A neuron in layer feeds every neuron in layer , so it affects the cost by several routes at once. Its is therefore a sum over those paths, not a single term. Forgetting the sum is the classic backprop derivation error.
These chain-rule expressions give the derivatives that form each component of the gradient, which is then used to minimise the cost by repeatedly stepping downhill - ordinary gradient descent, applied to every weight in the network at once.
Derivative of the sigmoid
Backpropagation needs at every layer, and the sigmoid has a particularly convenient one:
Derived with the quotient rule. The same exercise for gives:
and . During the backward pass the forward activations are already stored, so neither derivative costs a fresh exponential.
Overfitting in backpropagation
The situation is analogous to the decision-tree case. With many weights and many iterations, backpropagation can overfit - tuning the weights to idiosyncrasies of the training data that are not representative of the general distribution.
- Maintain a separate validation set, apart from both the training and the test sets.
- Periodically measure accuracy on the validation set while training continues.
- Choose the weights that gave the least validation-set error, not the ones training ended on.