Hessian matrix

Level UniversityDifficulty ★★★★★Concept⌖ Open in the map

What is it?

The matrix of second partial derivatives ∂2f/∂xi∂xj\partial^2 f/\partial x_i\partial x_j: the curvature of ff in every direction. Its eigenvalues classify critical points (minimum, maximum, saddle) and control how fast optimizers can go.

Why does it exist?

The gradient says which way is downhill but not how the slope changes — whether the valley is a gentle bowl, a narrow ravine or a saddle. That second-order information decides whether a critical point is a minimum and how big a step is safe.

Intuition

Near a critical point, f(x+h)≈f(x)+12h𝖳Hhf(x + h) \approx f(x) + \tfrac12 h^{\mathsf T}Hh: a quadratic bowl whose axes are the eigenvectors of HH and whose steepness along each axis is the eigenvalue. All positive: a bowl (minimum). All negative: a dome. Mixed signs: a saddle. Very different eigenvalues: a narrow ravine where gradient descent bounces from wall to wall.

Formal definition

For f∈C2f \in C^2, Hf(x)=∇2f(x)=(∂i∂jf(x))ijH_f(x) = \nabla^2 f(x) = \big(\partial_i\partial_j f(x)\big)_{ij}, symmetric by Schwarz. At a critical point aa: H≻0H \succ 0 (positive definite) ⇒ strict local minimum; H≺0H \prec 0 ⇒ strict local maximum; HH indefinite ⇒ saddle point.

Formulas

Hf=(fxxfxyfyxfyy)H_f = \begin{pmatrix} f_{xx} & f_{xy} \\ f_{yx} & f_{yy}\end{pmatrix}
f(x+h)≈f(x)+∇f(x)𝖳h+12 h𝖳Hf(x) hf(x + h) \approx f(x) + \nabla f(x)^{\mathsf T}h + \tfrac12\,h^{\mathsf T}H_f(x)\,h
κ=λmax⁡(H)λmin⁡(H),η<2λmax⁡(H)\kappa = \frac{\lambda_{\max}(H)}{\lambda_{\min}(H)}, \qquad \eta < \frac{2}{\lambda_{\max}(H)}
conditioning and the largest stable learning rate on a quadratic

Example

f(x,y)=x2−y2f(x, y) = x^2 - y^2: ∇f=0\nabla f = 0 at the origin, H=diag⁡(2,−2)H = \operatorname{diag}(2, -2), indefinite: a saddle (a Pringles chip). Gradient descent started exactly on the xx-axis converges to it; any tiny perturbation in yy escapes. That is why saddle points slow training down but rarely trap it.

Why does it matter?

Newton's method uses H−1∇fH^{-1}\nabla f; quasi-Newton methods (BFGS, L-BFGS) approximate it; Adam and other adaptive optimizers can be read as cheap diagonal approximations of curvature. In deep learning, the "sharpness" (largest Hessian eigenvalue) is linked to generalization and to the edge-of-stability phenomenon. The full Hessian of a billion-parameter model is never formed, but Hessian–vector products are cheap with autodiff.

Where it shows up in computing

  • Image processing and computer vision★★★★★advancedSignals, media and vision

    Hessian-based detectors (determinant of Hessian in SURF, Frangi vesselness) find blobs and ridges.

Where it shows up in AI

  • Second-order (Hessian-based) optimization★★★★★fundamentalAI and machine learning

    Newton, Gauss–Newton, natural gradient and K-FAC use the Hessian or an approximation of it.

  • Loss landscape★★★★★fundamentalAI and machine learning

    Hessian eigenvalues measure sharpness, detect saddles and set the stable learning rate η<2/λmax⁡\eta < 2/\lambda_{\max}.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Classify the critical points of f(x,y)=x3−3x+y2f(x, y) = x^3 - 3x + y^2.

Solution

∇f=(3x2−3,2y)=0\nabla f = (3x^2 - 3, 2y) = 0 at (±1,0)(\pm1, 0). H=diag⁡(6x,2)H = \operatorname{diag}(6x, 2): at (1,0)(1,0) positive definite → minimum; at (−1,0)(-1, 0) indefinite → saddle.

2AI

On f(x,y)=12(x2+100y2)f(x,y) = \frac12(x^2 + 100y^2), what is the largest learning rate for which gradient descent converges? How many steps to reduce the xx-error by 10−310^{-3} at that rate?

Solution

H=diag⁡(1,100)H = \operatorname{diag}(1, 100), so η<2/100=0.02\eta < 2/100 = 0.02. Along xx each step multiplies the error by 1−η≈0.981 - \eta \approx 0.98: 0.98k=10−3⇒k≈3420.98^k = 10^{-3} \Rightarrow k \approx 342. Condition number 100 makes it slow.

↑ ↓ to navigate · ↵ · Esc