Module contents
Lesson 13 of 27Core 120 min

Newton's method, trust regions and Gauss-Newton

Derive Newton's method by minimizing the complete quadratic model and prove its local quadratic convergence and affine invariance. Study globalization by damped line search or trust regions, and exploit nonlinear least-squares structure with Gauss-Newton and Levenberg-Marquardt.

After this lesson you can

  • Derive the Newton step and decrement and prove affine invariance.
  • Prove local quadratic convergence when the Hessian is Lipschitz and nonsingular at the optimum.
  • Implement damped Newton with backtracking and recognize its damped and quadratic phases.
  • Solve the trust-region subproblem with the Cauchy point and dogleg method, adjusting the radius using the reduction ratio.
  • Implement Gauss-Newton and Levenberg-Marquardt for curve fitting and relate them to Newton.

Before you start

Motivation: use curvature to arrive in a handful of iterations

Lesson 7’s gradient descent uses one piece of information: which way the function decreases. A step η\eta to be chosen or searched determines how far to move, tying speed to the condition number. On Rosenbrock, with Armijo backtracking from (−1.2,1)(-1.2, 1), gradient descent needs over thirteen thousand iterations to bring the gradient norm below 10−610^{-6} (the cell below counts them). Damped Newton takes about twenty. For logistic regression with five variables and four hundred examples, seven steps exhaust machine precision.

The difference is which information is used. The gradient gives a direction in which ff decreases; the Hessian gives curvature in every direction, exactly what is missing to decide how far to move. In a parabola f(x)=12hx2−bxf(x) = \tfrac12 h x^2 - bx, gradient hx−bhx - b divided by curvature hh gives the exact minimum from any point. In multiple dimensions Newton’s method performs this division in each Hessian eigenvector direction at once: gradient descent with a different step, inverse curvature, in each direction.

This idea underlies much of what you will use:

  • Logistic regression and generalized linear models are fitted with Newton (in statistics, IRLS: iteratively reweighted least squares). With few variables and lots of data, seven passes through the data beat thousands of gradient steps.
  • The Laplace approximation in probabilistic models uses the Hessian at the mode, the same object Newton constructs.
  • Interior-point methods apply Newton to a succession of barrier problems.
  • Bundle adjustment, SLAM and physical-model calibration are nonlinear least-squares problems solved by Gauss-Newton and Levenberg-Marquardt, the last two sections.
  • Large-scale optimizers (quasi-Newton and inexact Newton, later Adam and preconditioners) try to obtain part of this effect without its cost: O(n3)\bigO(n^3) per iteration.

The lesson proceeds through the Newton step as minimizer of a quadratic model, affine invariance, local quadratic convergence with proof, globalization (damped line search and trust regions), what to do when the Hessian is not positive definite, and the special structure of least squares. It ends with cost and code.

Intuition: jump to the model’s minimum

Around x\vb{x}, the second-order Taylor polynomial is the best quadratic approximation to ff. Newton minimizes it completely and jumps to the paraboloid’s minimum. In the figure, blue level curves are that paraboloid at the current iterate and pass through it; the purple circle marks its stationary point, the next iterate.

InteractiveJump to the model minimum
  • contours of ff
  • quadratic model at xk\vb{x}_k
  • stationary point of the model
  • iterates
  • step
  • minima of ff
iteration 0
At xk\vb{x}_k the model is a dome: the model’s “minimum” is a maximum.
Function
Method
Iteration kk0 of 5
f(xk)f(\vb{x}_k)156
∥∇f(xk)∥\norm{\nabla f(\vb{x}_k)}40.2
λmin⁡(∇2f)\lambda_{\min}(\hess f)−39.6
Decrement λ2\lambda^2−57
Change in ff on this step24.6
The model is a dome (λmin⁡(∇2f)=−39.6\lambda_{\min}(\hess f) = −39.6): Newton steps to its peak and ff rises 24.6. The decrement λ2=∇f⊤∇2f−1∇f\lambda^2 = \nabla f\T \hess f^{-1} \nabla f is negative.
Press ▶ to step through iterations. Blue curves are the quadratic model at current iterate xk\vb{x}_k (passing through it), and the orange arrow is the step. Start with Himmelblau and pure Newton: near the origin ff has a peak, the model is a dome, its stationary point is its peak and the step goes up. Where does it converge? Switch to Damped (Armijo backtracking with Hessian correction) and Trust (the teal circle is radius Δ\Delta; watch each step's ratio ρ\rho). Then try the convex function with pure Newton from (−1.4,1.1)(-1.4, 1.1): the model is a bowl everywhere, yet the jump lands far away. Drag x0\vb{x}_0 to find more cases.

Three things the figure shows, formalized in the rest of the lesson:

  1. With a convex model, the step reaches the model’s minimum, not necessarily that of ff. The farther from the optimum, the worse the model. In the convex function the jump from (−1.4,1.1)(-1.4, 1.1) lands almost ninety units away because the Hessian there is nearly singular (smallest eigenvalue 0.0090.009), dividing by a tiny number in that direction.
  2. With a nonconvex model, the model’s “minimum” does not exist. A dome’s stationary point is a maximum, and a saddle’s is not an extremum. Newton seeks zeros of the gradient, not minima.
  3. Two remedies both limit step length: shorten it along the Newton direction (line search), or first decide how much to trust the model and then choose direction (trust region).

Definition

The model gradient is ∇f+∇2f d\grad f + \hess f\,\vb{d}, zero at dN\vb{d}_N; since ∇2f≻0\hess f \succ 0 the model is strictly convex, so that stationary point is its unique minimum. Substituting, ∇f⊤dN=−λ2\grad f\T\vb{d}_N = -\lambda^2 and dN⊤∇2f dN=λ2\vb{d}_N\T\hess f\,\vb{d}_N = \lambda^2. Four frequently used facts follow:

  • What is gained. mx(0)−mx(dN)=12λ(x)2m_{\vb{x}}(\vb{0}) - m_{\vb{x}}(\vb{d}_N) = \tfrac12\lambda(\vb{x})^2: the squared decrement is twice the model’s predicted reduction. Near optimum it also estimates f(x)−f⋆f(\vb{x}) - f^\star and is the natural stopping criterion: 12λ2≤ε\tfrac12\lambda^2 \le \eps.
  • Descent direction. ∇f⊤dN=−λ2<0\grad f\T\vb{d}_N = -\lambda^2 < 0 if ∇f≠0\grad f \neq \vb{0} (descent direction). This holds only if ∇2f≻0\hess f \succ 0.
  • It is a norm. λ(x)2=dN⊤∇2f dN=∥dN∥∇2f2\lambda(\vb{x})^2 = \vb{d}_N\T\hess f\,\vb{d}_N = \norm{\vb{d}_N}_{\hess f}^2: step size measured in the curvature’s own metric. Thus it is independent of variable scaling (proved next).
  • It is Newton for equations. Minimizing ff requires solving F(x)=∇f(x)=0F(\vb{x}) = \grad f(\vb{x}) = \vb{0}. Newton’s method for equation systems (numerical methods lesson) uses xk+1=xk−F′(xk)−1F(xk)\vb{x}_{k+1} = \vb{x}_k - F'(\vb{x}_k)\inv F(\vb{x}_k), and here F′=∇2fF' = \hess f is the gradient’s Jacobian: the same algorithm. It inherits its blindness: it solves F=0F = \vb{0} without distinguishing minima, maxima and saddles.

If ff is quadratic, f(x)=12x⊤Ax−b⊤xf(\vb{x}) = \tfrac12\vb{x}\T\mat{A}\vb{x} - \vb{b}\T\vb{x} with A≻0\mat{A} \succ 0, the model is exact and Newton reaches the minimum, A−1b\mat{A}\inv\vb{b}, in one step from any point, regardless of κ(A)\kappa(\mat{A}). Compare gradient descent on quadratics, which needs on the order of κlog⁡(1/ε)\kappa\log(1/\eps) steps.

Affine invariance: why Newton ignores ill-conditioning

Gradient descent depends on coordinates. Stretch a variable tenfold and the function does not change, but the Hessian eigenvalues do, along with the largest stable step and iteration count. Newton does not notice. This distinguishes it from the first-order repertoire.

Proof

By the chain rule, ∇g(y)=A⊤∇f(x)\grad g(\vb{y}) = \mat{A}\T\grad f(\vb{x}) and ∇2g(y)=A⊤∇2f(x)A\hess g(\vb{y}) = \mat{A}\T\hess f(\vb{x})\mat{A}. Writing H=∇2f(x)\mat{H} = \hess f(\vb{x}) and using (A⊤HA)−1=A−1H−1A−⊤(\mat{A}\T\mat{H}\mat{A})\inv = \mat{A}\inv\mat{H}\inv\mat{A}^{-\T},

dNg(y)=−A−1H−1A−⊤A⊤∇f(x)=−A−1H−1∇f(x)=A−1dNf(x),\vb{d}_N^{g}(\vb{y}) = -\mat{A}\inv\mat{H}\inv\mat{A}^{-\T}\mat{A}\T\grad f(\vb{x}) = -\mat{A}\inv\mat{H}\inv\grad f(\vb{x}) = \mat{A}\inv\vb{d}_N^{f}(\vb{x}),

which is the first claim. For the decrement, ∇g⊤(∇2g)−1∇g=∇f⊤AA−1H−1A−⊤A⊤∇f=∇f⊤H−1∇f\grad g\T(\hess g)\inv\grad g = \grad f\T\mat{A}\mat{A}\inv\mat{H}\inv\mat{A}^{-\T}\mat{A}\T\grad f = \grad f\T\mat{H}\inv\grad f. The final claim follows by induction: Ayk+1+b=Ayk+b+AdNg(yk)=xk+dNf(xk)=xk+1\mat{A}\vb{y}_{k+1} + \vb{b} = \mat{A}\vb{y}_k + \vb{b} + \mat{A}\vb{d}_N^g(\vb{y}_k) = \vb{x}_k + \vb{d}_N^f(\vb{x}_k) = \vb{x}_{k+1}.

∎
InteractiveReparameterize the problem
Original space, f(x)f(\vb{x})
Reparameterized space, g(y)=f(Ay)g(\vb{y}) = f(\mat{A}\vb{y})
  • gradient in this space
  • gradient from the other space, mapped here
  • Newton in this space
  • Newton from the other space, mapped here (circles)
3.98
0.501
35°
Gradient iterations: in x\vb{x} and y\vb{y}24 and more than 80
Newton iterations: in x\vb{x} and y\vb{y}6 and 6
Distance between Newton pathsless than 1e-10
Distance between gradient paths1.1
κ(∇2)\kappa(\hess) at start, in x\vb{x} and y\vb{y}68.2 and 3180
Newton: both paths coincide (difference: less than 1e-10). Gradient descent: the path in y\vb{y}, mapped to x\vb{x}, deviates up to 1.1 from the original, and the iteration count changes from 24 to more than 80.
Left, original space of ff; right, reparameterized g(y)=f(Ay)g(\vb{y}) = f(\mat{A}\vb{y}) with A\mat{A} = rotation times axis stretches. Solid lines show each method in its own space. Dashed lines (gradient) and circles (Newton) are the other space's trajectory mapped with A\mat{A} or A−1\mat{A}\inv. Stretch an axis tenfold and rotate: right-hand contours become narrow oblique valleys and gradient descent zigzags or takes much longer, while Newton's circles land exactly on its points. Drag the start in either plane. Readouts give maximum distance between trajectories.

The figure uses damped Newton, not pure. No contradiction: Armijo backtracking only looks at ff values and directional derivative ∇f⊤d\grad f\T\vb{d}, both preserved: g(y+tdg)=f(x+tdf)g(\vb{y} + t\vb{d}^g) = f(\vb{x} + t\vb{d}^f) and ∇g⊤dg=∇f⊤df\grad g\T\vb{d}^g = \grad f\T\vb{d}^f. You prove this in the final proof exercise.

Consequences, from most practical to deepest:

  • The Hessian condition number does not govern Newton. Stretching, rotating or scaling variables does not change iterations (in exact arithmetic; floating-point linear solves do lose log⁡10κ(∇2f)\log_{10}\kappa(\hess f) digits, as any solve does). Feature normalization is unnecessary for Newton to converge, although useful for accurate solves.
  • The decrement λ\lambda is intrinsic, independent of coordinates. Thus 12λ2\tfrac12\lambda^2 is a reliable stopping criterion and gradient norm is not: ∥∇g∥=∥A⊤∇f∥\norm{\grad g} = \norm{\mat{A}\T\grad f} changes with A\mat{A}.
  • Gradient descent is Newton with the wrong Hessian. In y\vb{y} coordinates GD takes y+=y−ηA⊤∇f(x)\vb{y}_+ = \vb{y} - \eta\mat{A}\T\grad f(\vb{x}), i.e. x+=x−η AA⊤∇f(x)\vb{x}_+ = \vb{x} - \eta\,\mat{A}\mat{A}\T\grad f(\vb{x}). Reparameterization is preconditioning with P=AA⊤\mat{P} = \mat{A}\mat{A}\T. Newton corresponds to ideal preconditioner P=∇2f(x)−1\mat{P} = \hess f(\vb{x})\inv. The chapter on second-order methods and large-scale preconditioners (lesson 14, Adam in 20, geometry in 26) seeks to approach that P\mat{P} at reasonable cost.
  • What is not invariant is Euclidean analysis and regions. Constants μ\mu and MM of the next theorem change with A\mat{A}, although the algorithm does not. A trust region’s Euclidean ball is not invariant either: use a scaled norm ∥Dp∥≤Δ\norm{\mat{D}\vb{p}} \le \Delta. A complete affine-invariant analysis exists for Nesterov and Nemirovski’s self-concordant functions, returning in interior-point methods.

Local quadratic convergence

Now the property justifying the method: near a nondegenerate minimum, error is squared at every step.

Proof

Let x\vb{x} satisfy ∥e∥≤rˉ\norm{\vb{e}} \le \bar r, where e=x−x⋆\vb{e} = \vb{x} - \vb{x}^\star.

The Hessian is invertible and bounded. Since ∥∇2f(x)−∇2f(x⋆)∥2≤M∥e∥≤μ/2\norm{\hess f(\vb{x}) - \hess f(\vb{x}^\star)}_2 \le M\norm{\vb{e}} \le \mu/2, the smallest eigenvalue of ∇2f(x)\hess f(\vb{x}) is at least μ−μ/2=μ/2\mu - \mu/2 = \mu/2 (an eigenvalue moves by at most the perturbation norm). Thus ∇2f(x)≻0\hess f(\vb{x}) \succ 0 and ∥∇2f(x)−1∥2≤2/μ\norm{\hess f(\vb{x})\inv}_2 \le 2/\mu.

Step error. Since ∇f(x⋆)=0\grad f(\vb{x}^\star) = \vb{0}, the fundamental theorem of calculus on the segment connecting x⋆\vb{x}^\star to x\vb{x} (inside the ball) gives ∇f(x)=∫01∇2f(x⋆+te) e ⁣dt\grad f(\vb{x}) = \int_0^1 \hess f(\vb{x}^\star + t\vb{e})\,\vb{e}\dd t. Then

e+=e−∇2f(x)−1∇f(x)=∇2f(x)−1[∇2f(x)e−∇f(x)]=∇2f(x)−1∫01[∇2f(x)−∇2f(x⋆+te)]e ⁣dt.\vb{e}_+ = \vb{e} - \hess f(\vb{x})\inv\grad f(\vb{x}) = \hess f(\vb{x})\inv\Big[\hess f(\vb{x})\vb{e} - \grad f(\vb{x})\Big] = \hess f(\vb{x})\inv\int_0^1\big[\hess f(\vb{x}) - \hess f(\vb{x}^\star + t\vb{e})\big]\vb{e}\dd t.

The bound. By Lipschitz continuity, ∥∇2f(x)−∇2f(x⋆+te)∥≤M(1−t)∥e∥\norm{\hess f(\vb{x}) - \hess f(\vb{x}^\star + t\vb{e})} \le M(1 - t)\norm{\vb{e}}, and ∫01M(1−t) ⁣dt=M/2\int_0^1 M(1-t)\dd t = M/2, so the integral has norm at most M2∥e∥2\tfrac M2\norm{\vb{e}}^2. With the inverse Hessian bound, ∥e+∥≤2μ⋅M2∥e∥2=Mμ∥e∥2\norm{\vb{e}_+} \le \tfrac2\mu\cdot\tfrac M2\norm{\vb{e}}^2 = \tfrac M\mu\norm{\vb{e}}^2.

Induction. If ∥e∥≤μ/(2M)\norm{\vb{e}} \le \mu/(2M), then ∥e+∥≤Mμ∥e∥⋅∥e∥≤12∥e∥\norm{\vb{e}_+} \le \tfrac M\mu\norm{\vb{e}}\cdot\norm{\vb{e}} \le \tfrac12\norm{\vb{e}}: the new iterate stays in the ball and the bound applies again. Let ϱk=Mμ∥ek∥\varrho_k = \tfrac M\mu\norm{\vb{e}_k}. Then ϱk+1≤ϱk2\varrho_{k+1} \le \varrho_k^2 and ϱ0≤12\varrho_0 \le \tfrac12, so ϱk≤ϱ02k≤2−2k\varrho_k \le \varrho_0^{2^k} \le 2^{-2^k}.

∎

Three observations about what this says and does not say:

  • It is very fast, with a practical effect. With ϱ0≤12\varrho_0 \le \tfrac12, ϱ5≤2−32≈2×10−10\varrho_5 \le 2^{-32} \approx 2\times10^{-10} and ϱ6≤2−64\varrho_6 \le 2^{-64}, below machine precision. The quadratic phase’s iteration count grows as log⁡2log⁡2(1/ε)\log_2\log_2(1/\eps), almost constant: six or seven steps suffice for double precision.
  • Radius μ/(2M)\mu/(2M) is a guarantee, not a limit. It is conservative. For 1+x2\sqrt{1 + x^2} Newton gives x+=−x3x_{+} = -x^3 and converges iff ∣x0∣<1\abs{x_0} < 1 (cubically, too), whereas the theorem, with μ=f′′(0)=1\mu = f''(0) = 1 and M=max⁡∣f′′′∣≈0.859M = \max\abs{f'''} \approx 0.859, guarantees radius μ/(2M)≈0.58\mu/(2M) \approx 0.58. The actual convergence region may be much larger, with a complicated boundary (even fractal, already in one variable).
  • If ∇2f(x⋆)\hess f(\vb{x}^\star) is singular, this is lost. For f(x)=x4f(x) = x^4, x+=23xx_+ = \tfrac23 x: linear convergence at rate 23\tfrac23. The minimum is degenerate and its Hessian is 00, exactly what the theorem excludes.
InteractiveCorrect digits per iteration
  • Gradient (Armijo)
  • Pure Newton
  • Damped Newton
kGrad.PureDampedt×
00.00.00.01
10.00.00.00.13
20.00.00.01
30.00.30.01
40.01.30.01
50.05.00.00.25
60.010.70.01
70.0≥160.01
80.0≥160.01
90.0≥160.00.5
100.0≥160.01
110.0≥160.01
120.0≥160.21
130.0≥160.20.5
140.0≥160.41
150.0≥160.511.64
160.0≥160.911.30
170.0≥161.111.78
180.0≥162.011.44
190.0≥162.911.90
200.0≥165.611.77
210.0≥169.91
220.0≥16≥16·
230.0≥16≥16·
Digits =−log⁡10∥xk−x⋆∥= -\log_{10}\norm{\vb{x}_k - \vb{x}^\star}. Shading: iterations with t<1t < 1. “×”: digits at k+1k+1 divided by digits at kk (damped Newton).
Problem
1
25
Iterations to 10 digits: gradientmore than 25
Iterations to 10 digits: pure Newton6
Iterations to 10 digits: damped22
Length of damped phase14
Newton’s damped phase lasts 14 iterations (4 with shortened steps, t<1t < 1). It then accepts t=1t = 1 and digits double: the quadratic phase.
Correct digits for gradient descent with Armijo, pure Newton and damped Newton, measured as −log⁡10∥xk−x⋆∥-\log_{10}\norm{\vb{x}_k - \vb{x}^\star}. In the table, column '×' divides digits at iteration k+1k+1 by those at kk: in the quadratic phase it approaches 22. Rosenbrock shows a long damped phase (shaded rows, t<1t < 1), then digits double. Move the start farther away with the distance control to lengthen the first phase. In logistic regression convexity means Newton barely needs damping. For 1+x2\sqrt{1+x^2}, a factor of 1.251.25 brings the start to ∣x0∣=1\abs{x_0} = 1: pure Newton changes from cubic convergence to divergence.

Damped Newton: phases and global behavior

The theorem is local: it requires starting inside a ball. Outside it, pure Newton can make three mistakes, all in one variable:

  • Move away. For f(x)=1+x2f(x) = \sqrt{1 + x^2}, f′(x)=x/1+x2f'(x) = x/\sqrt{1 + x^2} and f′′(x)=(1+x2)−3/2f''(x) = (1 + x^2)^{-3/2}, so x+=x−x(1+x2)=−x3x_{+} = x - x(1 + x^2) = -x^3. If ∣x0∣>1\abs{x_0} > 1 iterates grow without bound although ff is smooth and convex; with ∣x0∣=1\abs{x_0} = 1 they oscillate between 11 and −1-1.
  • Leave the domain, as in x−ln⁡xx - \ln x.
  • Cycle. For f(x)=14x4−x2+2xf(x) = \tfrac14x^4 - x^2 + 2x, f′(x)=x3−2x+2f'(x) = x^3 - 2x + 2 and f′′(x)=3x2−2f''(x) = 3x^2 - 2. From x0=0x_0 = 0 the sequence is 0→1→0→1→⋯0 \to 1 \to 0 \to 1 \to \cdots forever.

The minimal remedy is that of any descent method: accept the step only if it improves ff sufficiently; otherwise shorten it.

Always start with t=1t = 1 because this makes Newton what it is: if the full step is acceptable, take it. The first question is when it is accepted; the answer explains the two phases.

Proof

With an MM-Lipschitz Hessian, the second-order Taylor polynomial has error at most M6∥d∥3\tfrac M6\norm{\vb{d}}^3 (Taylor remainder): f(x+d)≤mx(d)+M6∥d∥3f(\vb{x} + \vb{d}) \le m_{\vb{x}}(\vb{d}) + \tfrac M6\norm{\vb{d}}^3. For d=dN\vb{d} = \vb{d}_N, mx(dN)=f(x)−12λ2m_{\vb{x}}(\vb{d}_N) = f(\vb{x}) - \tfrac12\lambda^2. Also λ2=d⊤∇2f d≥μ∥d∥2\lambda^2 = \vb{d}\T\hess f\,\vb{d} \ge \mu\norm{\vb{d}}^2, i.e. ∥d∥≤λ/μ\norm{\vb{d}} \le \lambda/\sqrt\mu. Then

f(x+dN)≤f(x)−12λ2+M6μ3/2λ3.f(\vb{x} + \vb{d}_N) \le f(\vb{x}) - \tfrac12\lambda^2 + \frac{M}{6\mu^{3/2}}\lambda^3.

Armijo with t=1t = 1 requires f(x+dN)≤f(x)−αλ2f(\vb{x} + \vb{d}_N) \le f(\vb{x}) - \alpha\lambda^2, which holds if M6μ3/2λ≤12−α\tfrac{M}{6\mu^{3/2}}\lambda \le \tfrac12 - \alpha, the hypothesis.

∎

The full result for strongly convex functions is proved in Boyd and Vandenberghe (Convex Optimization, section 9.5.3): with μI⪯∇2f\mu\mat{I} \preceq \hess f and MM-Lipschitz ∇2f\hess f, constants η,γ>0\eta, \gamma > 0 exist depending on μ\mu, MM, an upper Hessian bound, and α\alpha and β\beta, such that

  • Damped phase: if ∥∇f(xk)∥≥η\norm{\grad f(\vb{x}_k)} \ge \eta, then f(xk+1)−f(xk)≤−γf(\vb{x}_{k+1}) - f(\vb{x}_k) \le -\gamma, generally with tk<1t_k < 1;
  • Quadratic phase: if ∥∇f(xk)∥<η\norm{\grad f(\vb{x}_k)} < \eta, then tk=1t_k = 1 and ∥∇f(xk+1)∥≤M2μ2∥∇f(xk)∥2\norm{\grad f(\vb{x}_{k+1})} \le \tfrac{M}{2\mu^2}\norm{\grad f(\vb{x}_k)}^2, continuing thereafter.

Total iterations are bounded by (f(x0)−f⋆)/γ+log⁡2log⁡2(ε0/ε)(f(\vb{x}_0) - f^\star)/\gamma + \log_2\log_2(\eps_0/\eps): one term depends on starting distance, the other is almost constant. The proposition above explains the second phase (why t=1t = 1 is accepted); see it in the digits figure: shaded rows are the damped phase, then t=1t = 1 and digits double. Boyd and Vandenberghe’s γ\gamma and η\eta are not affine invariant although the algorithm is: self-concordant analysis gives a bound with universal constants.

Indefinite Hessians: modify the Hessian or trust the model

Everything above assumes ∇2f≻0\hess f \succ 0. For nonconvex functions that can fail, breaking three things. The quadratic model has no minimum, so the Newton step points toward a maximum or saddle. The direction may not descend: ∇f⊤dN=−∇f⊤∇2f−1∇f\grad f\T\vb{d}_N = -\grad f\T\hess f\inv\grad f can be positive (always so if ∇2f≺0\hess f \prec 0 and ∇f≠0\grad f \neq \vb{0}), making Armijo backtracking inappropriate: for small tt, ff rises along dN\vb{d}_N and the condition always fails, so the loop either never terminates or accepts a long step that may even raise ff (with ∇f⊤d>0\grad f\T\vb{d} > 0 Armijo’s right side exceeds f(x)f(\vb{x})). Iterates may also converge to a critical point that is not a minimum, as in figure 1 with Himmelblau.

There are two solution families. The first fixes the Hessian.

Modify the Hessian

Replace ∇2f\hess f by ∇2f+τI\hess f + \tau\mat{I} with τ≥0\tau \ge 0 as small as possible while positive definite. The standard method uses Cholesky as a test (Nocedal and Wright algorithm 3.3): try factoring H+τI\mat{H} + \tau\mat{I}, with τ=0\tau = 0 if all diagonals are positive and τ=−min⁡ihii+β\tau = -\min_i h_{ii} + \beta otherwise; on failure double τ\tau and repeat. The step is d=−(H+τI)−1∇f\vb{d} = -(\mat{H} + \tau\mat{I})\inv\grad f and always descends, since ∇f⊤d=−∇f⊤(H+τI)−1∇f<0\grad f\T\vb{d} = -\grad f\T(\mat{H} + \tau\mat{I})\inv\grad f < 0. Code inverts nothing: one Cholesky factorization and two triangular substitutions, with shift τ\tau like the Cholesky stability “jitter”. This is implemented in the next cell and called “Hessian correction” in figure 1.

What matters is the form of d(τ)\vb{d}(\tau). With τ=0\tau = 0 it is Newton. As τ→∞\tau \to \infty, (H+τI)−1≈τ−1I(\mat{H} + \tau\mat{I})\inv \approx \tau\inv\mat{I} and d≈−∇f/τ\vb{d} \approx -\grad f/\tau: a gradient step of size 1/τ1/\tau. The shift interpolates between Newton and gradient descent, step length shrinking as τ\tau grows. This is exactly the same set of steps described by trust regions and Levenberg-Marquardt. A finer alternative replaces Hessian eigenvalues λi\lambda_i by max⁡(∣λi∣,δ)\max(\abs{\lambda_i}, \delta) (as in Dauphin et al.’s 2014 “saddle-free” Newton, seen in lesson 23) and uses the negative-curvature direction to escape.

Trust the model only as far as possible

The second family changes the approach. Instead of fixing direction and searching for length, first decide how much to trust the model, then choose the best step within that radius. This is the trust region.

Trust regions

The quadratic model mk(p)=fk+gk⊤p+12p⊤Bkpm_k(\vb{p}) = f_k + \vb{g}_k\T\vb{p} + \tfrac12\vb{p}\T\mat{B}_k\vb{p} approximates ff well near xk\vb{x}_k and poorly far away. Declare a radius Δk\Delta_k within which to trust it, solve the model there and adjust the radius based on the result.

Compare line search: it chooses direction first, then distance; a trust region first chooses how far to move, Δ\Delta, then the best direction under that limit. This solves the ascent-direction problem: a nonconvex model does have a minimum inside a ball.

What the subproblem solution satisfies

Proof

For any p\vb{p}, m^(p)=m(p)+λ2∥p∥2=g⊤p+12p⊤(B+λI)p\hat m(\vb{p}) = m(\vb{p}) + \tfrac\lambda2\norm{\vb{p}}^2 = \vb{g}\T\vb{p} + \tfrac12\vb{p}\T(\mat{B} + \lambda\mat{I})\vb{p} is convex because B+λI⪰0\mat{B} + \lambda\mat{I} \succeq 0, and its gradient g+(B+λI)p\vb{g} + (\mat{B} + \lambda\mat{I})\vb{p} vanishes at p⋆\vb{p}^\star. Hence p⋆\vb{p}^\star minimizes m^\hat m on all Rn\R^n: m(p)+λ2∥p∥2≥m(p⋆)+λ2∥p⋆∥2m(\vb{p}) + \tfrac\lambda2\norm{\vb{p}}^2 \ge m(\vb{p}^\star) + \tfrac\lambda2\norm{\vb{p}^\star}^2. By complementary slackness, λ∥p⋆∥2=λΔ2\lambda\norm{\vb{p}^\star}^2 = \lambda\Delta^2, so m(p)≥m(p⋆)+λ2(Δ2−∥p∥2)≥m(p⋆)m(\vb{p}) \ge m(\vb{p}^\star) + \tfrac\lambda2(\Delta^2 - \norm{\vb{p}}^2) \ge m(\vb{p}^\star) for all p\vb{p} with ∥p∥≤Δ\norm{\vb{p}} \le \Delta.

∎

Two readings. If B≻0\mat{B} \succ 0 and the Newton step fits in the ball, λ=0\lambda = 0 and p⋆\vb{p}^\star is the Newton step: near the optimum, where the step is short, the region does not interfere. Otherwise the step is on the boundary and is p(λ)=−(B+λI)−1g\vb{p}(\lambda) = -(\mat{B} + \lambda\mat{I})\inv\vb{g} for λ\lambda giving ∥p(λ)∥=Δ\norm{\vb{p}(\lambda)} = \Delta. This is the preceding section’s shift τ\tau family with τ=λ\tau = \lambda. Decomposing g\vb{g} into eigenvectors of B\mat{B} with eigenvalues λi\lambda_i, ∥p(λ)∥2=∑igi2/(λi+λ)2\norm{\vb{p}(\lambda)}^2 = \sum_i g_i^2/(\lambda_i + \lambda)^2 decreases with λ\lambda, so each radius Δ\Delta has a unique λ\lambda. As Δ\Delta shrinks the step rotates from Newton toward steepest descent: p(λ)≈−g/λ\vb{p}(\lambda) \approx -\vb{g}/\lambda for large λ\lambda. There is a “hard case” when g\vb{g} is orthogonal to the eigenvector of smallest eigenvalue λ1≤0\lambda_1 \le 0 and the radius exceeds the limit of ∥p(λ)∥\norm{\vb{p}(\lambda)} as λ→−λ1\lambda \to -\lambda_1: no λ\lambda in the family reaches the boundary, and the solution is p(−λ1)\vb{p}(-\lambda_1) plus the multiple of the λ1\lambda_1 eigenvector that reaches ∥p∥=Δ\norm{\vb{p}} = \Delta; the figure’s code explicitly handles it.

The Cauchy point and dogleg

Solving the exact subproblem costs several factorizations. Two cheap approximations suffice to guarantee convergence.

The Cauchy point minimizes the model on the steepest-descent segment inside the region: pC=−τ Δ∥g∥g\vb{p}^C = -\tau\,\tfrac{\Delta}{\norm{\vb{g}}}\vb{g}, with τ=1\tau = 1 if g⊤Bg≤0\vb{g}\T\mat{B}\vb{g} \le 0 and τ=min⁡{∥g∥3/(Δ g⊤Bg), 1}\tau = \min\{\norm{\vb{g}}^3/(\Delta\,\vb{g}\T\mat{B}\vb{g}),\,1\} otherwise. It is a gradient step with optimal bounded length.

Proof

Three cases. If g⊤Bg≤0\vb{g}\T\mat{B}\vb{g} \le 0, pC=−Δg/∥g∥\vb{p}^C = -\Delta\vb{g}/\norm{\vb{g}} and m(0)−m(pC)=Δ∥g∥−Δ22∥g∥2g⊤Bg≥Δ∥g∥m(\vb{0}) - m(\vb{p}^C) = \Delta\norm{\vb{g}} - \tfrac{\Delta^2}{2\norm{\vb{g}}^2}\vb{g}\T\mat{B}\vb{g} \ge \Delta\norm{\vb{g}}. If g⊤Bg>0\vb{g}\T\mat{B}\vb{g} > 0 and τ<1\tau < 1, reduction is ∥g∥4/(2g⊤Bg)≥12∥g∥2/∥B∥\norm{\vb{g}}^4/(2\vb{g}\T\mat{B}\vb{g}) \ge \tfrac12\norm{\vb{g}}^2/\norm{\mat{B}}. If g⊤Bg>0\vb{g}\T\mat{B}\vb{g} > 0 and τ=1\tau = 1, then g⊤Bg≤∥g∥3/Δ\vb{g}\T\mat{B}\vb{g} \le \norm{\vb{g}}^3/\Delta and reduction is Δ∥g∥−Δ22∥g∥2g⊤Bg≥12Δ∥g∥\Delta\norm{\vb{g}} - \tfrac{\Delta^2}{2\norm{\vb{g}}^2}\vb{g}\T\mat{B}\vb{g} \ge \tfrac12\Delta\norm{\vb{g}}. All cases satisfy the bound.

∎

That bound suffices for global convergence (below). Dogleg improves on the Cauchy point when B≻0\mat{B} \succ 0 by following a two-segment path: from 0\vb{0} to the model minimum along −g-\vb{g}, pU=−g⊤gg⊤Bgg\vb{p}^U = -\tfrac{\vb{g}\T\vb{g}}{\vb{g}\T\mat{B}\vb{g}}\vb{g}, then to Newton step pB=−B−1g\vb{p}^B = -\mat{B}\inv\vb{g}. The step is the path’s point touching the boundary: if ∥pB∥≤Δ\norm{\vb{p}^B} \le \Delta, it is pB\vb{p}^B; if ∥pU∥≥Δ\norm{\vb{p}^U} \ge \Delta, it is the first-leg intersection, −Δg/∥g∥-\Delta\vb{g}/\norm{\vb{g}}; otherwise the second-leg intersection with the circle, obtained from a quadratic equation. Along the path ∥p∥\norm{\vb{p}} increases and m(p)m(\vb{p}) decreases (Nocedal and Wright, lemma 4.2), so dogleg always improves on the Cauchy point. It needs one factorization per iteration. If B\mat{B} is not positive definite, dogleg is undefined; use the Cauchy point or exact method.

InteractiveThe trust region
  • quadratic model
  • region ∥p∥≤Δ\norm{\vb{p}} \le \Delta
  • exact solution
  • dogleg and its path
  • Cauchy point
  • exact path p(Δ)\vb{p}(\Delta)
  • chosen step
  • accepted iterates
  • model predicted reduction
  • actual reduction in ff
Function
1.2
Step solver
Predicted reduction1.25
Actual reduction1.16
Ratio ρ\rho0.93
∥p∥\norm{\vb{p}} and Δ\Delta1.2 and 1.2
Predicted: exact, dogleg, Cauchy1.4, 1.2, 0.71
Multiplier λ\lambda (exact)0.73
ρ=0.93\rho = 0.93: actual reduction nearly matches the prediction. If the step hits the boundary, the algorithm would expand the region.
Blue curves are the quadratic model at xk\vb{x}_k (draggable blue point); the teal circle is region ∥p∥≤Δ\norm{\vb{p}} \le \Delta. Start on the convex function with nearly singular ∇2f\hess f in one direction: the full Newton step is huge. Move Δ\Delta and observe the Cauchy point (orange), dogleg (magenta, dashed path 0→pU→pB\vb{0} \to \vb{p}^U \to \vb{p}^B) and exact solution (violet, with path p(Δ)\vb{p}(\Delta) as radius grows). Below are predicted model reduction and actual ff reduction: ratio ρ\rho is the ratio of the curves, near 11 for small radii and falling negative when Δ\Delta leaves the reliable model region (raise Δ\Delta to 33). Press 'Take step' to apply the rule: accept or reject and double or divide the radius. With Himmelblau near the origin, the model is a dome and dogleg does not exist.

Convergence

Global. Suppose ff is bounded below on the level set of f(x0)f(\vb{x}_0), ∇f\grad f is Lipschitz in a neighborhood, ∥Bk∥≤β\norm{\mat{B}_k} \le \beta and each step attains at least fraction c1c_1 of Cauchy decrease (and ∥pk∥≤c2Δk\norm{\vb{p}_k} \le c_2\Delta_k). Then with η>0\eta > 0, ∇f(xk)→0\grad f(\vb{x}_k) \to \vb{0}, and with η=0\eta = 0, lim inf⁡∥∇f(xk)∥=0\liminf\norm{\grad f(\vb{x}_k)} = 0 (Nocedal and Wright, theorem 4.6 for η>0\eta > 0 and 4.5 for η=0\eta = 0). Neither convexity nor Bk≻0\mat{B}_k \succ 0 is needed, distinguishing it from line search. If also Bk=∇2f(xk)\mat{B}_k = \hess f(\vb{x}_k) and the subproblem is solved exactly, limit points satisfy ∇2f⪰0\hess f \succeq 0 (Conn, Gould and Toint, 2000).

Local. Near a minimum with ∇2f≻0\hess f \succ 0, the Newton step fits inside the region and ratio ρ\rho approaches 11, so the radius grows and the method behaves like pure Newton: quadratic convergence. Nocedal and Wright (theorem 4.9) prove this under usual hypotheses: global and fast.

Cost and scale. Dogleg costs one factorization per iteration; the exact subproblem costs two to four. For large nn, approximate it with truncated conjugate gradients (Steihaug–Toint), using only Hessian-vector products and forming the basis of inexact Newton in lesson 14.

Variables with different scales. The Euclidean ball is not invariant under changing units. When variables have very different scales use a scaled norm ∥Dp∥≤Δ\norm{\mat{D}\vb{p}} \le \Delta, with diagonal D\mat{D}.

Nonlinear least squares: Gauss-Newton and Levenberg-Marquardt

Many problems have form f(x)=12∥r(x)∥2=12∑i=1mri(x)2f(\vb{x}) = \tfrac12\norm{\vb{r}(\vb{x})}^2 = \tfrac12\sum_{i=1}^m r_i(\vb{x})^2, with residuals r ⁣:Rn→Rm\vb{r}\colon \R^n \to \R^m (model minus data) and m≥nm \ge n: curve fitting, calibration, bundle adjustment, inverse kinematics, the correction step of the iterated extended Kalman filter (iterated EKF). This form has structure. With the Jacobian J(x)∈Rm×n\mat{J}(\vb{x}) \in \R^{m\times n} of r\vb{r},

∇f=J⊤r,∇2f=J⊤J+S,S(x)=∑i=1mri(x) ∇2ri(x).\grad f = \mat{J}\T\vb{r}, \qquad \hess f = \mat{J}\T\mat{J} + \mat{S}, \qquad \mat{S}(\vb{x}) = \sum_{i=1}^m r_i(\vb{x})\,\hess r_i(\vb{x}).

(Obtain this by differentiating ∂jf=∑iri ∂jri\partial_j f = \sum_i r_i\,\partial_j r_i again.) The Hessian splits into two terms, the first known from first derivatives alone and the second from each residual’s second derivatives. The second, S\mat{S}, vanishes when residuals are small or models nearly linear.

Three properties. It needs only first derivatives. J⊤J⪰0\mat{J}\T\mat{J} \succeq 0 always, so with full rank pGN\vb{p}_{GN} descends: ∇f⊤pGN=−r⊤J(J⊤J)−1J⊤r=−∥Pr∥2\grad f\T\vb{p}_{GN} = -\vb{r}\T\mat{J}(\mat{J}\T\mat{J})\inv\mat{J}\T\vb{r} = -\norm{\mat{P}\vb{r}}^2, with P\mat{P} the orthogonal projector onto J\mat{J}‘s columns, nonzero if ∇f≠0\grad f \neq \vb{0}. In practice use QR factorization of J\mat{J}, not forming J⊤J\mat{J}\T\mat{J} (which squares the condition number; see numerical least squares).

What is lost by discarding S?

Proof

The iteration is G(x)=x−(J⊤J)−1∇f(x)G(\vb{x}) = \vb{x} - (\mat{J}\T\mat{J})\inv\grad f(\vb{x}). Its derivative at x⋆\vb{x}^\star is I−(J⊤J)−1∇2f(x⋆)\mat{I} - (\mat{J}\T\mat{J})\inv\hess f(\vb{x}^\star), because the term differentiating the inverse multiplies ∇f(x⋆)=0\grad f(\vb{x}^\star) = \vb{0}. With ∇2f=J⊤J+S\hess f = \mat{J}\T\mat{J} + \mat{S}, DG(x⋆)=−(J⊤J)−1SDG(\vb{x}^\star) = -(\mat{J}\T\mat{J})\inv\mat{S}. First-order expansion of GG at x⋆\vb{x}^\star gives the formula, and the fixed-point local convergence criterion (Ostrowski’s theorem) says x⋆\vb{x}^\star attracts if ρ(DG)<1\rho(DG) < 1 and repels if ρ(DG)>1\rho(DG) > 1. Eigenvalues of (J⊤J)−1S(\mat{J}\T\mat{J})\inv\mat{S} are real because it is similar to symmetric (J⊤J)−1/2S(J⊤J)−1/2(\mat{J}\T\mat{J})^{-1/2}\mat{S}(\mat{J}\T\mat{J})^{-1/2}. If r(x⋆)=0\vb{r}(\vb{x}^\star) = \vb{0}, S(x)=O(∥e∥)\mat{S}(\vb{x}) = \bigO(\norm{\vb{e}}) near x⋆\vb{x}^\star, since r(x)=O(∥e∥)\vb{r}(\vb{x}) = \bigO(\norm{\vb{e}}); the Gauss-Newton step then differs from Newton by O(∥e∥2)\bigO(\norm{\vb{e}}^2) and Newton’s quadratic convergence proof applies with that perturbation.

∎

Strict local minimality (∇2f≻0\hess f \succ 0, i.e. S≻−J⊤J\mat{S} \succ -\mat{J}\T\mat{J}) only guarantees eigenvalues of (J⊤J)−1S(\mat{J}\T\mat{J})\inv\mat{S} exceed −1-1; it does not prevent one exceeding 11. A strict minimum can repel Gauss-Newton when optimal residual is large and the model curves in the same direction. With noise size σ\sigma, ∥r⋆∥\norm{\vb{r}^\star} and the rate grow with σ\sigma, as the figure shows.

InteractiveGauss-Newton and Levenberg-Marquardt
Parameter plane (a,b)(a, b) and cost contours
Data and fitted curve, y=a e−bty = a\,e^{-b t}
iteration 0
  • GN error
  • LM error
  • line with predicted rate
  • Gauss-Newton
  • Levenberg-Marquardt
  • local minimum x⋆\vb{x}^\star
  • true parameters
  • data
  • curve using true parameters
Model
0.5
Start
LM damping
1e-3
Fitted curve shown
Residual at optimum ∥r⋆∥\norm{\vb{r}^\star}1.78
Predicted GN rate ρ((J⊤J)−1S)\rho((\mat{J}\T\mat{J})^{-1}\mat{S})0.315
Iterations to 10−810^{-8}: GN and LM16 and 15
LM: μ\mu and rejections0.41 and 0
Residual at the optimum ∥r⋆∥=1.78\norm{\vb{r}^\star} = 1.78: the neglected term matters and convergence is linear with rate ρ((J⊤J)−1S)=0.315\rho((\mat{J}\T\mat{J})^{-1}\mat{S}) = 0.315 (measured: 0.315). Increase σ\sigma and the slope worsens.
Fit a two-parameter curve. Left, parameter plane with cost contours and trajectories of Gauss-Newton (orange) and Levenberg-Marquardt (violet); right, data and fitted curve. Below, error versus iteration on a logarithmic scale. With σ=0\sigma = 0 GN error falls increasingly fast (digits double). Raise σ\sigma: optimal residual ∥r⋆∥\norm{\vb{r}^\star} grows and the GN error line tilts at the slope predicted by the spectral radius of (J⊤J)−1S(\mat{J}\T\mat{J})\inv\mat{S} (dashed line). Change start (A, B) or drag it: pure undamped GN can get lost; LM does not. With very large μ0\mu_0, LM starts with short gradient steps and lengthens them as predictions improve.

Levenberg-Marquardt: Gauss-Newton with a trust region

Pure Gauss-Newton has no globalization: if J⊤J\mat{J}\T\mat{J} is nearly singular the step is huge, and if ρ((J⊤J)−1S)≥1\rho((\mat{J}\T\mat{J})\inv\mat{S}) \ge 1 it does not converge. The remedy is in the previous section.

This is Gauss-Newton with a trust region. By subproblem optimality, with B=J⊤J⪰0\mat{B} = \mat{J}\T\mat{J} \succeq 0 (so B+μI⪰0\mat{B} + \mu\mat{I} \succeq 0 for all μ≥0\mu \ge 0), the LM vector p\vb{p} with D=I\mat{D} = \mat{I} exactly solves min⁡12∥r+Jp∥2\min \tfrac12\norm{\vb{r} + \mat{J}\vb{p}}^2 subject to ∥p∥≤Δ\norm{\vb{p}} \le \Delta, with μ\mu the constraint multiplier: each Δ\Delta corresponds to a μ\mu. With diagonal D\mat{D}, it corresponds to elliptical region ∥D1/2p∥≤Δ\norm{\mat{D}^{1/2}\vb{p}} \le \Delta, making Marquardt’s version invariant to separate parameter rescalings. The extremes are expected: μ→0\mu \to 0 gives Gauss-Newton and μ→∞\mu \to \infty gives gradient step −J⊤r/μ-\mat{J}\T\vb{r}/\mu. Moreover J⊤J+μD\mat{J}\T\mat{J} + \mu\mat{D} is invertible even if J\mat{J} lacks full rank (Tikhonov regularization), and inverse kinematics with “damped least squares” (DLS) is LM with fixed μ\mu.

Cost per iteration and when it pays off

A Newton iteration needs the gradient, Hessian (an n×nn\times n matrix to assemble and store, 8n28n^2 bytes in double precision) and an n×nn\times n linear solve: Cholesky costs n3/3n^3/3 floating-point operations (flop count) and two substitutions cost 2n22n^2. If nn Hessian-vector products (HVPs) replace assembly, each costs about two or three gradient evaluations.

[ ]Cost of a Newton iterationBrowser
import numpy as np

def humano(b):
    for u in ["B", "KB", "MB", "GB", "TB", "PB", "EB"]:
        if b < 1000:
            return f"{b:.3g} {u}"
        b /= 1000
    return f"{b:.3g} ZB"

print(f"{'n':>10}  {'memoria de H':>12}  {'flops de Cholesky':>18}  {'a 1 TFLOP/s':>14}")
for n in [1e2, 1e3, 1e4, 1e5, 1.24e8, 7e9]:
    memoria = 8 * n * n                  # bytes en doble precisión
    flops = n**3 / 3
    seg = flops / 1e12
    t = f"{seg:.3g} s" if seg < 3600 else f"{seg / 3.156e7:.3g} años"
    print(f"{n:10.3g}  {humano(memoria):>12}  {flops:18.3g}  {t:>14}")

With nn in the hundreds or low thousands, an iteration is a blink and Newton wins decisively. At n=105n = 10^5 storage already requires 80 GB. With hundreds of millions of parameters in a language model (the 1.24×1081.24\times10^8 row is small GPT-2), no computer can store the Hessian; with 7×1097\times10^9 it would be about 400 exabytes. Deep learning therefore uses inexact Newton, limited-memory quasi-Newton, diagonal (Adam) or block preconditioners, not Newton.

It pays off when:

  • nn is small (hundreds to a few thousand) and high accuracy is needed: few cheap iterations. Logistic regression, distribution fitting, classical statistical models.
  • The Hessian is sparse or structured. In bundle adjustment the approximate Hessian J⊤J\mat{J}\T\mat{J} has block arrow structure, and the Schur complement reduces the large system to one the size of the cameras.
  • Evaluating ff and its gradient is expensive (a pass over many data points): few passes matter more than many cheap passes. With NN data and dd parameters, Hessian assembly costs O(Nd2)\bigO(Nd^2) once per iteration.
  • They are inner steps of another algorithm (interior-point, augmented Lagrangian methods).

Implementation from scratch

First, damped Newton with shifted Cholesky, without inverting any matrix. Apply it to regularized logistic regression (Newton is IRLS) and Rosenbrock, recording decrement 12λ2\tfrac12\lambda^2 to see the quadratic phase. For Rosenbrock the cell also counts gradient descent with Armijo.

[ ]Damped Newton with Cholesky from scratchBrowser
import numpy as np
from scipy.linalg import solve_triangular

def newton_modificado(H, g, beta=1e-3):
    """Dirección de Newton con Cholesky desplazado: d = -(H + tau I)^{-1} g, sin invertir nada."""
    n = len(g)
    mindiag = H.diagonal().min()
    tau = 0.0 if mindiag > 0 else -mindiag + beta
    while True:
        try:
            L = np.linalg.cholesky(H + tau * np.eye(n))
            break
        except np.linalg.LinAlgError:
            tau = max(2 * tau, beta)
    y = solve_triangular(L, -g, lower=True)       # L y = -g
    d = solve_triangular(L.T, y, lower=False)     # L^T d = y
    return d, tau

def newton(f, grad, hess, x0, amortiguado=True, alpha=1e-4, beta=0.5, tol=1e-13, max_iter=100):
    x = np.array(x0, dtype=float)
    hist = []
    for k in range(max_iter):
        g, H = grad(x), hess(x)
        d, tau = newton_modificado(H, g)
        lam2 = -g @ d                              # decremento de Newton al cuadrado
        if lam2 / 2 <= tol:                        # ½λ² estima f(x) - f*: parada afín invariante
            hist.append((f(x), lam2 / 2, 1.0, tau))
            break
        t = 1.0
        if amortiguado:                            # retroceso de Armijo sobre la dirección de Newton
            while f(x + t * d) > f(x) + alpha * t * (g @ d) and t > 1e-12:
                t *= beta
        hist.append((f(x), lam2 / 2, t, tau))
        x = x + t * d
    return x, hist

# 1) regresión logística regularizada: Newton es aquí IRLS
rng = np.random.default_rng(0)
n, d = 400, 5
X = rng.normal(size=(n, d))
y = (X @ rng.normal(size=d) + 0.7 * rng.normal(size=n) > 0).astype(float)
lam = 1e-3
def f_log(w):
    z = X @ w
    return np.mean(np.logaddexp(0, z) - y * z) + 0.5 * lam * w @ w
def g_log(w):
    return X.T @ (1 / (1 + np.exp(-(X @ w))) - y) / n + lam * w
def h_log(w):
    s = 1 / (1 + np.exp(-(X @ w)))
    return (X.T * (s * (1 - s))) @ X / n + lam * np.eye(d)

w, hist = newton(f_log, g_log, h_log, np.zeros(d))
print("logística: pasos dados =", len(hist) - 1)
print(" k    f - f*        ½λ²        t")
fstar = hist[-1][0]
for k, (fk, dec, t, tau) in enumerate(hist):
    print(f"{k:2d}  {fk - fstar:10.3e}  {dec:10.3e}  {t:.3f}")
dec = np.array([h[1] for h in hist])
cifras = -np.log10(dec[dec > 1e-15])
print("cifras de ½λ² por iteración:", np.round(cifras, 1))
print("cociente entre cifras sucesivas:", np.round(cifras[1:] / cifras[:-1], 2))

# 2) Rosenbrock: fase amortiguada y fase cuadrática
def f_r(x): return (1 - x[0])**2 + 100 * (x[1] - x[0]**2)**2
def g_r(x): return np.array([-2 * (1 - x[0]) - 400 * x[0] * (x[1] - x[0]**2), 200 * (x[1] - x[0]**2)])
def h_r(x): return np.array([[2 - 400 * x[1] + 1200 * x[0]**2, -400 * x[0]], [-400 * x[0], 200.0]])
x, hist = newton(f_r, g_r, h_r, [-1.2, 1.0])
print("\nRosenbrock, Newton amortiguado: pasos dados =", len(hist) - 1, " x =", x)
print(" k      f         ½λ²        t")
for k, (fk, dec, t, tau) in enumerate(hist):
    print(f"{k:2d}  {fk:9.2e}  {dec:9.2e}  {t:.4f}")

# 3) descenso por gradiente con Armijo desde el mismo punto (en Python puro, para que sea rápido)
def f2(a, b): return (1 - a)**2 + 100 * (b - a * a)**2
a, b, k = -1.2, 1.0, 0
while k < 30000:
    ga, gb = -2 * (1 - a) - 400 * a * (b - a * a), 200 * (b - a * a)
    gn2 = ga * ga + gb * gb
    if gn2 ** 0.5 < 1e-6:
        break
    t, fx = 1.0, f2(a, b)
    while f2(a - t * ga, b - t * gb) > fx - 1e-4 * t * gn2:
        t *= 0.5
    a, b, k = a - t * ga, b - t * gb, k + 1
print(f"\nRosenbrock, descenso por gradiente con Armijo: {k} iteraciones hasta |grad| < 1e-6")

Notice three code decisions. The stopping criterion is 12λ2≤tol\tfrac12\lambda^2 \le \mathrm{tol}, estimating f−f⋆f - f^\star independent of units. Backtracking uses directional derivative g⊤d\vb{g}\T\vb{d}, equal to −λ2-\lambda^2 if no shift occurred. np.linalg.inv is never called: two triangular substitutions use the Cholesky factor.

In logistic regression f−f⋆f - f^\star falls from 0.470.47 to 7×10−117\times10^{-11} in six steps with t=1t = 1 throughout, and the ratio between digits of 12λ2\tfrac12\lambda^2 in successive steps rises toward 22 (1.51.5, 1.71.7, 1.81.8). Rosenbrock has an irregular damped phase (21 steps total, with t=0.125t = 0.125, 0.250.25 or 0.50.5 interspersed through iteration 13), then roughly five quadratic steps in which 12λ2\tfrac12\lambda^2 goes from 5×10−35\times10^{-3} to 9×10−49\times10^{-4}, 8×10−58\times10^{-5}, 3×10−73\times10^{-7}, 9×10−129\times10^{-12} and 4×10−214\times10^{-21}. Gradient descent needs 13,756 iterations, over six hundred times more. Curiously, pure Newton from (−1.2,1)(-1.2, 1) converges in six or seven steps (depending on stopping criterion), fewer than damped Newton: Armijo’s monotonicity costs steps in a curved valley, and this lucky full step is unreliable (change the start and it may stop working, as the digits figure shows).

Now a trust region with dogleg, also from scratch, and comparison with the library. When the Hessian is not positive definite use the Cauchy point, as theory says.

[ ]Trust region (dogleg) from scratch and comparison with SciPyBrowser
import numpy as np
from scipy.optimize import minimize

def f_r(x): return (1 - x[0])**2 + 100 * (x[1] - x[0]**2)**2
def g_r(x): return np.array([-2 * (1 - x[0]) - 400 * x[0] * (x[1] - x[0]**2), 200 * (x[1] - x[0]**2)])
def h_r(x): return np.array([[2 - 400 * x[1] + 1200 * x[0]**2, -400 * x[0]], [-400 * x[0], 200.0]])

def punto_cauchy(g, B, delta):
    gBg = g @ B @ g
    tau = 1.0 if gBg <= 0 else min(np.linalg.norm(g)**3 / (delta * gBg), 1.0)
    return -tau * delta / np.linalg.norm(g) * g

def dogleg(g, B, delta):
    """Poligonal 0 -> pU -> pB, cortada en la frontera. Exige B definida positiva."""
    pB = -np.linalg.solve(B, g)
    if np.linalg.norm(pB) <= delta:
        return pB
    pU = -(g @ g) / (g @ B @ g) * g
    if np.linalg.norm(pU) >= delta:
        return -delta * g / np.linalg.norm(g)
    d = pB - pU                                   # ‖pU + s d‖² = Δ², raíz en [0, 1]
    a, b, c = d @ d, 2 * pU @ d, pU @ pU - delta**2
    s = (-b + np.sqrt(b * b - 4 * a * c)) / (2 * a)
    return pU + s * d

def region_confianza(f, grad, hess, x0, delta0=1.0, delta_max=10.0, eta=0.15, tol=1e-9, max_iter=200):
    x, delta = np.array(x0, dtype=float), delta0
    hist = []
    for k in range(max_iter):
        g, B = grad(x), hess(x)
        if np.linalg.norm(g) < tol:
            break
        definida = np.linalg.eigvalsh(B)[0] > 0
        p = dogleg(g, B, delta) if definida else punto_cauchy(g, B, delta)
        predicha = -(g @ p + 0.5 * p @ B @ p)     # m(0) - m(p)
        real = f(x) - f(x + p)
        rho = real / predicha
        hist.append((f(x), delta, rho))
        if rho < 0.25:
            delta *= 0.25
        elif rho > 0.75 and np.isclose(np.linalg.norm(p), delta):
            delta = min(2 * delta, delta_max)
        if rho > eta:
            x = x + p
    return x, hist

x, hist = region_confianza(f_r, g_r, h_r, [-1.2, 1.0])
rechazos = sum(1 for _, _, r in hist if r <= 0.15)
print(f"dogleg propio: {len(hist)} iteraciones ({rechazos} rechazadas), x = {x}")
for k, (fk, dl, rho) in list(enumerate(hist))[:6]:
    print(f"  k={k}  f={fk:9.3e}  Δ={dl:7.4f}  ρ={rho:6.3f}")

# comparación con SciPy desde el mismo punto
x0 = np.array([-1.2, 1.0])
print("\nmétodo           iter  f(x*)")
for metodo in ["Newton-CG", "dogleg", "trust-ncg", "trust-exact"]:
    r = minimize(f_r, x0, jac=g_r, hess=h_r, method=metodo, tol=1e-9)
    print(f"{metodo:14s}  {r.nit:4d}  {r.fun:.1e}")
r = minimize(f_r, x0, jac=g_r, method="BFGS", tol=1e-9)
print(f"{'BFGS':14s}  {r.nit:4d}  {r.fun:.1e}   (sin hessiano)")

The first iteration accepts the Newton step (ρ≈1\rho \approx 1), the second is rejected with ρ<0\rho < 0 (the model predicted a decrease but ff rose) and the radius is quartered; later the radius rises again when ρ>34\rho > \tfrac34 and the step touches the boundary. This is the trust-region figure’s mechanism in code. With the library (method='trust-exact', 'dogleg', 'trust-ncg' and 'Newton-CG' with analytic Hessian), dogleg and trust-exact need 25 and 26 iterations, like our dogleg (25), trust-ncg 30, Newton-CG (which uses line search) 85 and BFGS without Hessian 34; trust-ncg and Newton-CG accept a Hessian-vector product (hessp) instead of the Hessian, needed at scale.

Finally, nonlinear least squares: Gauss-Newton and Levenberg-Marquardt from scratch, with exponential model y=a e−bty = a\,e^{-bt} and Michaelis–Menten y=Vt/(K+t)y = Vt/(K + t), compared with scipy.optimize.least_squares (methods 'lm', MINPACK, and 'trf', trust region). The cell also calculates theorem rate ρ((J⊤J)−1S)\rho((\mat{J}\T\mat{J})\inv\mat{S}) and compares it to the measured rate.

[ ]Gauss-Newton and Levenberg-Marquardt, compared with SciPyBrowser
import numpy as np
from scipy.optimize import least_squares

def gauss_newton(r, J, x0, max_iter=100, tol=1e-10):
    x = np.array(x0, dtype=float)
    hist = [x.copy()]
    for _ in range(max_iter):
        Jx, rx = J(x), r(x)
        g = Jx.T @ rx
        if np.linalg.norm(g) < tol:
            break
        try:
            p = np.linalg.solve(Jx.T @ Jx, -g)    # ecuaciones normales de min ‖r + J p‖²
        except np.linalg.LinAlgError:             # JᵀJ singular: GN no sabe qué hacer
            break
        x = x + p
        hist.append(x.copy())
        if not np.all(np.isfinite(x)) or np.abs(x).max() > 1e8:
            break
    return x, hist

def levenberg_marquardt(r, J, x0, mu0=1e-3, max_iter=200, tol=1e-10):
    x = np.array(x0, dtype=float)
    mu, nu = None, 2.0
    hist = [x.copy()]
    for _ in range(max_iter):
        Jx, rx = J(x), r(x)
        A, g = Jx.T @ Jx, Jx.T @ rx
        if np.linalg.norm(g) < tol:
            break
        if mu is None:
            mu = mu0 * A.diagonal().max()
        while True:
            p = np.linalg.solve(A + mu * np.eye(len(x)), -g)
            xn = x + p
            reduccion_real = 0.5 * rx @ rx - 0.5 * r(xn) @ r(xn)
            reduccion_pred = 0.5 * p @ (mu * p - g)           # ganancia del modelo lineal
            if reduccion_pred < 1e-300:                       # ya no hay nada que ganar
                return x, hist
            rho = reduccion_real / reduccion_pred
            if rho > 0:
                x, nu = xn, 2.0
                mu *= max(1 / 3, 1 - (2 * rho - 1) ** 3)
                break
            mu, nu = mu * nu, 2 * nu                          # rechazado: más amortiguamiento
        hist.append(x.copy())
    return x, hist

t = np.linspace(0.3, 4.5, 12)

def problema(nombre, sigma):
    z = np.random.default_rng(3).normal(size=t.size)
    if nombre == "exponencial":
        xv = np.array([2.0, 0.6]); y = lambda x: x[0] * np.exp(-x[1] * t)
        J = lambda x: np.column_stack([np.exp(-x[1] * t), -x[0] * t * np.exp(-x[1] * t)])
        def S(x, rx):                                 # Σ r_i ∇²r_i, el término que GN ignora
            e = np.exp(-x[1] * t)
            return np.array([[0, np.sum(rx * -t * e)], [np.sum(rx * -t * e), np.sum(rx * x[0] * t**2 * e)]])
        x0 = [1.0, 2.0]
    else:
        xv = np.array([1.0, 1.0]); y = lambda x: x[0] * t / (x[1] + t)
        J = lambda x: np.column_stack([t / (x[1] + t), -x[0] * t / (x[1] + t) ** 2])
        def S(x, rx):
            c = -t / (x[1] + t) ** 2
            return np.array([[0, np.sum(rx * c)], [np.sum(rx * c), np.sum(rx * 2 * x[0] * t / (x[1] + t) ** 3)]])
        x0 = [0.5, 3.0]
    datos = y(xv) + sigma * z
    return (lambda x: y(x) - datos), J, S, x0

casos = [("exponencial", 0.0), ("exponencial", 0.5), ("Michaelis-Menten", 0.0), ("Michaelis-Menten", 0.2)]
for nombre, sigma in casos:
    r, J, S, x0 = problema(nombre, sigma)
    xl, hl = levenberg_marquardt(r, J, x0)
    rs = r(xl)
    rho = max(abs(np.linalg.eigvals(np.linalg.solve(J(xl).T @ J(xl), S(xl, rs)))))
    sp = {m: least_squares(r, x0, method=m, ftol=1e-15, xtol=1e-15, gtol=1e-15) for m in ("lm", "trf")}
    dif = max(np.abs(sp[m].x - xl).max() for m in sp)
    print(f"{nombre}, σ={sigma}: ‖r*‖ = {np.linalg.norm(rs):.3f}, x* = {np.round(xl, 4)}")
    print(f"   LM propio: {len(hl)-1} iteraciones; SciPy lm: {sp['lm'].nfev} evaluaciones, trf: {sp['trf'].nfev}; diferencia máxima {dif:.1e}")
    xg, hg = gauss_newton(r, J, xl + np.array([0.15, -0.15]))               # GN cerca del óptimo
    e = [np.linalg.norm(h - xl) for h in hg]
    print("   GN cerca del óptimo, errores:", " ".join(f"{v:.0e}" for v in e[:9]))
    print(f"   tasa predicha ρ((JᵀJ)⁻¹S) = {rho:.3f}" + (f", cociente medido entre errores sucesivos = {e[7] / e[6]:.3f}" if rho > 0.01 and len(e) > 8 else ""))
    xg2, hg2 = gauss_newton(r, J, x0, max_iter=60)                          # GN desde el arranque lejano
    ok = np.all(np.isfinite(xg2)) and np.linalg.norm(xg2 - xl) < 1e-6
    print(f"   GN puro desde {x0}: {'converge en ' + str(len(hg2) - 1) + ' iteraciones' if ok else 'no llega al mínimo'}")

Without noise the optimal residual is zero and Gauss-Newton near the minimum behaves like Newton: errors fall as 0.2,0.05,3×10−3,7×10−6,2×10−110.2, 0.05, 3\times10^{-3}, 7\times10^{-6}, 2\times10^{-11}, doubling digits. With noise (σ=0.5\sigma = 0.5 in the exponential model, large residual) the theorem predicts asymptotic rate ρ((J⊤J)−1S)=0.754\rho((\mat{J}\T\mat{J})\inv\mat{S}) = 0.754, matching measured 0.7530.753 to three digits: going from 10−110^{-1} to 10−810^{-8} takes about sixty iterations instead of five. With σ=0.2\sigma = 0.2 in Michaelis–Menten, 0.2260.226 versus 0.2240.224. From distant starts (last line in each case), pure Gauss-Newton misses the minimum in noiseless problems, while LM reaches it in all cases. Both SciPy implementations and ours agree on the minimum within 10−610^{-6} or less; 'trf' mainly exists for bounds and large sparse problems.

Common mistakes

Exercises

NumericTwo Newton steps
Apply two pure Newton steps to f(x)=x−ln⁡xf(x) = x - \ln x from x0=0.5x_0 = 0.5 and give x2x_2.
NumericThe Newton decrement
Let f(x)=12x⊤Ax−b⊤xf(\vb{x}) = \tfrac12\vb{x}\T\mat{A}\vb{x} - \vb{b}\T\vb{x} with A=[4113]\mat{A} = \begin{bmatrix} 4 & 1 \\ 1 & 3 \end{bmatrix} and b=(1,2)\vb{b} = (1, 2). What is f(0)−min⁡ff(\vb{0}) - \min f?
NumericCubic convergence in one variable
Apply two pure Newton steps to f(x)=1+x2f(x) = \sqrt{1 + x^2} from x0=0.5x_0 = 0.5 and give x2x_2.
NumericReduction at the Cauchy point
With g=(3,4)\vb{g} = (3, 4), B=diag⁡(2,1)\mat{B} = \diag(2, 1) and Δ=2\Delta = 2, what is model reduction m(0)−m(pC)m(\vb{0}) - m(\vb{p}^C) at the Cauchy point?
NumericA Gauss-Newton step
Fit y=ebty = e^{bt} to data (t,y)=(1,3)(t, y) = (1, 3) and (2,9)(2, 9), with residuals r1=eb−3r_1 = e^{b} - 3 and r2=e2b−9r_2 = e^{2b} - 9. Give the new bb after one Gauss-Newton step from b0=1b_0 = 1.
QuizWhy does Gauss-Newton slow down?
You fit a nonlinear model with Gauss-Newton and observe error near the minimum falling only 25% per iteration rather than doubling digits. What is the most likely explanation?
QuizNewton with an indefinite Hessian
Which statements are true?

More than one answer may be correct.

QuizUpdate the radius
In a trust-region iteration with η=0.1\eta = 0.1, step pk\vb{p}_k lands on the boundary, ∥pk∥=Δk\norm{\vb{p}_k} = \Delta_k, and reduction ratio is ρk=0.92\rho_k = 0.92. What does the algorithm do?
ProofThe global version with strong convexity
Prove: Let f∈C2f \in C^2 with ∇2f(x)⪰mI\hess f(\vb{x}) \succeq m\mat{I} for all x\vb{x} (m>0m > 0), ∇2f\hess f MM-Lipschitz throughout Rn\R^n, and x⋆\vb{x}^\star the minimizer. Then for every x\vb{x} the Newton step satisfies ∥x+−x⋆∥≤M2m∥x−x⋆∥2\norm{\vb{x}_{+} - \vb{x}^\star} \le \dfrac{M}{2m}\norm{\vb{x} - \vb{x}^\star}^2.
0
Write e=x−x⋆\vb{e} = \vb{x} - \vb{x}^\star, e+=x+−x⋆\vb{e}_+ = \vb{x}_+ - \vb{x}^\star and H=∇2f(x)\mat{H} = \hess f(\vb{x}).

Step 1 of 4. How do you express e+\vb{e}_+ to use what you know about ∇2f\hess f?

ProofDamped Newton is affine invariant
Prove: Let g(y)=f(Ay+b)g(\vb{y}) = f(\mat{A}\vb{y} + \vb{b}) with invertible A\mat{A}, and x0=Ay0+b\vb{x}_0 = \mat{A}\vb{y}_0 + \vb{b}. Damped Newton iterates (with the same α\alpha, β\beta) satisfy xk=Ayk+b\vb{x}_k = \mat{A}\vb{y}_k + \vb{b}, with the same steps tkt_k and stopping iteration if the criterion is 12λ2≤ε\tfrac12\lambda^2 \le \eps.
0
Write x=Ay+b\vb{x} = \mat{A}\vb{y} + \vb{b}, H=∇2f(x)\mat{H} = \hess f(\vb{x}) and df\vb{d}^f, dg\vb{d}^g for the Newton steps of ff at x\vb{x} and gg at y\vb{y}.

Step 1 of 4. How are gradients and Hessians of gg and ff related?

CodeLevenberg-Marquardt with adaptive damping
Implement levenberg_marquardt(residual, jac, x0, max_iter=200, tol=1e-10, mu0=1e-3), minimizing 12∥r(x)∥2\tfrac12\norm{\vb{r}(\vb{x})}^2 and returning (x, pasos_aceptados). Initialize with μ0\mu_0 times the largest diagonal entry of J⊤J\mat{J}\T\mat{J}, solve (J⊤J+μI)p=−J⊤r(\mat{J}\T\mat{J} + \mu\mat{I})\vb{p} = -\mat{J}\T\vb{r}, calculate gain ratio ρ=(f(x)−f(x+p))/(12p⊤(μp−J⊤r))\rho = (f(\vb{x}) - f(\vb{x}+\vb{p}))/(\tfrac12\vb{p}\T(\mu\vb{p} - \mat{J}\T\vb{r})) and update μ\mu as in Nielsen: if ρ>0\rho > 0, accept and μ←μmax⁡{1/3, 1−(2ρ−1)3}\mu \leftarrow \mu\max\{1/3,\ 1 - (2\rho - 1)^3\}; otherwise reject, μ←νμ\mu \leftarrow \nu\mu, ν←2ν\nu \leftarrow 2\nu. Stop when ∥J⊤r∥<tol\norm{\mat{J}\T\vb{r}} < \mathrm{tol}. Do not call scipy.
import numpy as np

def levenberg_marquardt(residual, jac, x0, max_iter=200, tol=1e-10, mu0=1e-3):
  """Minimiza 0.5*||residual(x)||^2. Devuelve (x, pasos_aceptados)."""
  x = np.array(x0, dtype=float)
  # tu código: mu inicial = mu0 * max(diag(J^T J)); en cada iteración resuelve (J^T J + mu I) p = -J^T r,
  # calcula la ganancia rho = reducción real / reducción predicha, acepta si rho > 0 y actualiza mu
  return x, 0
Shift+Enter to run
CodeThe dogleg step
Implement dogleg(g, B, delta), returning the dogleg step for min⁡g⊤p+12p⊤Bp\min \vb{g}\T\vb{p} + \tfrac12\vb{p}\T\mat{B}\vb{p} subject to ∥p∥≤Δ\norm{\vb{p}} \le \Delta. If B\mat{B} is positive definite: return Newton step pB=−B−1g\vb{p}^B = -\mat{B}\inv\vb{g} if it fits; otherwise, if ∥pU∥≥Δ\norm{\vb{p}^U} \ge \Delta with pU=−g⊤gg⊤Bgg\vb{p}^U = -\frac{\vb{g}\T\vb{g}}{\vb{g}\T\mat{B}\vb{g}}\vb{g}, return intersection −Δg/∥g∥-\Delta\vb{g}/\norm{\vb{g}}; otherwise return the point on pU→pB\vb{p}^U \to \vb{p}^B with ∥p∥=Δ\norm{\vb{p}} = \Delta. If B\mat{B} is not positive definite, return the Cauchy point. Solve the quadratic equation by hand; do not call an optimizer.
import numpy as np

def dogleg(g, B, delta):
  """Paso dogleg para min g.p + 0.5 p.B.p con ||p|| <= delta. Si B no es definida positiva, devuelve el punto de Cauchy."""
  g = np.asarray(g, dtype=float)
  B = np.asarray(B, dtype=float)
  # tu código: pB (paso de Newton), pU (mínimo a lo largo de -g) y los tres casos
  return np.zeros_like(g)
Shift+Enter to run

Summary

Key idea
Newton minimizes the complete quadratic model at each step, with affine invariance making it insensitive to ill-conditioning and local quadratic convergence doubling digits each iteration; outside that neighborhood step length must be limited (backtracking or trust region), and in least squares the second-order term S\mat{S} ignored by Gauss-Newton determines whether convergence is quadratic or linear.
  • Newton step dN=−∇2f−1∇f\vb{d}_N = -\hess f\inv\grad f minimizes the second-order Taylor model, 12λ2\tfrac12\lambda^2 is its predicted decrease and λ\lambda is an intrinsic (affine-invariant) measure of distance to optimum. On a quadratic it arrives in one step.
  • With MM-Lipschitz ∇2f\hess f and ∇2f(x⋆)⪰μI\hess f(\vb{x}^\star) \succeq \mu\mat{I}, ∥ek+1∥≤(M/μ)∥ek∥2\norm{\vb{e}_{k+1}} \le (M/\mu)\norm{\vb{e}_k}^2 within radius μ/(2M)\mu/(2M). Six or seven iterations exhaust double precision. A singular Hessian at optimum loses this and convergence is linear.
  • Pure Newton can move away, leave the domain, cycle or converge to a maximum or saddle. Damped Newton (Armijo backtracking starting at t=1t = 1) has a damped phase with guaranteed minimum decrease per iteration, and a quadratic one with t=1t = 1 accepted once λ≤3(1−2α)μ3/2/M\lambda \le 3(1 - 2\alpha)\mu^{3/2}/M.
  • With an indefinite Hessian, modify it (H+τI\mat{H} + \tau\mat{I} with Cholesky) or use a trust region: solve min⁡m(p)\min m(\vb{p}) with ∥p∥≤Δ\norm{\vb{p}} \le \Delta, exactly (conditions (B+λI)p=−g(\mat{B} + \lambda\mat{I})\vb{p} = -\vb{g}, λ≥0\lambda \ge 0, complementary slackness) or with the Cauchy point or dogleg; actual-to-predicted reduction ratio ρ\rho decides acceptance and whether radius expands or shrinks. It converges globally even without convexity.
  • For least squares, ∇2f=J⊤J+S\hess f = \mat{J}\T\mat{J} + \mat{S}. Gauss-Newton discards S\mat{S}: quadratic if optimal residual is zero and linear at rate ρ((J⊤J)−1S)\rho((\mat{J}\T\mat{J})\inv\mat{S}) otherwise. Levenberg-Marquardt, (J⊤J+μD)p=−J⊤r(\mat{J}\T\mat{J} + \mu\mat{D})\vb{p} = -\mat{J}\T\vb{r}, is the trust region for that model and globalizes by adapting μ\mu with ρ\rho.
  • Cost: O(n3)\bigO(n^3) per iteration and O(n2)\bigO(n^2) memory. It pays with small nn, sparse structure or expensive evaluations; at scale use quasi-Newton and inexact Newton, in the next lesson.