AI Wiki中文/EN

Newton's method

牛顿法

Use curvature to propose a step and backtracking to check the real decrease.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Curvature can suggest a very large step

Gradient descent uses the local slope to choose a direction. Newton’s method also asks how quickly that slope changes. On a quadratic bowl, the slope and curvature together identify the minimizer in one exact step. Away from a quadratic model, that same confidence can be misplaced.

Our example minimizes exp(x)−x−1. Its unique minimum is at zero, but starting from −4 gives a Newton proposal far to the right, where the exponential is enormous. Backtracking reduces the step until the actual objective decreases sufficiently. The direction comes from the local model; the accepted distance comes from checking the real function.

Read Hessians, Taylor expansions and gradient descent before the multivariable derivation.

Minimize the quadratic model by solving a system

At the current point x, let g be the gradient and H the Hessian of a twice differentiable objective. Its second-order local model is:

mx(p)=f(x)+gTp+12pTHp,HpN=−g.m_x(p)=f(x)+g^Tp+\frac12p^THp,\qquad Hp_N=-g.

If H is positive definite, the system has a unique solution and p_N minimizes that quadratic model. In an implementation, solve the linear system rather than forming H’s inverse. The directional slope obeys:

gTpN=−gTH−1g<0when g≠0 and H≻0.g^Tp_N=-g^TH^{-1}g<0\quad\text{when }g\ne0\text{ and }H\succ0.

Thus it is a descent direction under these assumptions. This does not say that a unit step decreases the original nonlinear function. The unconstrained minimization slides, Newton-step section connect the step to a quadratic approximation and curvature. Convex Optimization §9.5 develops the algorithm and its convergence analysis.

Backtracking tests the actual objective

Start with step size t=1 and repeatedly multiply it by β in (0,1) until the sufficient-decrease test holds:

f(x+tpN)≤f(x)+αt gTpN,0<α<12.f(x+tp_N)\le f(x)+\alpha t\,g^Tp_N,\qquad 0<\alpha<\frac12.

Our program uses α=1/4 and β=1/2. Since the slope is negative, the right side asks for a decrease proportional to the proposed first-order change. For a smooth function and a genuine descent direction, sufficiently small steps satisfy this test in exact arithmetic. A practical implementation also needs finite-value checks, a stopping condition and explicit failure limits.

Derive the scalar example

The objective, derivatives and Newton proposal are:

f(x)=ex−x−1,f′(x)=ex−1,f′′(x)=ex>0,pN=−(1−e−x).f(x)=e^x-x-1,\qquad f'(x)=e^x-1,\qquad f''(x)=e^x>0,\qquad p_N=-(1-e^{-x}).

The inequality exp(x)≥1+x gives f(x)≥0 with equality only at zero. At x=−4, p_N=exp(4)−1 is about 53.6, so the unit proposal is near 49.6. The local curvature was small on the left; it is not an accurate model of the entire proposed jump across the exponential’s steep region.

Near a nondegenerate minimum, with a locally Lipschitz Hessian and a sufficiently close starting point, full Newton steps have quadratic local error convergence. That rate concerns a local regime under assumptions, not the whole run or every objective. Damping can help reach that regime. For an exact positive-definite quadratic, the local model is the function itself and one exact full step reaches its minimizer.

Reject the disastrous full proposal, then converge

Run the complete Python 3.12 standard-library program. Starting values must be finite real numbers in [−10,10]; booleans are rejected. The stopping tolerance must lie between 10⁻¹² and 10⁻⁴. The solver stops on the absolute gradient of this specific scalar objective, with at most 40 accepted iterations and 60 trial steps per iteration.

expm1(x) computes exp(x)−1 without the direct near-zero subtraction. Trial overflow is treated as an unacceptable infinite objective and causes backtracking. Neither an overflow nor a used-up budget is reported as convergence.

import math


def loss(x):
    try:
        return math.expm1(x)-x
    except OverflowError:
        return math.inf


def damped_newton(start,tolerance=1e-10):
    if type(start) not in (int,float) or not math.isfinite(start) or not -10 <= start <= 10:
        raise ValueError('finite real starting value in [-10,10] required')
    if type(tolerance) not in (int,float) or not math.isfinite(tolerance) or not 1e-12 <= tolerance <= 1e-4:
        raise ValueError('tolerance in [1e-12,1e-4] required')
    x=float(start);rows=[]
    for iteration in range(41):
        gradient=math.expm1(x)
        if abs(gradient) <= tolerance:
            return x,rows
        if iteration == 40:
            raise RuntimeError('iteration budget exhausted')
        direction=-gradient/math.exp(x)
        old_loss=loss(x);slope=gradient*direction;step=1.0
        for _ in range(60):
            candidate=x+step*direction;candidate_loss=loss(candidate)
            if math.isfinite(candidate_loss) and candidate_loss <= old_loss+0.25*step*slope:
                break
            step*=0.5
        else:
            raise RuntimeError('line search failed')
        rows.append({'x':x,'next_x':candidate,'loss':old_loss,'next_loss':candidate_loss,
                     'slope':slope,'step':step})
        x=candidate


if __name__ == '__main__':
    start=-4.0
    full_step=start-math.expm1(start)/math.exp(start)
    x,rows=damped_newton(start)
    print('full Newton step increases loss:',loss(full_step)>loss(start))
    print('first accepted step:',rows[0]['step'])
    print('iterations:',len(rows))
    print('final |gradient| <= 1e-10:',abs(math.expm1(x))<=1e-10)

Output from the recorded run:

full Newton step increases loss: True
first accepted step: 0.0625
iterations: 6
final |gradient| <= 1e-10: True

The first accepted fraction is 1/16. The full proposal raises loss, while accepted steps satisfy the recorded sufficient-decrease condition. The result meets the gradient tolerance. This is a small floating-point experiment with an analytic minimizer; it is not a universal iteration-count guarantee.

In d dimensions, a dense Hessian stores O(d²) entries and a generic dense factorization costs O(d³) arithmetic, excluding derivative evaluation. Hessian-vector products and iterative linear solves can reduce storage for large models, while quasi-Newton methods approximate curvature. This scalar implementation has constant-cost derivative evaluations; line search adds a variable number of objective evaluations.

Curvature can be singular or point the wrong way

An indefinite Hessian does not guarantee descent. For f(x)=−x², the Newton step heads toward the stationary maximum at zero. A singular Hessian may make the Newton system unsolvable or nonunique. Curvature modification, trust-region methods or other safeguarded strategies address these situations; simply inserting a matrix inverse does not.

Newton’s method for solving a root F(x)=0 uses F and its derivative. Newton optimization applies that idea to the gradient of an objective, which is why the Hessian appears. Finding a stationary point is not the same as finding a global minimum.

Function values near the minimum can lose precision through subtraction even when expm1 helps the derivatives. Residual tolerances should reflect the objective’s scale and parameterization. Our code’s limits and tolerance are declared for this demonstration, not recommended defaults for arbitrary models or mixed-precision training.

Separate the direction, the distance and the claim

  1. Why can the Newton direction be a descent direction while the unit step increases loss?

Answer 1: A negative directional derivative describes sufficiently small movement. The quadratic approximation can become inaccurate across a large step; the actual function may rise before reaching the proposed endpoint.

  1. At x=−4 in this example, what is the unscaled Newton direction?

Answer 2: exp(4)−1, about 53.6. The full candidate is near 49.6, far beyond the region whose curvature was measured.

  1. For f(x)=(x−3)²/2, what does one exact full Newton step do from any starting x?

Answer 3: The gradient is x−3 and the Hessian is 1, so the step is 3−x and lands exactly at 3.

  1. Does a zero gradient after Newton optimization prove a global minimum for every objective?

Answer 4: No. It can be a maximum or saddle. For −x², zero is stationary and is a maximum; curvature and problem-level assumptions still matter.

Spend curvature work where it helps

The book and slides provide the quadratic-model view and line-search framework. The exponential example makes the need to check a full proposal visible with a single variable. Inspecting both the step model and the actual decrease is more informative than reporting only a final objective.

As an extension, compare gradient descent and damped Newton on this objective using function and derivative evaluation counts, not just iterations. Then move to a positive-definite two-dimensional quadratic and solve the Newton system directly. Keep any timing experiment separate from the mathematical one-step property.

Make a prediction, then check

Does a Newton descent direction guarantee that the full unit step decreases a nonlinear objective?

Choose one answer

Learning objectives

  • Derive a Newton direction as a linear solve.
  • Distinguish descent direction, accepted step and local convergence rate.

Prerequisites & connections

Explore related knowledge →

References

  1. Convex Optimization
    Stephen Boyd; Lieven Vandenberghe · 2004
  2. Convex Optimization — Unconstrained minimization lecture slides
    Stephen Boyd; Lieven Vandenberghe; Parth Nobel

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, derivations, literal or exact computational checks, and bilingual review; not independent human or second-agent peer review.

  • Single-agent authored technical review: source locations, stated domains and assumptions, derivations, literal or exact reference cases and matching bilingual programs/exercises. Not independent human or second-agent peer review.
  • Four focused tests passed on CPython 3.12.4. Exact Fraction examples are used except for the explicitly floating-point damped Newton experiment. Strict bilingual MDX/KaTeX rendering gives four equations, six anchors and four answers per language; repository publication checks are recorded separately.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.