1.2.6Calculus & Optimization Basics

The Hessian matrix

2,310 words11 min readdifficulty · medium6 backlinks

WHAT is the Hessian?

For n=2n=2 with variables x,yx,y:

H=[2fx22fxy2fyx2fy2]H = \begin{bmatrix} \dfrac{\partial^2 f}{\partial x^2} & \dfrac{\partial^2 f}{\partial x\,\partial y} \\[2mm] \dfrac{\partial^2 f}{\partial y\,\partial x} & \dfrac{\partial^2 f}{\partial y^2} \end{bmatrix}

WHY is the Hessian symmetric?

WHY does order not matter? Both mixed partials measure the same "twist" of the surface — how the slope in the xx-direction responds to a nudge in yy equals how the slope in yy responds to a nudge in xx. Geometrically it's a single warping, measured from either angle.

This symmetry is a gift: a real symmetric matrix has real eigenvalues and an orthonormal eigenbasis (spectral theorem) — exactly what we need to classify critical points.


HOW the Hessian appears: the 2nd-order Taylor expansion

Step 1 — 1D reminder. Near aa: f(a+h)=f(a)+f(a)h+12f(a)h2+f(a+h) = f(a) + f'(a)h + \tfrac12 f''(a)h^2 + \cdots Why this step? This is the reference we'll generalize; the 12f(a)h2\tfrac12 f''(a)h^2 term is the curvature contribution.

Step 2 — Restrict to a line. In Rn\mathbb{R}^n, pick a point x\mathbf{x} and a direction v\mathbf{v}, and define g(t)=f(x+tv)g(t) = f(\mathbf{x} + t\mathbf{v}), a 1D function of tt. Why this step? Any multivariable behaviour along a straight path is a 1D function — so we can reuse 1D Taylor.

Step 3 — Differentiate gg via the chain rule. g(t)=f(x+tv)v,g(t)=vH(x+tv)vg'(t) = \nabla f(\mathbf{x}+t\mathbf{v})^\top \mathbf{v}, \qquad g''(t) = \mathbf{v}^\top H(\mathbf{x}+t\mathbf{v})\, \mathbf{v} Why this step? g(t)g'(t) is the directional derivative. Differentiating again, the chain rule brings down a second gradient of a gradient — that's precisely the Hessian sandwiched between v\mathbf{v}'s.

Step 4 — Plug into 1D Taylor at t=0t=0, then set t=1t=1, v=Δx\mathbf{v}=\Delta\mathbf{x}: f(x+Δx)f(x)+f(x)Δx+12ΔxH(x)Δx\boxed{f(\mathbf{x}+\Delta\mathbf{x}) \approx f(\mathbf{x}) + \nabla f(\mathbf{x})^\top \Delta\mathbf{x} + \tfrac12\, \Delta\mathbf{x}^\top H(\mathbf{x})\, \Delta\mathbf{x}}

Why this matters: the last term 12ΔxHΔx\tfrac12 \Delta\mathbf{x}^\top H \Delta\mathbf{x} is a quadratic form. Its sign in every direction tells you the shape of the surface.


Classifying critical points with the Hessian

At a critical point f=0\nabla f = \mathbf{0}, so the linear term vanishes and the Hessian alone decides the local shape.

WHY eigenvalues? In the eigenbasis, the quadratic form becomes 12iλiui2\tfrac12\sum_i \lambda_i u_i^2. Each eigenvalue is the curvature along its eigenvector. Positive in all directions ⇒ every path curves upward ⇒ minimum.

Figure — The Hessian matrix

Worked examples


Why AI/ML cares


Common mistakes


Flashcards

What does the Hessian matrix collect?
All second-order partial derivatives of a scalar function, Hij=2f/xixjH_{ij}=\partial^2 f/\partial x_i \partial x_j.
Why is the Hessian symmetric?
By Schwarz's theorem: if second partials are continuous, mixed partials commute, so H=HH=H^\top.
What is the 2nd-order Taylor expansion of ff about x\mathbf{x}?
f(x+Δx)f(x)+fΔx+12ΔxHΔxf(\mathbf{x}+\Delta\mathbf{x}) \approx f(\mathbf{x}) + \nabla f^\top \Delta\mathbf{x} + \tfrac12 \Delta\mathbf{x}^\top H \Delta\mathbf{x}.
At a critical point, what do all-positive eigenvalues of HH mean?
Local minimum (positive definite Hessian).
At a critical point, what do mixed-sign eigenvalues mean?
A saddle point.
For a 2×2 Hessian, what does detH<0\det H < 0 imply?
A saddle point (eigenvalues of opposite sign).
For 2×2 with detH>0\det H>0, how do you tell min from max?
Check the top-left entry aa (or trace): a>0a>0→min, a<0a<0→max.
Why does Newton's method use H1fH^{-1}\nabla f?
It minimizes the local quadratic Taylor model exactly in one step, using curvature to scale/rotate the step.
What does a large condition number λmax/λmin\lambda_{\max}/\lambda_{\min} of HH indicate?
An ill-conditioned, long thin valley where gradient descent zig-zags slowly.
When is the second-derivative test inconclusive?
When some eigenvalue of HH is zero (a flat direction).
Does Adam approximate the Hessian?
No — Adam adapts per-parameter steps from squared gradients (first-order statistics); it does not estimate curvature. L-BFGS is a true (quasi-Newton) Hessian approximation.

Recall Feynman: explain to a 12-year-old

Imagine hiking on a hilly landscape. The gradient is like a compass that always points straight uphill — it tells you which way to walk. But it doesn't tell you the shape around you: are you in a valley bottom, on a hilltop, or on a horse's saddle where it goes up one way and down another? The Hessian is a little "bend-o-meter": for every direction it tells you how sharply the ground is curving. If it curves up in every direction, you're at the bottom of a bowl (a minimum). If it curves down everywhere, you're on a summit. If it curves up one way and down another — that's a saddle. Computers use this bend info to reach the lowest valley faster.

Connections

Concept Map

cannot classify

packages

equals

entry Hij

off-diagonal

continuous partials

spectral theorem

classify

curvature term

derived from

next term

Gradient - slope

Critical point type

Hessian matrix

Second partial derivatives

grad squared f

d2f / dxi dxj

Direction coupling curvature

Schwarz theorem

Symmetric H

Real eigenvalues and orthonormal basis

2nd-order Taylor expansion

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, gradient batata hai ki function kis direction mein sabse tez badh raha hai — matlab pahaad par uphill kaunsi taraf hai. Lekin sirf slope se pata nahi chalta ki tum valley ke bottom par ho, hilltop par ho, ya saddle (ghode ki kaathi) par ho. Iske liye chahiye curvature — slope khud kaise change ho raha hai. Yahi kaam Hessian matrix karta hai: yeh saare second-order partial derivatives ko ek n×nn\times n square matrix mein rakh deta hai. Ismein diagonal terms har direction ka curvature dikhaate hain, aur off-diagonal terms batate hain ki directions ek doosre se kaise coupled hain.

Ek important baat: agar second derivatives continuous hain to Hessian symmetric hota hai (H=HH=H^\top) — kyunki mixed partial derivatives ka order matter nahi karta (Schwarz theorem). Symmetric hone ka fayda yeh hai ki eigenvalues real hote hain, aur inhi eigenvalues se hum critical point classify karte hain: saare positive → minimum (bowl), saare negative → maximum (dome), mixed signs → saddle. 2x2 ke liye shortcut: D=detHD=\det H. Agar D>0D>0 aur top-left a>0a>0 to minimum, a<0a<0 to maximum; agar D<0D<0 to saddle.

Yeh Taylor expansion se nikalta hai: f(x+Δx)f+fΔx+12ΔxHΔxf(\mathbf{x}+\Delta\mathbf{x}) \approx f + \nabla f^\top\Delta\mathbf{x} + \tfrac12\Delta\mathbf{x}^\top H\Delta\mathbf{x}. Critical point par gradient zero ho jaata hai, isliye us jagah ka shape sirf Hessian decide karta hai — yeh quadratic form 12ΔxHΔx\tfrac12\Delta\mathbf{x}^\top H\Delta\mathbf{x} ka sign hi sab kuch hai.

ML mein Hessian bahut kaam ka hai: Newton's method H1fH^{-1}\nabla f use karke minimum tak seedha jump karta hai, aur Hessian ke eigenvalues ka condition number (λmax/λmin\lambda_{max}/\lambda_{min}) batata hai ki loss landscape kitna patla-lamba (ill-conditioned) hai, jahan simple gradient descent zig-zag karta hai. Full Hessian bahut bada hota hai, isliye L-BFGS jaise quasi-Newton methods sasti Hessian approximation banate hain. Lekin dhyaan rakho — Adam Hessian approximate nahi karta! Woh sirf squared gradients (first-order statistics) se har parameter ka step size adjust karta hai, curvature ka seedha estimate nahi karta. Bas yaad rakho: gradient = slope, Hessian = bend.

Go deeper — visual, from zero

Test yourself — Calculus & Optimization Basics

Connections