Taylor Expansions in Optimization

Approximating a curve with a line or a bowl, which is how optimisers move.

🔴 advanced5 min readcalculusoptimization
A Taylor expansion approximates a complicated function near a point using simple pieces: its value there, its slope and its curvature. Using just the slope gives a straight-line approximation, and following that line downhill is exactly what gradient descent does. Adding the curvature gives a bowl-shaped approximation, and jumping straight to the bottom of that bowl is Newton's method. That is why Newton's method needs far fewer steps, but each step costs much more, since curvature is expensive to compute for large models.

What is a Taylor Series?

A Taylor Series approximates any smooth non-linear function near point x0x_0 using a sum of polynomial terms constructed from derivatives:

f(x0+Δx)=f(x0)+f′(x0)Δx+12!f′′(x0)Δx2+13!f′′′(x0)Δx3+…f(x_0 + \Delta x) = f(x_0) + f'(x_0) \Delta x + \frac{1}{2!} f''(x_0) \Delta x^2 + \frac{1}{3!} f'''(x_0) \Delta x^3 + \dots
   Non-linear Loss Function f(x) vs Taylor Approximations
   Loss
    High ┤            /  Actual Non-linear Loss f(x)
         │           /  / 2nd-order Quadratic Approx (Parabola)
         │          /  / /
         │         /  / /  1st-order Linear Approx (Tangent Line)
         │        /  / /  /
     Low ┴───────(  *  )─────────────────► Parameter x
                 x_0 (Expansion Point)

First-Order Approximation (Gradient Descent)

Truncating the series after the first derivative term:

f(x0+Δx)≈f(x0)+∇f(x0)TΔxf(x_0 + \Delta x) \approx f(x_0) + \nabla f(x_0)^T \Delta x

To make loss f(x0+Δx)<f(x0)f(x_0 + \Delta x) < f(x_0), choose displacement Δx=−α∇f(x0)\Delta x = -\alpha \nabla f(x_0):

f(x0−α∇f)≈f(x0)−α∥∇f(x0)∥2<f(x0)(α>0)f(x_0 - \alpha \nabla f) \approx f(x_0) - \alpha \|\nabla f(x_0)\|^2 < f(x_0) \quad (\alpha > 0)

This proves mathematically why moving in the opposite direction of the gradient guarantees local loss reduction!

Second-Order Approximation (Newton's Method)

Including the second derivative (Hessian matrix HH):

f(x0+Δx)≈f(x0)+∇f(x0)TΔx+12ΔxTH(x0)Δxf(x_0 + \Delta x) \approx f(x_0) + \nabla f(x_0)^T \Delta x + \frac{1}{2} \Delta x^T H(x_0) \Delta x

To find the step Δx\Delta x that minimizes this quadratic approximation, set derivative wrt Δx\Delta x to 0:

∂∂Δx[f(x0)+∇f(x0)TΔx+12ΔxTH(x0)Δx]=∇f(x0)+H(x0)Δx=0\frac{\partial}{\partial \Delta x} \left[ f(x_0) + \nabla f(x_0)^T \Delta x + \frac{1}{2} \Delta x^T H(x_0) \Delta x \right] = \nabla f(x_0) + H(x_0) \Delta x = 0 ΔxNewton=−H(x0)−1∇f(x0)\mathbf{\Delta x_{\text{Newton}} = -H(x_0)^{-1} \nabla f(x_0)}

Newton's Method uses curvature HH to jump directly to the minimum of the quadratic approximation in a single step!

Why Deep Learning Prefers 1st-Order

  1. 1st-Order (SGD / Adam): Requires O(N)O(N) memory and compute per step.
  2. 2nd-Order (Newton): Requires storing O(N2)O(N^2) Hessian matrix and computing O(N3)O(N^3) inverse H−1H^{-1}. For N=100MN = 100\text{M} weights, H−1H^{-1} is computationally impossible.

Say this out loud

Taylor series expands complex functions locally using derivatives. 1st-order expansion f(x) ≈ f(x_0) + ∇f^T Δx proves why setting Δx = -α ∇f guarantees local loss reduction in Gradient Descent. 2nd-order expansion adds Hessian curvature (1/2) Δx^T H Δx, deriving Newton's method step Δx = -H^-1 ∇f for single-step quadratic minimization.

Follow-ups to expect

Check yourself

Question 1 of 3

What is the 2nd-order Taylor Series expansion formula for a scalar loss function f(x) around point x_0 with displacement Δx = x - x_0?

More in Math & Statistics

See all →
Bayes’ Theorem4 minCentral Limit Theorem4 minLaw of Large Numbers4 min