advanced25 min studyLesson 43 in Mathematics

Gradient descent and line search

Derive descent from a local model, test trial steps, and distinguish progress in values from a certificate of optimality.

On this page

What you’ll understand

  • Derive a stable gradient step from the descent lemma.
  • Carry out an Armijo backtracking test numerically.
  • Choose stopping criteria that match available guarantees.

The negative gradient is a direction, not a complete algorithm. An implementation must decide how far to travel, what evidence counts as improvement, and when to stop. A step that is excellent on one curvature scale may explode on another. Line search replaces a guessed universal step with a sequence of explicit tests, while convergence analysis explains the assumptions under which those tests eventually succeed.

Pay attention to the squared gradient

Insert y=x−η∇f(x)y=x-\eta\nabla f(x) into the smoothness upper bound. The predicted change is at most minus the step size times one minus half the scaled curvature, multiplied by the squared gradient norm. Thus any step strictly between zero and 2/L2/L decreases the objective when the gradient is nonzero. The conventional choice 1/L1/L gives a clean guaranteed reduction and avoids operating close to the unstable boundary.

This is a statement about exact arithmetic, exact gradients, and a valid smoothness bound on the relevant segment. A coding error in a derivative cannot be repaired by citing the theorem. Directional finite-difference checks can expose such errors, although their own rounding and truncation limits matter. Logging both gradient norms and accepted objective changes makes it easier to distinguish an oversized step from an inaccurate derivative or a flat objective scale.

f(x−η∇f(x))≤f(x)−η(1−Lη2)∥∇f(x)∥2f(x-\eta\nabla f(x))\leq f(x)-\eta\left(1-\frac{L\eta}{2}\right)\|\nabla f(x)\|^2
For an L-smooth function the bracket is positive when 0<η<2/L. Convexity is not required for this one-step descent inequality.↔ Scroll wide equations horizontally.

Backtracking asks for sufficient decrease

Armijo backtracking begins with a trial step, tests actual improvement against a fraction of the linear prediction, and repeatedly shrinks the step if the test fails. For gradient descent the required decrease is proportional to the squared gradient norm. Choose a sufficient-decrease constant strictly between zero and one and a shrink factor in the same range. With a descent direction and appropriate local smoothness, sufficiently small positive trials are accepted.

Do not interpret acceptance as a global certificate. It only says the current trial makes the promised local progress. Convexity, lower boundedness, regularity, and the step-selection rules enter broader convergence results. Backtracking also consumes extra function evaluations, which may dominate runtime if each evaluation requires an expensive simulation. In stochastic learning, evaluating two fresh random minibatches can invalidate a deterministic acceptance comparison; controlled data reuse or stochastic line-search theory is needed.

f(x−αg)≤f(x)−cα∥g∥2,g=∇f(x),0<c<1f(x-\alpha g)\leq f(x)-c\alpha\|g\|^2,\qquad g=\nabla f(x),\quad 0<c<1
Armijo accepts a trial α only when its actual decrease reaches the stated fraction c of the linear prediction. Failed trials are multiplied by a fixed β in (0,1).↔ Scroll wide equations horizontally.

Stop for the claim you can support

A small step can mean convergence, but it can also mean an extremely small chosen learning rate. A small change in objective can hide substantial error in a flat direction. For a differentiable unconstrained problem, a gradient-norm tolerance directly measures first-order stationarity. With known positive strong-convexity constant, the squared gradient also gives an upper bound on the objective gap. Constraints require a projected-gradient or other appropriate residual instead of the raw gradient.

The lab exposes the exact recurrence for the unit quadratic. Compare step 0.5 with 1.5: both contract in magnitude, but the latter alternates sides. At step size η=2\eta=2, a nonzero initial position oscillates without decreasing value; above two it diverges. These experiments isolate a step-size mechanism. They neither perform line search nor justify applying the same numeric thresholds to an objective with a different curvature constant.

Reject a trial before it becomes an iteration

At x=2x=2 for f(x)=x2/2f(x)=x^2/2, run Armijo with c=1/4c=1/4, initial trial α=2\alpha=2, and shrink factor 1/21/2.

  1. The current gradient is g=2g=2 and the value is two. The first trial proposes xtrial=2−2(2)=−2x_{\mathrm{trial}}=2-2(2)=-2, whose objective value is also two.

  2. The Armijo right-hand side is 2−(1/4)(2)(4)=02-(1/4)(2)(4)=0. The proposed value two is greater than zero, so the trial fails even though it did not increase the objective.

  3. Shrink to α=1\alpha=1. The new trial is zero with objective zero, while the required upper bound is 2−(1/4)(1)(4)=12-(1/4)(1)(4)=1. Since zero is at most one, accept the step and update x to zero.

The result

The first trial is rejected because it makes no sufficient progress. The second trial is accepted and reaches this particular quadratic's minimizer.

Explore the model

Interactive lab

Interactive lab · optimization

Find the stability boundary by prediction

Set a nonzero initial x₀ and compare η=1.5, 2, and 2.2 on f(x)=x²/2. Predict sign and magnitude after each Step. The lab uses a fixed step and does not implement Armijo backtracking or an arbitrary objective evaluator.

Find the stability boundary by predictionGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forFor this fixed curvature, descent, neutral oscillation, and divergence occur in distinct step-size regimes.

Check your understanding

What does passing an Armijo test at one iterate certify?

Try it yourself

For f(x)=x2f(x)=x^2 at x=1x=1, test α=1/2\alpha=1/2 with Armijo constant c=1/4c=1/4. State the accepted point and both sides of the test.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The gradient is two, so compute the trial point before comparing objective values. The current objective is one.

Compare with the solution

The trial is 1−(1/2)2=01-(1/2)2=0 with value zero. The required bound is 1−(1/4)(1/2)(22)=1/21-(1/4)(1/2)(2^2)=1/2. Because 0≤1/20\leq1/2, this trial is accepted. The step is exactly the reciprocal curvature for this objective, whose second derivative is two; that explains why it lands at the minimizer.

Take it with you

  • A direction and a step size together determine an optimization update.
  • Armijo backtracking checks a measurable fraction of predicted decrease.
  • Small motion, stationarity, and global optimality are different stopping claims.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.