Skip to main content

Welcome to a Grasp lesson

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

Lesson 2

Gradient Descent: Derivation and Convergence for Convex Functions

Recommended resources

Welcome back! In our previous lesson, we explored the crucial property of convexity and established why it's so desirable for optimization problems: any local minimum is also a global minimum. This guarantee simplifies the search for an optimal solution immensely.

Today, we will build directly on that foundation to derive and analyze one of the most fundamental optimization algorithms in machine learning: gradient descent. You'll learn how this algorithm uses local derivative information to iteratively navigate the landscape of a cost function towards its minimum. Our main goals are to derive the famous gradient descent update rule from a first-order Taylor approximation and then, using the concepts of convexity and smoothness, formally explain its convergence guarantees.

The Intuition: Approximating and Stepping

The core idea of gradient descent is simple: start somewhere, look around to see which way is "downhill," and take a step in that direction. We repeat this process until we can't go any lower. To make this precise, we need a mathematical way to determine the "downhill" direction.

This is where the Taylor series, a powerful tool for approximating functions, comes into play. A first-order Taylor approximation allows us to approximate a complex function near a point with a simple linear function—its tangent line (or hyperplane in higher dimensions).

To refresh your intuition on using simpler functions for approximation, this video by Dr. Trefor Bazett provides a great conceptual overview.

Intro to Taylor Series: Approximations on Steroids

This video explains how we can approximate a function, like e^x, with increasingly accurate polynomials, starting with a constant and then a line.

Watch the first part of the video covering the constant and linear approximations (the setup) and then the section explaining how the coefficients of the linear approximation are chosen by matching the function's value and derivative at a point (linear approximation).

As the video shows, the linear approximation is the best linear fit to the function near the point . We will use this exact idea to decide which direction to move from our current position.


Deriving the Gradient Descent Update Rule

Let's formalize the "downhill" search. Suppose we are at a point and we want to find a new point such that . We'll define our step as , where is a small scalar called the step size or learning rate, and is a unit vector representing the direction of movement.

Using a first-order Taylor expansion around , we can approximate the function value at the new point:

The change in the function value is therefore:

Our goal is to make this change as negative as possible to ensure the greatest decrease in . Since is a positive constant, we need to choose the direction to minimize the quantity .

This video provides an excellent and intuitive walkthrough of this exact derivation for a single-variable function.

Gradient Descent and Taylor Series

This video from IIT Madras lucidly connects the Taylor series approximation to the choice of the negative gradient as the descent direction.

Please watch from the beginning to see how the first-order approximation is used to justify the gradient descent update rule. The key argument happens between approximation and continues until the final justification at derivation.

As the video concludes, to make the product most negative, we should choose to be in the direction opposite to the gradient .

More formally, from the definition of the dot product (and the Cauchy-Schwarz inequality), we know:

where is the angle between the gradient and the direction vector. Since is a unit vector (), this expression is minimized when . This occurs when points in the exact opposite direction of .

Thus, the direction of steepest descent is .

Plugging this back into our step, , we get the update rule:

In practice, the normalization term is often absorbed into the learning rate , giving us the canonical gradient descent update rule:

This diagram illustrates the gradient descent process. At the current position \(\theta_0\), the gradient \(\nabla J(\theta)\) points in the direction of steepest ascent. The algorithm takes a step of size \(\eta\) in the opposite direction, \(-\nabla J(\theta)\), moving "downhill" towards the minimum \(\theta^*\).

Convergence Guarantees of Gradient Descent

We've derived a plausible algorithm, but does it actually work? Under what conditions will it converge to the minimum ? This is where we connect back to the properties of the function we are optimizing.

The proofs of convergence typically rely on an assumption called L-smoothness.

Definition (L-smoothness): A differentiable function is L-smooth if its gradient is Lipschitz continuous with constant . This means for any two points and :

Intuitively, L-smoothness means the gradient cannot change arbitrarily fast. A key consequence is that an L-smooth function is upper-bounded by a quadratic function. This "quadratic upper bound" is essential for the analysis.

To understand the convergence proof, we'll follow the clear and rigorous derivation in the MIT lecture notes by Prof. Gabriele Farina.

[PDF] Lecture 7 Gradient descent - MIT

These notes provide a formal analysis of gradient descent, deriving its convergence rate for L-smooth convex functions.

First, read the introduction and the derivation of the update rule in Section 1. Next, read Section 2, which introduces L-smoothness and proves the Gradient Descent Lemma (Theorem 2.3). This lemma is critical, as it shows that if the step size \eta \le 1/L, each step guarantees a decrease in the function value. Finally, read Section 2.3. This section combines L-smoothness with the convexity assumption from our last lesson. Follow the derivation that leads to Theorem 2.6. This is the main result we are after.

Let's break down the key results from that reading:

  1. Descent Lemma (for L-smooth functions): If is L-smooth and we choose a step size , then each step of gradient descent guarantees progress:

    This tells us the function value will decrease at every step unless the gradient is zero (i.e., we are at a stationary point). For a non-convex function, this could be a local minimum or a saddle point.

  2. Convergence for Convex Functions (Theorem 2.6): When we add the assumption that is also convex, we can prove a much stronger result. As derived in the notes, the sub-optimality of the function value (the difference between the current value and the true minimum ) is bounded:

    This is a profound result. It guarantees that gradient descent will converge to the global minimum. The rate of this convergence is , which is known as a sublinear rate. This means that to achieve a desired accuracy , we need approximately iterations.

A Note on Faster Convergence

While convergence is good, we can do even better under a stronger condition called m-strong convexity. An m-strongly convex function is one whose curvature is bounded below by some (formally, ). For such functions, gradient descent enjoys a linear convergence rate.

3.5. Gradient descent and its convergence analysis

This section of the MMiDS textbook provides a clean derivation of the faster convergence rate for strongly convex functions.

Please read the subsection "Smooth and strongly convex case". Focus on the final theorem and its implication.

As shown in the reading, for an L-smooth and m-strongly convex function, the convergence rate is:

This is an exponential decay, often written as where . This means we only need iterations to reach an accuracy of , which is significantly faster than the sublinear rate for general convex functions.


Conclusion

In this lesson, we demystified the gradient descent algorithm. You learned not just what it does, but why it works. The key takeaways are:

  • The gradient descent update rule, , is derived by minimizing a first-order Taylor approximation of the function at the current point.
  • The negative gradient, , is the direction of steepest descent.
  • Convergence is not automatic. It depends on the properties of the function being optimized.
  • For an L-smooth and convex function, gradient descent is guaranteed to converge to the global minimum with a sublinear rate of .
  • If the function is also m-strongly convex, the convergence rate improves exponentially to a linear rate, .

So far, we have assumed that we can compute the full gradient at each step. This involves evaluating the gradient over all data points in your training set. For massive datasets, this can be computationally prohibitive. In our next lesson, we will address this challenge by exploring Stochastic Gradient Descent (SGD), a powerful and widely used variant that approximates the gradient using only a small subset of the data.