Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 37

Taylor Approximation and Gradient Descent

Recommended resources

Introduction

In our last lesson, we traced the path of the gradient descent algorithm, visualizing it as a journey down the "mountain" of a loss surface. We established the core update rule: at each step, we adjust our model's parameters by taking a small step in the direction of the negative gradient. This is the how of optimization. Today, we delve into the why.

This lesson provides the mathematical justification for the gradient descent algorithm. We will introduce a powerful tool from calculus, the Taylor approximation, which allows us to approximate any complex, differentiable function with a simpler one (like a straight line) in a small neighborhood. By applying this tool to our loss function, you will see precisely why moving opposite the gradient is the mathematically optimal choice for making local progress towards a minimum. This bridges the gap between the algorithmic procedure and its underlying principles.


The Power of Local Approximation: Taylor Series

Most loss functions in machine learning are complex and non-linear. Analyzing them directly can be intractable. The core idea behind many optimization methods is to forget the global complexity for a moment and focus on creating a simple, local approximation of the function right where we are. If you zoom in far enough on any smooth curve, it starts to look like a straight line. The Taylor series is the mathematical formalization of this idea.

The 3Blue1Brown video below provides a masterful intuition for how we can construct a polynomial that "hugs" a more complex function around a specific point by matching its value, its slope (first derivative), and its curvature (second derivative).

Taylor series | Chapter 11, Essence of calculus

This video from the "Essence of Calculus" series explains the motivation and construction of Taylor polynomials.

Watch from the beginning to understand the motivation for approximating functions with polynomials (the motive). Then, pay close attention to the step-by-step construction of a quadratic approximation for cos(x) (building the approximation). The key insight is how the coefficients of the polynomial are chosen to match the original function's value, its first derivative (slope), and its second derivative (curvature) at the point of approximation.

The most basic and, for our purposes, most important of these is the first-order Taylor approximation, which is simply the tangent line to the function at a point.

This plot shows a loss function (solid black curve) at a specific point (the green dot). The red dashed line is the first-order Taylor approximation—the tangent line at that point. Notice how, in the immediate vicinity of the current point, this line is a very good approximation of the actual function.

Justifying Gradient Descent with the First-Order Approximation

Let's now formalize this for our loss function , where is the vector of our model's parameters. The following reading introduces the equation for the first-order Taylor approximation in the context of machine learning.

Chapter 2: Taylor Approximations

This excerpt from a University of Toronto course text provides the precise mathematical formulation we need.

Focus on the section "The Gradient Vector." Read the short introduction and pay special attention to Equation (6). This is the first-order Taylor approximation for a scalar-valued function (like our loss, here denoted J) around a point w0.

As the reading shows, the approximation of our loss function around our current parameter vector is:

Here, is the gradient vector evaluated at our current position, and is the "step" we are considering taking to a new position . Let's call this step vector . Our approximation then becomes:

Our goal is to choose a step that makes the new loss, , as small as possible. Looking at the equation, is our current loss, a fixed number. To minimize the whole expression, we need to make the term as negative as possible.

This term is a dot product between the gradient vector and our proposed step vector . So, the question becomes: for a fixed step size , what direction should have to make its dot product with the gradient maximally negative?

The answer lies in the geometric definition of the dot product: , where is the angle between the vectors. The value of is minimized at -1 when , meaning the vectors point in opposite directions.

Therefore, to make maximally negative, the step vector must point in the exact opposite direction of the gradient vector .

This is the mathematical proof for the core principle of gradient descent! The best local direction to step in is . The following video explains this crucial dot product relationship beautifully.

Why the gradient is the direction of steepest ascent

This Khan Academy video provides the final piece of the puzzle: why the dot product connects the gradient to the direction of steepest change.

Watch the segment that sets up the problem of finding the direction of maximum change using the directional derivative, which is a dot product (the setup). The key insight is in the next segment, which uses the geometric interpretation of the dot product (involving projection) to show that the result is maximized when the direction vector aligns with the gradient (the maximization argument). By the same logic, the dot product is minimized (made most negative) when the direction vector is opposite to the gradient.


The Role of the Learning Rate

This analysis provides a formal reason for why the learning rate, , must be small. The Taylor approximation is only accurate for points that are very close to .

The update rule for gradient descent is . Our step is .

  • If is small, our step is small. We stay within the "region of better approximation" shown in the image above, where the tangent line is a good proxy for the true function. Our move is guaranteed to decrease the loss.
  • If is large, our step is large. We travel so far that the linear approximation is no longer valid. The actual loss function may have curved upwards by then, causing us to "overshoot" the minimum and end up at a point with higher loss than where we started.

This is the theoretical reason for the divergence we can observe in practice when the learning rate is too high. The following reading explicitly links the first-order approximation to the gradient descent algorithm.

[PDF] Optimization with Taylor Expansions

This document provides a concise summary of how Taylor expansions are used in optimization.

Start by reading the section "Taylor Series" to see the formula for a first-order approximation presented again (the approximation). Then, read the section "Gradient Descent," which directly states that the algorithm is based on this first-order approximation and defines the update rule (the connection).


Conclusion

In this lesson, you've moved beyond the procedural steps of gradient descent to understand its mathematical foundation. By approximating a complex loss function with its local tangent line, we can easily determine the optimal direction of travel.

Key Takeaways:

  • Taylor approximations allow us to model complex functions with simpler polynomials (like lines or parabolas) in a small local neighborhood.
  • The first-order Taylor approximation of a function at a point is its tangent line.
  • Minimizing this linear approximation is equivalent to finding a step vector that has the most negative dot product with the gradient.
  • The dot product is maximally negative when the two vectors point in opposite directions. This proves that the direction of steepest descent is precisely the negative gradient .
  • This justification holds only for small steps, providing the theoretical reason why a small learning rate is necessary for gradient descent to converge.

You now understand why the gradient descent update rule works. In the next lesson, we will explore some of the practical challenges of this algorithm, diagnosing why it can be slow or get stuck, and introduce Stochastic Gradient Descent (SGD), a crucial variant that is the workhorse of modern large-scale machine learning.