You have implemented backpropagation by hand and want to test it with gradient checking. Why is the central difference J(w+h)−J(w−h)2h preferred to the forward difference, how do you compare it with your analytic gradient, and what goes wrong if h is too large or too small? Illustrate with J(w)=w3 at w=2 and h=0.1?

Deep learning, Backpropagation
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you know how to test a backprop implementation, including the order of the numerical error and its practical limits.

Key idea

Taylor expansion shows that the forward difference has error O(h) while the central difference has error O(h2). The numerical gradient is compared with the analytic one by relative error, and h must balance truncation error (large h) against round-off error (tiny h).

Steps

  1. Expand J(w±h)=J±hJ′+h22J′′±h36J′′′+…. Subtracting, the even terms cancel: J(w+h)−J(w−h)2h=J′+h26J′′′+…, an O(h2) error. The forward difference (J(w+h)−J(w))/h=J′+h2J′′+… has O(h) error.
  2. Example. J=w3 so J′(2)=12. Central: (2.13−1.93)/0.2=(9.261−6.859)/0.2=12.01, an error of 0.01. Forward: (9.261−8)/0.1=12.61, an error of 0.61.
  3. Compare using a relative error, because absolute error depends on the scale: ∥ganalytic−gnum∥max⁡(∥ganalytic∥,∥gnum∥). In double precision with h≈10−5, values below about 10−7 are good and values above about 10−3 signal a bug.
  4. If h is too large, truncation error O(h2) dominates. If h is too small (say 10−12), J(w+h) and J(w−h) agree in almost all digits, so subtracting them loses precision (round-off error roughly εmach/h).
  5. Check each parameter in turn (or a random subset), run the check on a tiny network and batch, and use double precision.
  6. Switch off random behaviour (dropout, data augmentation) or fix its random seed, otherwise J changes between the two evaluations. Also turn off batch-norm updates of running statistics, and test away from kinks such as the ReLU at 0.

Common mistakes

How long your answer should be

Half a page; 4–5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: A scalar parameter starts at θ0=1 and is trained with Adam using learning rate η=0.1, β1=0.9, β2=0.999 and ϵ=10−8. The first two gradients are g1=0.4 and g2=−0.2. What are θ1 and θ2, and what would the first step have been without bias correction?
Next in Deep learning: A network has input x=(1,2)⊤, two hidden units, and one linear output y^=a1w21+a2w22+b2. All weights and biases start at 0. The loss is 12(y^−1)2 and the learning rate is 1. What happens over two gradient-descent steps (a) with sigmoid hidden units and (b) with ReLU hidden units, and what happens to the two hidden units?