Every backward formula this entire curriculum has written, 03-tanh's 1 - output**2, 03-mse-gradient's grad_prediction.T @ input, Assemble minimal autograd engine's whole reverse-topological walk, is a place a mistake could have silently crept in: a dropped transpose, a sign flip, a wrong axis, a formula copied from the wrong nearby function. A backward formula with a subtle bug doesn't crash, it just quietly computes a WRONG gradient, that a model then trains against, producing a model that trains slower, or worse, or not at all, with no error message pointing at the actual cause.
Numerical gradient checking is the tool that catches this class of bug directly: compute the SAME gradient two completely independent ways, once analytically (the formula you wrote, that you're not fully sure is correct) and once numerically (01-derivatives-first-principles's central difference, slow, but essentially impossible to get subtly wrong), and confirm they agree. This is, formalized into reusable code, the exact discipline this entire curriculum's authoring process has quietly relied on: every single backward formula built throughout this whole session was checked against something equivalent to this before being trusted.
Theory computes the numerical gradient via central difference, compares it to a provided analytical gradient using a SCALE-INVARIANT relative error (rather than a raw absolute difference, which would be meaningless without knowing the gradient's typical magnitude), and returns whether that error falls below a tolerance.
Implement numerical_gradient(f, x, eps=1e-5) first, then relative_error(analytical, numerical), then gradient_check(f, x, analytical_grad, eps=1e-5, tolerance=1e-5).
numerical_gradient is 01-derivatives-first-principles's exact central difference formula, restated here for a self-contained, standalone autograd utility.relative_error must handle the edge case where both gradients are (near) zero, without dividing by zero.gradient_check returns a plain bool.Open one at a time. Each gives away a little more than the last.
(f(x + eps) - f(x - eps)) / (2 * eps) is the entire numerical_gradient formula, no new derivation needed.
max(abs(analytical), abs(numerical), 1e-12) as the denominator keeps relative_error well-defined even when both gradients happen to be exactly 0.
Click "Run Tests" to test your implementation