Skip to content
Glacius

Machine learning

Why gradient descent can oscillate

Why gradient descent oscillates: a visual, worked example showing convergence, overshooting, and divergence as the learning rate changes.

In this article
  1. A function we can see all the way through
  2. Three rates, three stories
  3. The exact boundary in this example
  4. What carries over to machine learning?
  5. Predict the next step
Gradient descent on f(x) = x²/2 starting at x = 1. Across eight steps, learning rate 0.5 converges without oscillation, 1.5 converges with oscillation, and 2.1 oscillates with increasing magnitude. The axes show iteration and x, not loss.Gradient descent on f(x) = x²/2 starting at x = 1. Across eight steps, learning rate 0.5 converges without oscillation, 1.5 converges with oscillation, and 2.1 oscillates with increasing magnitude. The axes show iteration and x, not loss.
Three learning rates, three trajectories

Filled markers: η = 0.5. Hollow markers: η = 1.5. Dashed line: η = 2.1. All start at x = 1 on the same quadratic.

Calculated from xₜ = (1 − η)ᵗ for f(x) = x²/2. Illustrative calculation, not training benchmark data.

The gradient tells you which way a function increases locally. Taking a step in the opposite direction sounds like a reliable way to go downhill. So why can gradient descent bounce from one side of a minimum to the other—or get farther away?

A direction is not a step size. A locally useful direction can still carry you past the point you wanted to reach. A simple quadratic lets us calculate exactly when that happens.

A function we can see all the way through

Use f(x)=x2/2f(x) = x^2/2. Its minimum is at x=0x = 0, and its derivative is f(x)=xf'(x) = x. Start at x0=1x_0 = 1.

With a learning rate η\eta, gradient descent takes the update:

xt+1=xtηf(xt)=(1η)xt.x_{t+1} = x_t - \eta f'(x_t) = (1-\eta)x_t.

Each step multiplies the current value by the same number, 1η1-\eta. Repeating the update gives xt=(1η)tx_t = (1-\eta)^t for our starting point. We can understand the whole trajectory by looking at that multiplier.

Three rates, three stories

With η=0.5\eta = 0.5, the multiplier is 0.5. The sequence is 1,0.5,0.25,0.125,1, 0.5, 0.25, 0.125, \ldots. Each step closes half the remaining distance. The sign stays positive and the distance from zero gets smaller.

With η=1.5\eta = 1.5, the multiplier is −0.5. Now the sequence is 1,0.5,0.25,0.125,1, -0.5, 0.25, -0.125, \ldots. Each step crosses the minimum. It oscillates, but its distance from zero still halves. This trajectory converges too.

With η=2.1\eta = 2.1, the multiplier is −1.1. The sequence begins 1,1.1,1.21,1.331,1, -1.1, 1.21, -1.331, \ldots. It crosses zero and gets farther away every time. This one diverges.

The chart above plots the parameter xx against step number, rather than plotting the loss. That distinction matters: the parameter can oscillate even while the loss steadily falls.

Learning rateMultiplierParameter behavior
0.50.5Approaches zero from one side
10Reaches zero in one step
1.5−0.5Oscillates toward zero
2−1Alternates between 1 and −1
2.1−1.1Oscillates away from zero

The exact boundary in this example

For the distance to zero to shrink, the magnitude of the multiplier must be less than 1:

1η<1.|1-\eta| < 1.

Solving gives 0<η<20 < \eta < 2. Inside that interval, this quadratic converges from our starting point. At η=2\eta=2, it keeps bouncing at a fixed distance; above 2, the distance grows.

The threshold 2 belongs to this particular function. It is not a universal learning-rate recommendation. If we change the function to f(x)=cx2/2f(x)=cx^2/2 for c>0c>0, the derivative becomes cxcx, the multiplier becomes 1ηc1-\eta c, and the convergence condition becomes 0<η<2/c0<\eta<2/c.

Greater curvature reduces the size of a stable step. This is one reason a learning rate that works on one objective can fail on another.

What carries over to machine learning?

Real training problems can have many parameters, different curvatures in different directions, and noisy gradient estimates. The simple multiplier above no longer describes the full process.

But it gives you a useful question to ask when a training run behaves strangely: is the update direction wrong, or is the step too large for the local geometry? Dive into Deep Learning develops this idea further with examples of gradient descent.

Changing the learning rate is an experiment to evaluate, not a diagnosis by itself. Inspect the loss, check gradient calculations when appropriate, and compare runs under controlled conditions. A noisy curve can have more than one explanation.

Predict the next step

For our original function, start again at x=1x=1 and use η=0.8\eta=0.8. Where does the first update land? Does the next one cross zero?

Show the answer

The multiplier is 10.8=0.21-0.8=0.2. The first update lands at 0.2 and the second at 0.04. Neither crosses zero. Repeated updates approach zero from the positive side.

Continue with the step-size lesson, or revisit the gradient update to connect the formula to the direction of movement.

The figure’s downloadable CSV contains all nine plotted values for each rate, so you can reproduce the trajectories. These are exact-form calculations for an illustrative function, not measurements from a model-training benchmark.

Check the reasoning

Sources & notes

  1. Dive into Deep Learning: Gradient Descent

    Develops gradient descent in one and multiple dimensions and illustrates the effect of learning rate.

Our figures use illustrative mathematical examples unless a dataset is explicitly identified. You can share the original Glacius figures with attribution and a link to this article; linked third-party material retains its own terms.

By Glacius. Send a correction ↗

Make the connection

Practice these concepts

Practice in Glacius