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
The question for today
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 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 decreases the objective when the gradient is nonzero. The conventional choice 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.
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.
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 , 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.
Work it through
Reject a trial before it becomes an iteration
At for , run Armijo with , initial trial , and shrink factor .
The current gradient is and the value is two. The first trial proposes , whose objective value is also two.
The Armijo right-hand side is . The proposed value two is greater than zero, so the trial fails even though it did not increase the objective.
Shrink to . The new trial is zero with objective zero, while the required upper bound is . Since zero is at most one, accept the step and update x to zero.
The first trial is rejected because it makes no sufficient progress. The second trial is accepted and reaches this particular quadratic's minimizer.
The living notebook
Explore the model
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.
- Position x0
- 2
- Objective x²/2
- 2
- Iteration behavior
- Stable step
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.
Pause & reason
Check your understanding
Your turn
Try it yourself
For at , test with Armijo constant . 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 with value zero. The required bound is . Because , 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.
Keep the idea
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.