Explainer

One Learning Rate, Two Curvatures: Why Gradient Descent Zigzags

A two-variable quadratic shows why gradient descent can oscillate across a steep direction yet make slow progress along a flat one under one shared step size.

On this page

Deck: I animated a two-variable quadratic to show why gradient descent crawls along the flat direction while it bounces across the steep one. The cause is not noise or bad luck; it is that a single step size has to serve every direction at once.

The loss I animated, and why I chose it

I made a short Manim film about gradient descent on the simplest loss I could write down:

L(x, y) = 1/2 · (a_x · x² + a_y · y²)

That is a bowl centered at the origin, with one number — a_x or a_y — setting how sharply the surface curves along each axis. Set them equal and the bowl is round. Set them far apart and it becomes a long narrow valley: steep across the short axis, gentle along the long one. Real loss surfaces are not quadratic, but they look approximately quadratic near a minimum, which is why this shape is worth understanding on its own.

No momentum, no gradient clipping, no stochastic noise, no optimizer tricks. Just the update rule, applied over and over:

x ← x − eta · a_x · x = (1 − eta · a_x) · x
y ← y − eta · a_y · y = (1 − eta · a_y) · y

That closed form is the whole story of the film. For a quadratic, each step multiplies each coordinate by a fixed number, 1 − eta · a, so the run is decided by two multipliers computed before the first step. Gradient descent on this surface is a linear iteration wearing a calculus costume. Once I wrote the multipliers down, the shapes I wanted to animate stopped being a matter of taste and became arithmetic: a multiplier between 0 and 1 shrinks steadily, a negative one alternates sides, and a magnitude above 1 grows.

The film is here: https://youtu.be/ePitf5YApI4. The scene and the loss definition are public on a working branch of my animation repository — the scene and the loss asset. The companion interactive lab is still an unmerged draft, not a live page; these files are the math behind the film.

The round case is the control

I ran the same starting point and the same step count in both scenes: start at (2.4, 0.35), eta = 0.45, 24 steps.

For the round scene I set a_x = a_y = 0.45. Both multipliers are

1 − 0.45 · 0.45 = 0.7975

so both coordinates shrink by the same factor on every step. The ratio y / x never changes, which means the trajectory is a straight line into the origin. After 24 steps the coordinates have been multiplied by 0.7975^24 ≈ 0.0044: x lands near 0.0105, y near 0.0015, and the loss falls from about 1.32 to about 2.5 × 10⁻⁵.

Visually, this scene is boring. It is a dot sliding into a bowl. I kept it in the series anyway because it establishes the baseline: descent is not inherently zigzagging. A perfectly conditioned quadratic — one where the curvature is the same in every direction — descends cleanly, so any jaggedness I show later has to come from somewhere specific.

The stretched case is where the motion becomes interesting

For the second scene I set a_x = 0.12 and a_y = 3.6: the same starting point, the same eta, the same 24 steps. Now the two multipliers disagree:

x: 1 − 0.45 · 0.12 = 0.946
y: 1 − 0.45 · 3.6  = −0.62

Read the two numbers separately, because they describe two different behaviors of the same step size.

0.946 is positive and close to one, so x decays slowly and monotonically — it slides down the flat direction without overshooting. Its half-life, the number of steps to shrink to half, is ln 2 / ln(1/0.946) ≈ 12.5 steps. Over 24 steps x only reaches 0.946^24 ≈ 0.264 of its starting value, ending near 0.63.

−0.62 is negative. The sign flip is the overshoot: each step jumps past the axis to the other side. But the magnitude is still below one, so each jump is smaller than the last. The y coordinate alternates sides while shrinking, with a half-life measured on magnitude — ln 2 / |ln 0.62| ≈ 1.45 steps. After 24 steps |y| is about 1.0 × 10⁻⁵ of its start, which is 3.6 × 10⁻⁶ in absolute terms.

So in the same run, y converges about 8.6 times faster than x. The ratio shows up the same way whichever framing I use: per step, ln(1/0.62) / ln(1/0.946) ≈ 8.6, and measured as steps needed to fall to 10⁻⁵ of the starting value, about 24 steps for y against about 207 for x. And yet y is the coordinate that looks unstable on screen. That contrast is the point of the film: the steep direction is the one that oscillates, and the flat direction is the one that actually holds the error.

The loss numbers make the same point from the other side. This scene starts at a loss of about 0.57, lower than the round scene’s 1.32 despite the sharper curvature: the steep a_y = 3.6 multiplies the coordinate that starts small (0.35), while the gentle a_x = 0.12 multiplies the one that starts large (2.4). After 24 steps the stretched scene ends near 0.024, against 2.5 × 10⁻⁵ in the round scene. The remaining loss is essentially all x: the term 1/2 · 0.12 · 0.6333² contributes 0.02406, while the y term contributes about 2 × 10⁻¹¹. The visible zigzag is happening in the direction that has already converged.

The stable range is set by the sharpest direction

Because each coordinate behaves independently, convergence requires |1 − eta · a| < 1 for every direction. Two assumptions are doing quiet work in that sentence: eta > 0, and positive curvature. With both in place the inequality rearranges to

0 < eta < 2 / a

A negative curvature would instead push the multiplier above 1 at small eta, so its window would be a different interval; everything below assumes a_x and a_y are positive, as they are in both scenes. Each direction has its own window, and one eta has to satisfy all of them at once:

DirectionCurvature aWindow for etaMultiplier at eta = 0.45
flat (x)0.12below 16.70.946
steep (y)3.6below 0.556−0.62

The usable window is the intersection, so the sharpest direction wins the argument. The two ceilings on eta differ by the same factor as the curvatures do — 30 — because the ceiling is 2 / a: 16.7 for the flat direction against 2 / 3.6 ≈ 0.5556 for the steep one. At that boundary the y multiplier is exactly −1: y oscillates between two fixed values forever, never converging and never blowing up. Push eta past it and the oscillations grow. My chosen 0.45 sits inside the window, which is exactly why the film shows a stable zigzag instead of a divergence. It is not finely tuned: one multiplier is positive and slow, the other is negative but smaller than 1 in magnitude, and both keep the run convergent while making the contrast visible.

Here is the tradeoff that makes the flat direction a problem. eta = 0.45 is legal — it sits inside the shared window — but a step size small enough to stay safe across a_y = 3.6 is also slow across a_x = 0.12. Safety and speed pull in opposite directions: the steep direction caps how large eta may be, while the flat direction needs a large eta to move at a comparable rate. To make x shrink like y — at multiplier 0.62 rather than 0.946 — x would need 1 − eta · 0.12 = 0.62, that is eta ≈ 3.17: about six times the 0.5556 ceiling the y direction imposes. (At that eta the y multiplier would be 1 − 3.17 · 3.6 ≈ −10.4, so y would blow up instead of zigzagging.) Making eta big enough for the flat direction destabilizes the steep one. That is the deadlock the animation is about. Methods that change the geometry or scale directions differently address this kind of mismatch; this example isolates the problem rather than analyzing those methods.

There is one more thing the arithmetic shows, because “8.6 times faster” is easy to misread as a verdict about which direction matters. It is a rate, not a finish. Both coordinates converge; the steep one just gets there long before the scene ends, while the flat one is still visibly mid-descent when the film stops. Run the same settings for a few hundred steps and the zigzag fades while the slow crawl along x is what remains.

What the animation does not claim

This is a math explainer about a quadratic. There is no stochastic gradient, no minibatch noise, no scheduling, and no real training run in it, so none of the numbers above transfer to a network: a real loss surface is not a fixed bowl, its curvature changes from point to point, and the direction descent comes from is sampled rather than exact. What transfers is the mechanism: curvature that differs by direction — anisotropy — combined with a single shared step size, produces motion that oscillates where the surface is sharp and stalls where it is flat. The film shows that mechanism at its cleanest, with the multipliers written on the screen so a viewer can check the arithmetic themselves.

If you want to reproduce the scenes, change a_x and a_y and watch the two multipliers. The visual difference between a straight slide and a zigzag is decided before the first step runs: it is arithmetic, not chance, and a viewer who computes 1 − eta · a can predict the whole film.