Line search

On this page 7

Line search is a procedure in numerical optimization that, given a current point and a descent direction, chooses a step length along that direction so that the objective function decreases by a sufficient amount. It reduces a multidimensional problem to a one-dimensional search at every iteration, and it is the component that turns a direction-finding rule such as gradient descent, Newton’s method or L-BFGS into an algorithm with dependable convergence.

In artificial intelligence, line search appears in classical model fitting (logistic regression, conditional random fields, Gaussian process hyperparameters), in full-batch training of smaller neural networks, and in second-order and quasi-Newton solvers used inside larger pipelines. It is less common in large-scale stochastic training, where noisy gradients make exact step selection expensive and unreliable.

How line search chooses the step length

A line search answers one question per iteration: how far to move along the direction p from the point x. Writing the one-dimensional function phi(alpha) = f(x + alpha p), the method looks for a value of alpha greater than zero that makes phi small enough without wasting function evaluations. The direction must be a descent direction, meaning that the directional derivative, the dot product of the gradient and p, is negative.

An exact line search minimizes phi(alpha) completely, which is rarely worth the cost except for quadratic objectives where a closed-form step exists. Practical solvers use an inexact line search: they accept the first step that satisfies a small set of mathematical conditions guaranteeing progress. A typical loop proposes an initial step, tests the conditions, and then shrinks, expands or interpolates until a step is accepted.

  1. Compute a descent direction p from the outer algorithm.
  2. Propose an initial step, often alpha = 1 for Newton-type methods.
  3. Evaluate the objective, and the gradient if required, at the trial point.
  4. Accept the step if the chosen conditions hold; otherwise shrink or interpolate.
  5. Move to the new point and pass the new gradient back to the outer algorithm.

Acceptance conditions: Armijo, Wolfe and Goldstein

The acceptance conditions define what counts as a good enough step. The Armijo condition, also called the sufficient decrease condition, requires that the new objective value lies below a line drawn from the current value with a slope equal to a small fraction c1 of the directional derivative. On its own it prevents steps that are too long but allows steps that are uselessly short.

The curvature condition fixes that weakness by requiring that the slope at the new point is noticeably less negative than at the start. Together, the two form the Wolfe conditions; the strong Wolfe conditions additionally bound the absolute value of the new slope, which keeps the step near a stationary point of phi. The table below summarizes the common rules and their typical constants.

ConditionWhat it enforcesTypical constantsMain use
ArmijoSufficient decrease in fc1 between 1e-4 and 1e-3Backtracking with gradient or Newton steps
WolfeSufficient decrease plus curvaturec1 = 1e-4, c2 = 0.9Quasi-Newton methods such as BFGS
Strong WolfeDecrease plus bounded absolute slopec1 = 1e-4, c2 = 0.1 to 0.9Nonlinear conjugate gradient, L-BFGS
GoldsteinStep neither too long nor too shortc between 0 and 0.5Newton-type methods, rarely quasi-Newton
Common acceptance conditions for inexact line search

The choice of conditions matters for the outer method. BFGS and L-BFGS need the curvature condition because it guarantees that the curvature estimate stays positive, which keeps the approximate Hessian positive definite. The Goldstein conditions can exclude every minimizer of phi, so they are less suited to quasi-Newton updates.

Main line search algorithms

Several algorithms implement these conditions, and they differ mainly in how many evaluations they spend and how robust they are on difficult objectives. Backtracking is the simplest: start with a full step and multiply it by a contraction factor, usually between 0.3 and 0.8, until the Armijo condition holds.

AlgorithmInformation usedTypical cost per iterationStrengths and weaknesses
Backtracking ArmijoFunction values1 to 5 evaluationsSimple and robust; may accept short steps
Bracketing and zoomValues and gradients2 to 10 evaluationsSatisfies strong Wolfe; more code
More-ThuenteValues and gradientsUsually 1 to 3 evaluationsReliable safeguarded cubic interpolation
Hager-ZhangValues and gradientsUsually 1 to 3 evaluationsApproximate Wolfe; tolerant of rounding error
Golden-section searchFunction values onlyMany evaluationsExact-style search without derivatives
Line search algorithms and their trade-offs

Production solvers usually rely on safeguarded polynomial interpolation: they fit a quadratic or cubic model to the known values and slopes of phi, jump to its minimizer, and clip the result to a safe interval. The More-Thuente method is the default in many L-BFGS implementations, while the Hager-Zhang method is valued when floating-point noise makes the standard Armijo test unreliable near convergence.

Line search compared with other step-size strategies

Line search is one of several ways to control step size, and the right choice depends on gradient noise, problem size and evaluation cost. The main alternative in classical optimization is the trust region method, which first fixes a radius and then chooses both direction and length inside it. Machine learning practice adds fixed learning rates, schedules and adaptive optimizers.

StrategyHow the step is setBest suited toMain limitation
Line searchSearched along a fixed directionDeterministic, smooth objectivesExtra evaluations per iteration
Trust regionBounded by an adaptive radiusIll-conditioned or indefinite HessiansSubproblem solve at every step
Fixed learning rateChosen once by the userSimple stochastic trainingNeeds manual tuning
Learning rate scheduleDecays or warms up over timeLarge-scale deep learningNo per-step guarantee of decrease
Adaptive optimizersScaled per parameter from gradient historyNoisy, high-dimensional gradientsNo sufficient decrease test
Step-size strategies in optimization for AI

Line search and trust region methods both give global convergence guarantees for smooth problems under standard assumptions, whereas learning rates in stochastic gradient descent guarantee convergence only in expectation and only with suitable decay. Research on stochastic line search, which applies an Armijo test to the current mini-batch, shows promising results for overparameterized models, but it is not yet a standard default.

Limitations and common mistakes

Most line search failures come from inconsistent inputs rather than from the algorithm itself. A solver that reports “line search failed” usually signals a gradient that does not match the function, a direction that is not a descent direction, or numerical precision exhausted near the optimum.

  • Incorrect gradients: an analytic or automatic gradient that disagrees with the objective breaks every acceptance test; verify with finite differences.
  • Mini-batch noise: evaluating phi on different batches makes values incomparable, so the Armijo test becomes random.
  • Poor scaling: badly scaled variables produce tiny accepted steps; normalize features or precondition the problem.
  • Wrong initial step: starting gradient descent at alpha = 1 on a poorly scaled problem wastes many backtracking evaluations.
  • Nonsmooth objectives: L1 penalties or ReLU kinks can violate the curvature condition; prefer proximal or subgradient methods.

A further cost is computational: each trial step requires at least one full objective evaluation, which can dominate run time when the objective involves a large dataset. For that reason, line search is most attractive when evaluations are cheap relative to computing a good direction, as in full-batch quasi-Newton training.

Explained without jargon

Imagine walking downhill in fog. You can feel which way the ground slopes, but you cannot see how far the slope continues. Line search decides how long each stride should be. You try a stride, check whether you are lower than before, and shorten it if you are not.

The direction comes from another rule. The line search only handles the distance. A good stride saves effort and avoids overshooting the bottom of the valley. This is why many fitting programs in machine learning use it behind the scenes.

A typical use case

A data science team fits a logistic regression model with L2 regularization on 2 million customer records and 400 features to predict subscription churn. The library uses L-BFGS with a More-Thuente line search and strong Wolfe constants of c1 = 1e-4 and c2 = 0.9. Because the full dataset fits in memory, each objective and gradient evaluation takes about 0.8 seconds.

In most iterations, the first trial step of length one is accepted, so the line search adds almost no overhead. During the first few iterations, before the curvature estimate has settled, the search shortens the step two or three times. The solver converges in about 60 iterations and 75 evaluations, compared with several thousand iterations for plain gradient descent with a hand-tuned learning rate.

When an engineer later adds a custom feature transformation with a coding error in its derivative, the solver stops with a line search failure after three iterations. A finite-difference gradient check reveals the mismatch within minutes, and the corrected model trains normally.