Gradient Descent with Momentum

Lesson Introduction

Welcome back! Today, we'll explore Gradient Descent with Momentum. You've already familiarized yourself with basic gradient descent. However, sometimes gradient descent is slow and gets stuck, especially on bumpy paths to the minimum.

So, how do we speed it up? We use momentum. Imagine pushing a heavy shopping cart. Instead of stopping and starting, you build momentum. This helps you move faster. By the end of this lesson, you'll understand how gradient descent with momentum works, implement it in Python, and see how it improves optimization.

Introducing Momentum

How Velocity Works in Gradient Descent with Momentum

In the basic gradient descent, the update to the parameters is directly proportional to the gradient of the function. However, this approach can be slow due to the oscillations around the minimum.

With momentum, the velocity term vtv_t is introduced to accelerate gradient vectors in the right directions. Here's a detailed breakdown of how the velocity term works:

  1. Initial Update (at t=0t=0)
    • Velocity starts at zero: v0=0v_0 = 0.
    • The first update is similar to basic gradient descent.
  2. Subsequent Updates (at t>0t>0)
    • The velocity is updated with a fraction of the previous velocity, vt1v_{t-1}, scaled by β\beta, and the current gradient, scaled by α\alpha.
    • This means that the update direction is influenced not just by the current gradient but also by the past gradients, providing a smoothing effect.
    • The point is updated using this velocity.

In essence, the velocity term accumulates the gradients of past steps to create a more stable and faster approach toward the minimum.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal