For gradient descent on f(x) = x^2, which learning rates converge and which diverge?
answer
- the update is a multiplication
- one contraction factor governs everything
- compare that factor against one in absolute value
- two thresholds, not one
- the general form involves the curvature
basics
~20 sOn f(x) = x^2 the update multiplies x by (1 - 2 * eta) each step, so it converges exactly when eta is between 0 and 1. eta = 0.5 lands on the minimum in one step, eta between 0.5 and 1 oscillates while shrinking, eta = 1 cycles forever, and eta above 1 diverges.
solid answer
~50 sFor `f(x) = x^2` the derivative is `2x`, so one step gives `x_new = x - eta * 2x = (1 - 2 * eta) * x`. The whole behaviour is that one contraction factor `r = 1 - 2 * eta`, and after k steps `x_k = r^k * x_0`. You converge exactly when `|r| < 1`, that is `0 < eta < 1`. Within that range: `eta < 0.5` decays monotonically from the same side; `eta = 0.5` sets r to zero and hits the minimum in a single step; `0.5 < eta < 1` alternates sign each step while shrinking; `eta = 1` flips between x and -x forever with no progress; `eta > 1` alternates and grows without bound. The general rule is `eta < 2 / L`, where L is the curvature (the second derivative, here 2), so the safe range shrinks as the surface gets steeper.
code
python · 15 lines# f(x) = x^2, so the gradient is 2x and one step is x - eta*2*x
for eta in (0.1, 0.5, 0.9, 1.0, 1.1):
x = 1.0
first_two = []
for i in range(20):
x = x - eta * 2 * x
if i < 2:
first_two.append(round(x, 4))
print("eta", eta, "first steps", first_two, "after 20", round(x, 6))
# eta 0.1 -> factor 0.8, decays smoothly toward 0
# eta 0.5 -> factor 0, lands on the minimum in one step
# eta 0.9 -> factor -0.8, alternates sign but still shrinks
# eta 1.0 -> factor -1, cycles between 1 and -1 forever
# eta 1.1 -> factor -1.2, alternates and blows upgo deeper
Recall that too large a step makes the loss explode and too small a step makes training crawl, and be able to plug two learning rates into f(x) = x^2 by hand and see the difference.
Derive the contraction factor 1 - 2 * eta for f(x) = x^2, state the convergence condition as an absolute value less than one, and generalise it to eta below 2 divided by the curvature.
Diagnose a live training curve from its shape: explosion means past the threshold, sawtooth means past one over the curvature, near-flat means far below it, and know how far to cut in each case.
Frame step size as a stability budget owned by the team: what the sweep protocol is, how loss scaling and data changes silently move the threshold, and what safeguard catches a divergent run early.
## The exact dynamics on a quadratic Quadratics are the right place to reason about step size because the iteration has a closed form. For `f(x) = x^2` the derivative is `f'(x) = 2x`, and the gradient descent update is ``` x_new = x - eta * 2 * x = (1 - 2 * eta) * x ``` Every step multiplies the iterate by the same constant `r = 1 - 2 * eta`, so after k steps `x_k = r^k * x_0`. Convergence to the minimum at zero happens exactly when `|r| < 1`, which rearranges to `0 < eta < 1`. ## The five regimes Starting from `x_0 = 1`: - **eta = 0.1** gives r = 0.8. The iterates 0.8, 0.64, 0.512 shrink monotonically and never change sign. Safe but slow. - **eta = 0.5** gives r = 0. The single step lands exactly on the minimum. On a quadratic, the ideal step is `1 / curvature`. - **eta = 0.9** gives r = -0.8. The iterates -0.8, 0.64, -0.512 overshoot the minimum every step but land closer each time. Converging, visibly oscillating. - **eta = 1.0** gives r = -1. The iterate flips between 1 and -1 forever. The loss never changes; the method is exactly on the stability boundary. - **eta = 1.1** gives r = -1.2. The iterates -1.2, 1.44, -1.728 alternate sign and grow geometrically. After twenty steps the magnitude is roughly 38, and in a real training loop this shows up as a loss that explodes to infinity or to a non-finite value within a handful of iterations. ## The general threshold The number 1 is not special — it comes from the curvature of `x^2`. Write the second derivative as L (here `f'' = 2`). Then the contraction factor is `1 - eta * L`, and the condition `|1 - eta * L| < 1` becomes ``` 0 < eta < 2 / L ``` which for L = 2 gives `eta < 1`. Two consequences worth stating in an interview. First, the stability limit is set by the largest curvature anywhere the iterates travel, not by the average one. Second, for a function whose gradient is L-Lipschitz (curvature bounded by L), the standard descent inequality gives, for a step of length eta, ``` f(x - eta * g) <= f(x) - eta * (1 - eta * L / 2) * ||g||^2 ``` so any `eta < 2 / L` guarantees the objective actually decreases at every step, and `eta = 1 / L` is the usual safe default because it maximises that guaranteed decrease. ## Reading it off a loss curve This theory translates directly into diagnosis: - Loss blowing up to a huge or non-finite value in a few steps: eta is above the threshold. Cut it by an order of magnitude, not by ten percent. - Loss falling but bouncing up and down between consecutive steps: eta is inside the range but past `1 / L`, the overshooting regime. Often still fine, sometimes worth halving. - Loss falling smoothly but painfully slowly, with the curve nearly a straight line: eta is far below the threshold and you are wasting iterations. - Loss flat from the start: either eta is minuscule or the gradient is effectively zero at the initial point. ## Tuning in practice Because the safe range depends on a curvature you usually do not know, the practical recipe is a coarse geometric ladder — try step sizes separated by factors of three or ten, run a small number of iterations of each, keep the largest one that does not blow up, then back off by a factor of two or three for margin. Note that this threshold is not a property of your problem alone: it moves if you rescale the objective (multiplying the loss by 10 multiplies every gradient by 10 and divides the safe eta by 10) or rescale the inputs, so a learning rate copied from another setup carries no guarantee. ## The trap in the question The common wrong instinct is that a smaller step size is always safer and a larger one always faster, so the trade-off is smooth. The quadratic shows it is not: behaviour changes qualitatively at `1 / L` (overshoot begins) and again at `2 / L` (divergence begins). Between those two points the method still converges while visibly oscillating, and exactly at `2 / L` it neither converges nor diverges. Being able to name those two thresholds, and derive them from a two-line calculation, is what separates a memorised answer from an understood one.
- Why does the largest safe learning rate change if you multiply the whole loss by 100?Scaling the objective by 100 scales every gradient by 100, so the effective curvature L is 100 times larger and the stability limit 2 / L is 100 times smaller. The same eta that was safe now overshoots badly. This is why a learning rate borrowed from another problem, or kept after switching from a mean loss to a summed loss, can explode.
- What does an oscillating but slowly decreasing loss curve tell you about the step size?It says eta is in the band between 1 / L and 2 / L: each step overshoots the minimum along the steepest direction but lands closer than it started, so the sign alternates while the magnitude shrinks. It is converging, not broken. Halving eta removes the oscillation, at the cost of slower progress on flatter directions.
- Why does eta = 1 / L reach the minimum of a one-dimensional quadratic in a single step?The contraction factor is 1 - eta * L, which is exactly zero when eta = 1 / L, so the iterate is mapped straight onto the minimiser. This exactness is special to a quadratic with a single curvature; with several different curvatures no single scalar step can zero out all of them at once.
saying these in an interview costs you the question
- Claims a smaller learning rate is always strictly safer with no cost
- Thinks divergence begins as soon as the iterate overshoots the minimum
- Cannot connect the safe range to the curvature of the surface
- Assumes a good learning rate transfers across objectives unchanged
- Says a diverging loss means the data or the gradient formula is wrong