Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Backpropagation

1. The Optimization Problem

The goal of training a neural network is to minimize the empirical loss over a training set of nn samples:

min⁡θL(θ)=1n∑i=1nℓ(fθ(xi),yi)\min_{\theta} L(\theta) = \frac{1}{n} \sum_{i=1}^{n} \ell(f_{\theta}(x_i), y_i)

2. The Backpropagation Algorithm

Backpropagation is an efficient method for computing the gradient ∇ℓi(θ)\nabla \ell_i(\theta) using the chain rule. It consists of two primary phases:

Phase 1: Forward Pass

Input xx is fed through the network to compute and store intermediate activations:

  1. Linear Combination: a=Vxa = Vx

  2. Hidden Activation: h=σ(a)h = \sigma(a)

  3. Output Logits: z=Whz = Wh

  4. Prediction: y^=g(z)\hat{y} = g(z)

  5. Loss Computation: ℓ(θ)=∥y−y^∥2\ell(\theta) = \|y - \hat{y}\|^2 (for regression)

Phase 2: Backward Pass

Gradients are computed layer-by-layer starting from the output:

  1. Output Error (δ(2)\delta^{(2)}): Compute the error signal at the output layer:

    δ(2)=2(g(z)−y)⊙g′(z)\delta^{(2)} = 2(g(z) - y) \odot g'(z)
  2. Output Weights Gradient: ∂ℓ∂W=δ(2)h⊤\frac{\partial \ell}{\partial W} = \delta^{(2)}h^\top

  3. Hidden Error (δ(1)\delta^{(1)}): Backpropagate the error to the hidden layer:

    δ(1)=(W⊤δ(2))⊙σ′(a)\delta^{(1)} = (W^\top \delta^{(2)}) \odot \sigma'(a)
  4. Input Weights Gradient: ∂ℓ∂V=δ(1)x⊤\frac{\partial \ell}{\partial V} = \delta^{(1)}x^\top


3. Computational Efficiency

The total cost of a single training step is the sum of the forward and backward passes:


4. Stochastic Gradient Descent (SGD)

To scale to massive datasets, optimizers use subsets of data rather than the full batch.

Mini-batch SGD

Instead of computing the full gradient ∇L(θ)\nabla L(\theta), we sample a mini-batch BkB_k of size bb:

θk+1=θk−α1b∑i∈Bk∇ℓi(θk)\theta_{k+1} = \theta_k - \alpha \frac{1}{b} \sum_{i \in B_k} \nabla \ell_i(\theta_k)

5. Model Summary: NN vs. Ensemble Methods

Lecture 13 also concludes the discussion on tree-based ensembles: