§4.3.1Beyond the Gradient: Jacobian and Hessian Matrices

Part I DL pp. 86–92 · ~6 min read

  • jacobian matrix
  • hessian matrix
  • curvature
  • second derivative test
  • newtons method
  • lipschitz continuous
  • convex optimization

For vector→vector functions, all the partial derivatives assemble into the Jacobian matrix : for f:RmRnf: \mathbb{R}^m \to \mathbb{R}^n, JRn×mJ \in \mathbb{R}^{n \times m} with Ji,j=f(x)i/xjJ_{i,j} = \partial f(\boldsymbol{x})_i / \partial x_j. And derivatives of derivatives — second derivatives — tell us how the slope itself will change as we move: they measure curvature , i.e. whether a gradient step will deliver as much improvement as the slope promised.

Negative curvaturedecreases FASTER than predictedNo curvaturegradient prediction exactPositive curvaturedecreases SLOWER — big steps can go uphilldashed: the value the gradient alone predicts for a downhill step

Fig 4.4 (recreated) — curvature bends reality away from the gradient’s linear forecast.

The Hessian

With multiple input dimensions the second derivatives collect into the Hessian matrix :

Term by term

H(f)(x)i,j=2xixjf(x)\boldsymbol{H}(f)(\boldsymbol{x})_{i,j} = \frac{\partial^2}{\partial x_i\, \partial x_j} f(\boldsymbol{x})
H\boldsymbol{H}all second derivatives — equivalently, the Jacobian of the gradientn×n
Hi,j=Hj,iH_{i,j} = H_{j,i}symmetric wherever second partials are continuous (differential operators commute) — true almost everywhere in DL, so §2.7 gives real eigenvalues + an orthogonal eigenbasissymmetric
dHd\boldsymbol{d}^\top \boldsymbol{H} \boldsymbol{d}the second derivative along unit direction d: an eigenvalue when d is an eigenvector; otherwise a 0–1-weighted average of eigenvalues (closer eigenvectors weigh more). λmax and λmin bound itscalar

How does curvature interact with a gradient step? Take the second-order Taylor approximation around x(0)\boldsymbol{x}^{(0)} and substitute the step x=x(0)ϵg\boldsymbol{x} = \boldsymbol{x}^{(0)} - \epsilon\boldsymbol{g}:

Term by term

f(x(0)ϵg)f(x(0))ϵgg+12ϵ2gHgf(\boldsymbol{x}^{(0)} - \epsilon\boldsymbol{g}) \approx f(\boldsymbol{x}^{(0)}) - \epsilon\boldsymbol{g}^\top\boldsymbol{g} + \tfrac{1}{2}\epsilon^2\, \boldsymbol{g}^\top\boldsymbol{H}\boldsymbol{g}
f(x(0))f(\boldsymbol{x}^{(0)})where we arebaseline
ϵgg-\epsilon\boldsymbol{g}^\top\boldsymbol{g}the improvement the SLOPE promises — always a decreaselinear term
+12ϵ2gHg+\tfrac{1}{2}\epsilon^2 \boldsymbol{g}^\top\boldsymbol{H}\boldsymbol{g}the curvature correction: when this outgrows the linear term, the "descent" step goes UPHILL. If gᵀHg ≤ 0 the approximation says any ε helps (don’t trust it far); if positive, the best step is ε* = gᵀg / gᵀHgquadratic term

Worked example — the worst-case step size

If g\boldsymbol{g} happens to align with the eigenvector of λmax\lambda_{\max}, then gHg=λmaxg2\boldsymbol{g}^\top\boldsymbol{H}\boldsymbol{g} = \lambda_{\max}\|\boldsymbol{g}\|^2 and ϵ=1/λmax\epsilon^* = 1/\lambda_{\max}. With λmax=4\lambda_{\max} = 4: ε* = 0.25 — any constant learning rate above 2/λmax=0.52/\lambda_{\max} = 0.5 makes steps land higher than they started (try ε > 2 in the lab below, where λmax = 1). To the extent f is locally quadratic, the Hessian’s eigenvalues SET the scale of the learning rate.

The second derivative test

At a critical point (f=0\nabla f = 0), the Hessian’s eigenvalues decide what you’re standing on — the multivariate second derivative test :

Hessian at ∇f = 0Verdict
positive definite (all λ > 0)local minimum
negative definite (all λ < 0)local maximum
some λ > 0 AND some λ < 0saddle point — max on one cross-section, min on another
all nonzero λ same sign, some λ = 0inconclusive (flat along the zero-eigenvalue cross-section)
↑ x₂: curves DOWN (λ = −2)→ x₁: curves UP (λ = +2)

Fig 4.5 (recreated as contours) — the quintessential saddle f=x12x22f = x_1^2 - x_2^2: both eigenvalue signs present. In > 1 dimension, saddles don’t need zero eigenvalues — just mixed signs.

Ill-conditioning: the canyon

In multiple dimensions there is a different second derivative in every direction; the condition number of the Hessian measures how much they disagree. A poorly conditioned Hessian is a canyon: one direction curves steeply (the walls, λmax\lambda_{\max}), another barely at all (the floor, λmin\lambda_{\min}). Gradient descent suffers doubly — it wastes steps zigzagging down the walls, and the step size must stay small enough for the walls, making floor progress glacial. This is the book’s fig 4.6, live:

Fig 4.6 (interactive) — gradient descent in a canyon: raise κ to steepen the walls, raise ε to overshoot
minimumstartcontours of f(x) = ½xᵀHx — eigenbasis at 45°, λmax = 1, λmin = 1/κ

step 0/45 · f = 137.20

Canyon regime: GD zigzags down the steep walls (λmax direction) while crawling along the floor (λmin direction) — ε must stay small for the walls, so progress along the floor is slow. Try the momentum optimizer.

Newton’s method — using the Hessian to steer

The zigzag exists because gradient descent is blind to curvature. Newton’s method solves the local second-order Taylor model exactly:

Term by term

x=x(0)H(f)(x(0))1xf(x(0))\boldsymbol{x}^* = \boldsymbol{x}^{(0)} - \boldsymbol{H}(f)(\boldsymbol{x}^{(0)})^{-1} \nabla_{\boldsymbol{x}} f(\boldsymbol{x}^{(0)})
H1\boldsymbol{H}^{-1}rescales the gradient by inverse curvature: big steps along flat directions, small steps along steep ones — exactly what the canyon needsn×n
x\boldsymbol{x}^*the critical point of the local quadratic model — for a truly positive definite quadratic, the minimum in ONE application (toggle it in the lab); otherwise iteraten×1

What this really says — and the catch

Gradient-only methods are first-order; Hessian-using methods are second-order. Newton’s method jumps to the nearest critical point — which is wonderful near a minimum and harmful near a saddle (it jumps TO the saddle; §8.2.3). Gradient descent at least isn’t attracted to saddles unless the gradient aims at them.

What guarantees can we get?

DL objectives are too complicated for most classical guarantees. Two partial refuges: Lipschitz continuity f(x)f(y)Lxy2|f(\boldsymbol{x}) - f(\boldsymbol{y})| \le L\|\boldsymbol{x} - \boldsymbol{y}\|_2, a weak bound (“small input change ⟹ small output change”) that many DL problems can be given with minor modifications — and convex optimization , the most successful specialized field: Hessian positive semidefinite everywhere, hence no saddles and every local minimum global. Most DL problems can’t be expressed convexly, so convexity survives mainly as a subroutine and a source of analysis ideas.

Check yourself — curvature and the Hessian

1.In the GradientDescentLab with κ = 5, why does the trajectory zigzag instead of heading straight for the minimum?

2.You raise ε past 2 (with λmax = 1) in the lab. Predict the behavior, and connect it to the Taylor analysis.

3.At a critical point the Hessian has eigenvalues (+3, −1). What is the point, and why?

4.Why does Newton's method fix the canyon — and when is it dangerous?

5.What makes convex functions so friendly to optimize, and what is their role in deep learning?

5 questions