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.
- Compute a descent direction p from the outer algorithm.
- Propose an initial step, often alpha = 1 for Newton-type methods.
- Evaluate the objective, and the gradient if required, at the trial point.
- Accept the step if the chosen conditions hold; otherwise shrink or interpolate.
- 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.
| Condition | What it enforces | Typical constants | Main use |
|---|---|---|---|
| Armijo | Sufficient decrease in f | c1 between 1e-4 and 1e-3 | Backtracking with gradient or Newton steps |
| Wolfe | Sufficient decrease plus curvature | c1 = 1e-4, c2 = 0.9 | Quasi-Newton methods such as BFGS |
| Strong Wolfe | Decrease plus bounded absolute slope | c1 = 1e-4, c2 = 0.1 to 0.9 | Nonlinear conjugate gradient, L-BFGS |
| Goldstein | Step neither too long nor too short | c between 0 and 0.5 | Newton-type methods, rarely quasi-Newton |
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.
| Algorithm | Information used | Typical cost per iteration | Strengths and weaknesses |
|---|---|---|---|
| Backtracking Armijo | Function values | 1 to 5 evaluations | Simple and robust; may accept short steps |
| Bracketing and zoom | Values and gradients | 2 to 10 evaluations | Satisfies strong Wolfe; more code |
| More-Thuente | Values and gradients | Usually 1 to 3 evaluations | Reliable safeguarded cubic interpolation |
| Hager-Zhang | Values and gradients | Usually 1 to 3 evaluations | Approximate Wolfe; tolerant of rounding error |
| Golden-section search | Function values only | Many evaluations | Exact-style search without derivatives |
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.
| Strategy | How the step is set | Best suited to | Main limitation |
|---|---|---|---|
| Line search | Searched along a fixed direction | Deterministic, smooth objectives | Extra evaluations per iteration |
| Trust region | Bounded by an adaptive radius | Ill-conditioned or indefinite Hessians | Subproblem solve at every step |
| Fixed learning rate | Chosen once by the user | Simple stochastic training | Needs manual tuning |
| Learning rate schedule | Decays or warms up over time | Large-scale deep learning | No per-step guarantee of decrease |
| Adaptive optimizers | Scaled per parameter from gradient history | Noisy, high-dimensional gradients | No sufficient decrease test |
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.