Skip to main content

Welcome to a Grasp lesson

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

Lesson 22

Momentum and Nesterov Acceleration in Ill-Conditioned Landscapes

Recommended resources

Welcome back. In our last lesson, we derived the standard gradient descent algorithm and analyzed its performance. The key takeaway was a vulnerability: on ill-conditioned problems, which are characterized by long, narrow valleys in the loss landscape, gradient descent converges very slowly. Its path consists of unproductive "zigzags" across the steep walls of the valley, making only minimal progress along the valley floor.

Today, we'll address this exact weakness by exploring two powerful extensions to gradient descent: classical momentum and Nesterov accelerated gradient (NAG). These methods are designed to accelerate convergence, particularly in the ill-conditioned landscapes typical of deep learning. We will derive their update rules, develop a physical intuition for how they work, and analyze the mathematical basis for their dramatic improvement in convergence speed.

1. Classical Momentum: The Heavy Ball Analogy

The core issue with gradient descent is that its steps are determined solely by the local gradient at the current point, with no memory of the past. Momentum introduces this memory. The intuition is often described using the physical analogy of a heavy ball rolling down a hill.

  • A simple gradient step is like a person walking, who can change direction instantly. In a narrow ravine, they may step from one side to the other repeatedly.
  • A heavy ball, however, has inertia. Its current velocity is a combination of its previous velocity and the force of gravity (the gradient). This inertia helps it to smooth out the oscillations and build up speed along the bottom of the ravine.

Mathematically, this is achieved by introducing a "velocity" vector, , which is an exponentially decaying moving average of the past gradients. The update rule is a two-step process: first update the velocity, then update the parameters.

The update rules for classical momentum (also known as Polyak or heavy-ball momentum) are:

  1. Update velocity: The new velocity is a combination of the old velocity , decayed by a momentum coefficient , and the new gradient step.
  2. Update parameters: The parameters are updated by adding the new velocity vector.

Here, is the momentum coefficient, typically a value close to 1 (e.g., 0.9 or 0.99). When , we recover standard gradient descent. As approaches 1, we incorporate more history into our steps.

Let's unpack why this helps in a narrow valley:

  • Across the valley: The gradient components perpendicular to the valley floor flip their sign at each step. By averaging them, the momentum term dampens these oscillations.
  • Along the valley: The gradient components pointing towards the minimum have a consistent sign. The momentum term accumulates these components, accelerating movement in the correct direction.

The following image illustrates this behavior. The momentum-based path is smoother and more direct than the zigzagging path of simple gradient descent we saw previously.

The path of an optimization algorithm using momentum on a 2D loss surface. The accumulated velocity helps dampen oscillations and speed up convergence toward the optimum.

2. The Mathematics of Acceleration

The heavy ball analogy is useful, but the true power of momentum is revealed through a more formal analysis. In the last lesson, we saw that for an ill-conditioned quadratic, the convergence rate of gradient descent is dictated by the condition number , with the error decreasing by a factor proportional to at each step. For large , this is very close to 1, signifying slow convergence.

Momentum dramatically improves this. For the same problem, with optimally chosen parameters, the error decreases by a factor proportional to . The "square root" improvement on the condition number is the mathematical essence of acceleration.

Professor Gilbert Strang provides a clear derivation of this result in his MIT lecture. He shows how to analyze the momentum update by converting the second-order recurrence relation into a system of two first-order equations, a standard technique you'll recognize from solving linear ordinary differential equations.

23. Accelerating Gradient Descent (Use Momentum)

This lecture, "Accelerating Gradient Descent," directly follows the previous one on gradient descent. Professor Strang first recaps the zigzagging problem and then introduces the momentum term.

Watch these two key segments: First, from the introduction of momentum, he sets up the problem and reveals the final result: the improvement from B to \sqrt{B} (where B=1/\kappa) in the convergence rate factor. Then, from the main derivation, he transforms the second-order momentum update into a 2x2 first-order system. Pay close attention to how he follows a single eigenvector, reducing the vector problem to a scalar one involving the matrix R. This matrix governs the evolution of the system.

The analysis boils down to choosing the step size and momentum to make the eigenvalues of the iteration matrix as small as possible, across all eigenvalues of the Hessian. This is a non-trivial minimax problem. The following article presents the solution and provides a rich interactive environment to explore the results.

Why Momentum Really Works

This article from Distill.pub offers one of the best available analyses of momentum. It uses the convex quadratic model to develop deep insights.

Please read the following sections: Start with the introduction, which sets the stage and highlights the theoretical optimality of momentum. Then, read the section on analyzing momentum on a quadratic. This parallels Professor Strang's derivation, showing the coupled update rule and the iteration matrix R. Finally, study the section on optimal parameters. This is the payoff. It provides the optimal formulas for \alpha and \beta in terms of the largest and smallest eigenvalues (\lambda_n and \lambda_1) and explicitly shows the convergence rate changing from depending on \kappa to depending on \sqrt{\kappa}.


3. Nesterov Accelerated Gradient (NAG): Looking Before You Leap

While powerful, classical momentum has a subtle flaw. It calculates the gradient at the current position and then adds this to the scaled velocity vector . This is like taking a big step in the direction of your accumulated momentum and, separately, a small step in the direction of the local gradient, then adding them up.

Nesterov's key insight was that it is more efficient to first use the momentum to "look ahead" to an approximate future position and then compute the gradient at that future position to make a correction. This is the "look before you leap" principle.

The update proceeds in two conceptual steps:

  1. Look-ahead: Make a provisional update using only the accumulated momentum: .
  2. Correction: Compute the gradient at this look-ahead point, , and use it to make the final update.

This leads to the Nesterov Accelerated Gradient (NAG) update rule, in the form commonly used in deep learning (derived by Sutskever et al.):

Notice the crucial difference: the gradient is evaluated at , not at .

A visual representation of the Nesterov method. The algorithm first makes a "jump" (brown vector) in the direction of the previous accumulated gradient. It then measures the gradient where it lands and makes a "correction" (red vector). The final step (green vector) is the sum of these two. This is contrasted with standard momentum (blue vectors), which computes the gradient before the jump.

Why is this better? Imagine the momentum is carrying you too far up the other side of a valley.

  • Classical momentum would compute the gradient at your current position (still low in the valley), which might not strongly oppose the momentum. Only on the next step, after you've already overshot, will the gradient provide a strong correction.
  • NAG would first make the momentum jump, landing high on the other side of the valley. The gradient it computes there will point sharply back towards the minimum, providing an immediate and strong braking force that corrects the overshoot before the final update is committed. This results in smaller, more efficient "U-turns."

The following video provides an excellent visual demonstration of this effect.

Deep Learning(CS7015): Lec 5.5 Nesterov Accelerated Gradient Descent

This lecture from NPTEL provides a clear, intuitive explanation of NAG.

Please watch from the beginning to the end of the explanation. The lecturer first introduces the "look before you leap" idea. The most valuable part is the animation of the single-variable error surface, where they walk through how NAG anticipates the change in gradient sign after overshooting, leading to a smaller, corrective "U-turn" compared to the large overshoot of classical momentum.


4. Deriving the Common Form of NAG

The common implementation of NAG, as we've seen, looks very similar to classical momentum, with the gradient evaluated at a "look-ahead" point. You may wonder how this relates to Nesterov's original formulation, which appears quite different. The following reading provides a detailed walk-through, showing how the more intuitive Sutskever formulation can be derived from the original by simply shifting the perspective of what constitutes an "iteration". Given your background, following this derivation will provide a solid understanding of the algorithm's structure.

Nesterov Accelerated Gradient and Momentum

This blog post provides one of the most thorough comparisons of classical momentum and various NAG formulations available online.

This is a rich resource, but we will focus on a few key parts. First, familiarize yourself with the author's notation in the section on Classical Momentum. Then, read the section on NAG to see the original formulation. The core of our reading is the section on Sutskever Nesterov Momentum. This section brilliantly explains how a simple re-labeling of the iteration steps transforms the original NAG equations into the familiar "look-ahead" form. Finally, read the short Conclusions section. It provides a great summary of the practical differences and implementation challenges.


Conclusion

In this lesson, we have moved beyond simple gradient descent to algorithms that are far more effective in the challenging, ill-conditioned landscapes of deep learning.

Key Takeaways:

  • Classical Momentum introduces a "velocity" term, an exponentially weighted average of past gradients. This helps dampen oscillations across narrow valleys and builds speed along them.
  • Nesterov Accelerated Gradient (NAG) improves on momentum by using the velocity term to "look ahead" before computing the gradient. This allows for a more responsive correction that reduces overshooting and leads to more stable convergence.
  • The primary theoretical advantage of these methods is their improved convergence rate on ill-conditioned problems. The dependence on the condition number is reduced from to , a significant acceleration.
  • There are multiple, mathematically equivalent formulations of NAG. Understanding how they relate, particularly the Sutskever "look-ahead" form, is key to its practical implementation and intuition.

We have now seen how to accelerate optimization by using a running average of the gradients (the first moment). However, all parameters in our model still share the same, global learning rate . What if some parameters need to move faster than others? In our next lesson, we will introduce the Adam optimizer, which combines the momentum concept with adaptive, per-parameter learning rates by tracking not only the first moment of the gradients but also the second.