Jacobian, Hessian and convexity

When there are several inputs, the derivative is no longer one number. It becomes a table. The Jacobian tells you how a function stretches and turns the plane at one spot. The Hessian tells you how a landscape bends at one spot. It also tells you whether a place where the gradient is 0 is a bottom, a top or a saddle point. Move the points and see.

Short answer. The Jacobian is the table (matrix) of all partial derivatives of a function with several inputs and several outputs. Very close up, the function stretches and turns the plane just like this matrix does. The Hessian is the table of second derivatives. It tells you which way the landscape bends at that spot, and by how much. Where the gradient is 0, the eigenvalues of the Hessian tell a bottom (both +), a top (both −) and a saddle point (different signs) apart.

Input plane. Drag point P
Where F sends it
Around F(P), zoomed in by 1/h

Point P (r, θ) = ( , )

Jacobian J at P

Drag point P in the top left picture, or type numbers. Top left is the input plane. Top right is where F moves its grid. The orange square is a small square with side h around P, and the shape it moves to. The bottom picture puts F(P) in the middle and zooms that shape in by 1/h. The black dashed shape is the parallelogram the Jacobian J makes from the same square. The green and blue arrows are the first and second columns of J. Move the "Square side h" slider to the right to make h smaller, and the two shapes come together.

Definitions

The text below uses functions with two inputs and two outputs, but the definitions are the same for any number. A point is written 𝐱=(x1,…,xn), and we assume the partial derivatives we need exist.

Jacobian matrix
For a function F=(F1,…,Fm):ℝn→ℝm, the m×n matrix with the partial derivative ∂Fi∂xj in row i, column j. When m = n, its determinant det JF is called the Jacobian determinant.

JF(𝐱)=[∂F1∂x1⋯∂F1∂xn⋮⋱⋮∂Fm∂x1⋯∂Fm∂xn]

Hessian matrix
For a function f:ℝn→ℝ, the n×n matrix with the second partial derivative ∂2f∂xi∂xj in row i, column j. If all second partial derivatives are continuous, the order of differentiation does not change the value, so the matrix is symmetric.

Hf(𝐱)=[∂2f∂x12⋯∂2f∂x1∂xn⋮⋱⋮∂2f∂xn∂x1⋯∂2f∂xn2]

critical point
If f is differentiable at a point x₀ and its gradient there is the zero vector, x₀ is called a critical point (stationary point) of f. Some books also count points where a partial derivative does not exist.

∇f(𝐱0)=0

saddle point
A critical point x₀ that is neither a local maximum nor a local minimum. That is, every neighborhood of x₀ has both points with f(𝐱)>f(𝐱0) and points with f(𝐱)<f(𝐱0).
second derivative test
At a critical point x₀ of a function f with continuous second partial derivatives: if the eigenvalues of the Hessian Hf(x₀) are all positive, it is a local minimum; if they are all negative, a local maximum; if there are both positive and negative ones, a saddle point. In the other cases (an eigenvalue is 0 and there are not both positive and negative ones) this test cannot tell. With two variables you can use D below instead. D > 0 and fxx > 0 means a local minimum, D > 0 and fxx < 0 a local maximum, D < 0 a saddle point, and D = 0 cannot tell.

D=fxx(𝐱0)fyy(𝐱0)−fxy(𝐱0)2=detHf(𝐱0)

convex function
A function f defined on a convex set is convex if the inequality below holds for every two points x, y and every 0 ≤ t ≤ 1. If the domain is an open convex set and f is twice differentiable, f is convex exactly when the Hessian is positive semidefinite (all eigenvalues 0 or more) at every point.

f(t𝐱+(1−t)𝐲)≤tf(𝐱)+(1−t)f(𝐲)

1. The Jacobian: a table of all the partial derivatives

A derivative was the slope of a function with one input and one output. Partial derivatives and the gradient were the slopes of a function with several inputs and one output (a spot on a map → the height of the ground). Now the function has several outputs too. The first function in the experiment takes a distance r and an angle θ and gives back a spot (x, y) on the plane.

F(r,θ)=(rcosθ,rsinθ)turns a distance and an angle (polar coordinates) into ordinary coordinates

For every pair of one output and one input there is one partial derivative. 2 outputs × 2 inputs = 4 of them. Laid out as a table, they form the Jacobian.

move only rmove only θ
output x∂x/∂r∂x/∂θ
output y∂y/∂r∂y/∂θ

2. Work it out by hand: the Jacobian of polar coordinates

  1. Write down the outputs. x = r cos θ, y = r sin θ.
  2. Take the partial derivative by r (keep θ fixed). Treat cos θ and sin θ as fixed numbers. ∂x/∂r = cos θ, ∂y/∂r = sin θ. This is the first column.
  3. Take the partial derivative by θ (keep r fixed). ∂x/∂θ = −r sin θ, ∂y/∂θ = r cos θ. This is the second column.
  4. Put them in a table. Top row cos θ, −r sin θ, bottom row sin θ, r cos θ.
  5. Find the determinant. cos θ × r cos θ − (−r sin θ) × sin θ = r × (cos²θ + sin²θ) = r. cos²θ + sin²θ is always 1.
  6. Put in numbers. For r = 2 and θ = 0.5 (radians), cos 0.5 ≈ 0.88 and sin 0.5 ≈ 0.48, so the top row is 0.88, −0.96 and the bottom row is 0.48, 1.76. The determinant is exactly 2. This is the first screen of the experiment.

Here is the same work written as formulas.

J=[∂x∂r∂x∂θ∂y∂r∂y∂θ]=[cosθ−rsinθsinθrcosθ]

detJ=cosθ·rcosθ−(−rsinθ)·sinθ=r(cos2θ+sin2θ)=r

J(2,0.5)≈[0.88−0.960.481.76],detJ(2,0.5)=2

What it means: a tiny square near P moves to something very close to a parallelogram with twice the area. Far from the center (large r), the same angle covers a longer arc, so things spread out more. At r = 0 the determinant is 0 too, because every angle lands on the same single point, the center.

Try this. With Polar selected: ① At the start (P = (2, 0.5), h = 1), the determinant is 2, and the area after F ÷ h² is also 2. ② Move P to r = 1 and you get 1. At r = 3 you get 3. Changing θ does not change the determinant. ③ Move to r = 0 and the determinant is 0. The parallelogram in the bottom picture is squashed onto a line.

3. Up close, it is a matrix

Even a curved function does almost the same thing as a single matrix when you look very close up. If you move from P by a small arrow d, the output moves by about J × d.

F(P+𝐝)≈F(P)+J𝐝

This is f(x + h) ≈ f(x) + f′(x) × h from the derivative page, made two-dimensional. There you multiplied by the number f′(x). Here you multiply by the matrix J, the same way as in matrix multiplication.

The bottom picture of the experiment shows this. It takes a square with side h, moves it with F (orange) and with J (black dashes), zooms both in by the same amount and puts them on top of each other. When h is large, the orange shape is curved and they do not match. When h gets small, they almost match. How far apart they are shrinks in step with h.

So what you learned about the determinant works at that spot too.

Try this. ① With Polar and P = (2, 0.5), make "Square side h" go 1 → 0.1 → 0.01. The largest gap goes 0.365 → 0.035 → 0.004. Make h ten times smaller and the gap gets about ten times smaller too. ② Pick Wave and put P at (0, 0). The determinant is 0.75. The area after F ÷ h² is 0.82 at h = 2, 0.77 at h = 1 and 0.75 at h = 0.2, getting closer to the determinant. ③ Pick Fold and set the x of P to 1, 0 and −1. The determinant is 2, 0 and −2. At −2 the green arrow in the bottom picture points left.

Integrals use this area factor too. When you add up the area of a round piece of land by cutting it into small pieces in (r, θ) instead of (x, y), one small (r, θ) square is really r times as large. That is why you write r dr dθ in place of dx dy. When you change variables in an integral, you multiply by the size of the Jacobian determinant (integrals).

4. The chain rule multiplies Jacobians

For functions with one input, you multiplied the slopes of the steps (the chain rule). With several inputs and outputs, you multiply Jacobians instead. If you do G first and F second:

JF∘G(𝐩)=JF(G(𝐩))JG(𝐩)((F∘G)(𝐩)=F(G(𝐩)))

The later step goes on the left. You measure the outer step's Jacobian at G(p), the spot that comes out of the inner step, not at p. This is the same trap as on the derivative page.

Example: G is the polar change of coordinates, and F is F(x, y) = x² + y², which has one output. The Jacobian of F is the single row [2x 2y].

  1. Multiply. Row × table: [2x cos θ + 2y sin θ, −2x r sin θ + 2y r cos θ].
  2. Put in x = r cos θ and y = r sin θ. First entry 2r cos²θ + 2r sin²θ = 2r, second entry −2r² cos θ sin θ + 2r² sin θ cos θ = 0.
  3. Check. The result is [2r 0]. Combining first gives F(G(r, θ)) = r² cos²θ + r² sin²θ = r², and taking the derivative directly gives 2r by r and 0 by θ. They match. For r = 2 it is [4 0].

Backpropagation multiplies Jacobians starting from the back. A neural network is a chain of functions, one for each layer, and the loss at the very end is a single number. So the last Jacobian is a single row. If you multiply from the back, every step is "one row × matrix = one row", which is cheap. If you multiply from the front, you have to do "big matrix × big matrix". Real programs never even build the full Jacobian matrices. They compute "one row × Jacobian" directly (a vector-Jacobian product). See backpropagation for more.

5. The Hessian: a table of second derivatives

Now back to a function with one output, the height of the ground f(x, y). The gradient (∂f/∂x, ∂f/∂y) is the slope at that spot. The slope also changes from spot to spot, so you can take partial derivatives of it by x and by y once more. Put the four results in a table and you get the Hessian.

once more by xonce more by y
∂f/∂xf_xxf_xy
∂f/∂yf_yxf_yy

The Hessian is the Jacobian of the gradient. The gradient is itself a function with two inputs (x, y) and two outputs (the two partial derivatives).

The Hessian also tells you how much the ground bends in any one direction. For a direction u of length 1, the bending is uᵀ H u (the dot product of u and H u). The directions where this is largest and smallest are the eigen directions of the Hessian, and the bending in those directions is the eigenvalues. Because the Hessian is symmetric, its eigenvalues are always real numbers and its two eigen directions are at right angles.

Example: f(x, y) = x³ − 3x + y². ∂f/∂x = 3x² − 3 and ∂f/∂y = 2y. Taking derivatives once more gives f_xx = 6x, f_xy = f_yx = 0 and f_yy = 2. At P = (0.5, 1) the Hessian is [3 0 / 0 2] (top row before the /, bottom row after it), and the eigenvalues are 3 (x direction) and 2 (y direction).

The ground can bend even when the diagonal is 0. The Hessian of f = xy is [0 1 / 1 0]. It does not bend in the x or y direction, but its eigenvalues are 1 and −1, with eigen directions (1, 1) and (1, −1). It bends up along one diagonal and down along the other.

The ground in 3D
Contour map from above. Drag point P

Point P = ( , )

Hessian H at P

Drag point P on the map on the right, or type numbers. The lines on the map are contour lines that join points of the same height. Darker means higher. The green line is the direction that bends up the most (λ₁), and the blue line is the direction that bends the least (λ₂). A direction with a negative eigenvalue (bending down) is drawn dashed. The green and blue curves in the 3D picture on the left are slices of the ground along those directions. The black arrow is the gradient (drawn at 1/4 length). Turn on "Show the quadratic approximation" to lay the paraboloid made from the Hessian over the ground as an orange net. An orange ring on the map shows where that paraboloid is flat (where Newton's method goes).

6. The second derivative test: bottom, top or saddle point

Where the gradient is (0, 0), the ground does not slope in any direction. This is called a stopping point (a critical point). It might be a bottom, a top, or a saddle point, like the middle of a horse saddle: uphill one way and downhill another way. The slope is 0, so the slope alone cannot tell them apart. You have to look at the bending (the Hessian).

At a stopping point P the gradient is 0, so the height nearby is f(P + d) ≈ f(P) + ½ dᵀ H d. If ½ dᵀ H d is + in every direction, every way goes up. The signs of the eigenvalues decide this. To see, picture by picture, how the table below comes out of this formula, go to How the formula is built.

Eigenvalues of the HessianShapeExamples (at the origin)
both +Bottom (local minimum). Every way goes upx² + y², x² + 4y²
both −Top (local maximum). Every way goes down−x² − y²
one +, one −Saddle point. Up along λ₁, down along λ₂x² − y², xy
one is 0Cannot tell. You need third order or higher in that directionx², x² + y⁴, x² − y⁴

A shortcut without finding the eigenvalues. The determinant of the Hessian is the product of the two eigenvalues, and the trace (f_xx + f_yy) is their sum (see eigenvalues). So:

7. How the formula is built: the second derivative test

The table above only gives the results. Here you build it step by step, by cutting the ground around a stopping point one direction at a time. The starting example is the stopping point (−1, 0) of "Hill and saddle x³ − 3x + y²" from the lab above.

Map from above. The orange bar is the cutting direction θ
Top: the slice along that direction. Bottom: the bend for each direction

Press "Next" to go one step at a time. Each step changes the two pictures by that much, adds one line to the formula under the pictures (the orange background marks the line just added), and explains why at the bottom. You can move the "Cutting direction θ" slider at any step. The orange bar on the map is the cutting direction, and the arrow points to where t is +. The top of the second picture is the slice along that direction (across: the distance t from P, up: how much higher than f(P)). The thick gray line is the real ground and the orange line is the quadratic approximation. The bottom is the bend k(θ) for each direction θ. Green and blue are the eigenvalues λ₁ and λ₂ and their directions. The purple dotted line is the middle of the wave.

Written only as formulas, the steps above are:

∇f(P)=0⇒f(P+𝐝)≈f(P)+12𝐝𝖳H𝐝=f(P)+12(fxxdx2+2fxydxdy+fyydy2)

𝐝=t𝐮=t(cosθ,sinθ)⇒f(P+t𝐮)≈f(P)+12k(θ)t2

k(θ)=𝐮𝖳H𝐮=fxxcos2θ+2fxycosθsinθ+fyysin2θ=m+fxx−fyy2cos2θ+fxysin2θ

m=fxx+fyy2,R=(fxx−fyy2)2+fxy2,λ2=m−R≤k(θ)≤m+R=λ1

λ1λ2=fxxfyy−fxy2=detH,λ1+λ2=fxx+fyy=trH

(−1,0):H=[−6002],m=−2,R=4,λ1=2,λ2=−6,detH=−12<0

θ=30∘:k=−6×0.75+2×0.25=−4

Here is the same thing in words. The numbers are for the starting example (−1, 0) and θ = 30°.

  1. The slope term drops out. In the quadratic approximation f(P + d) ≈ f(P) + ∇f · d + ½ dᵀ H d (the quadratic approximation and Newton's method), a stopping point has ∇f = (0, 0), so the middle term is 0. Written out, the ½ dᵀ H d that is left is ½(f_xx·dx² + 2f_xy·dx·dy + f_yy·dy²). At (−1, 0), f = 2 and the Hessian is [−6 0 / 0 2], so f ≈ 2 − 3dx² + dy². The real height is 2 − 3dx² + dx³ + dy², so the only difference is dx³, and it shrinks faster than the bending terms as you get closer to P.
  2. Cut along one direction and you get one parabola. Go a distance t along a direction of length 1, u = (cos θ, sin θ). Then dx = t cos θ and dy = t sin θ. Put these in, and the three terms collapse into one: ½ · k(θ) · t². Here k(θ) = f_xx cos²θ + 2f_xy cos θ sin θ + f_yy sin²θ, which is the same as uᵀ H u from section 5. For θ = 30°, k = −6 × 0.75 + 2 × 0.25 = −4, and the slice is the parabola −2t², which opens down.
  3. Turn all the way around and you get a wave whose ends are the eigenvalues. Use cos²θ = (1 + cos 2θ) ÷ 2, sin²θ = (1 − cos 2θ) ÷ 2 and 2 sin θ cos θ = sin 2θ. Then k(θ) = m + (f_xx − f_yy) ÷ 2 × cos 2θ + f_xy × sin 2θ with m = (f_xx + f_yy) ÷ 2. The part that mixes cos and sin is a wave that goes up and down by the radius R = √(((f_xx − f_yy) ÷ 2)² + f_xy²). So k stays between m − R and m + R and reaches both ends. The two roots of the eigenvalue equation λ² − (f_xx + f_yy)λ + (f_xx f_yy − f_xy²) = 0 are also m ± R. So the most bending is λ₁ and the least bending is λ₂. At (−1, 0), m = −2 and R = 4, so λ₁ = 2 (at 90°) and λ₂ = −6 (at 0°).
  4. The signs decide the shape. The bend in any direction lies between λ₂ and λ₁. If λ₂ > 0, every slice is a parabola that opens up: a bottom. If λ₁ < 0, every slice opens down: a top. If λ₁ > 0 > λ₂, some directions open up and some open down: a saddle point. At (−1, 0), k is 0 at 60° and 120°. Cut between them (around 90°) and the slice opens up. Cut anywhere else and it opens down. The difference between the real ground and the quadratic approximation shrinks faster than t² as you get closer to P, so very close to P the sign of the bending term wins (we do not prove this here). If an eigenvalue is 0, the bending term is 0 in that direction, so the leftover difference (third order and beyond) decides the shape. That is why you cannot tell.
  5. The shortcut with the determinant and the trace. The product and the sum of the two roots of a quadratic equation come straight from its coefficients: λ₁ × λ₂ = f_xx f_yy − f_xy² (the determinant of the Hessian) and λ₁ + λ₂ = f_xx + f_yy (the trace). If the product is −, the signs differ: a saddle point. If the product is +, the signs are the same, and that sign is the sign of the sum. When the product is +, f_xx f_yy > f_xy² ≥ 0, so f_xx and f_yy also have the same sign. That is why you can look at f_xx instead of the trace, as in the list above. At (−1, 0) the determinant is −6 × 2 − 0² = −12 < 0 → saddle point.

Try this. ① With the starting example, go to step 2 and turn the bar to 90°. Then k = 2 and the slice opens up. At 60°, k = 0, so the quadratic approximation is a flat line (the real ground still bends a little because of dx³). ② Pick "Diagonal saddle xy". From step 1 the real ground and the quadratic approximation are the same, because the ground is already a quadratic formula. At step 3, λ₁ = 1 (at 45°) and λ₂ = −1 (at 135°). It bends along the diagonals even though f_xx and f_yy are 0. ③ For "Upside-down bowl", the wave at step 3 is a flat line stuck at −2. ④ Look at "Flat valley x²" at step 4. The wave touches 0 at 90°, and it says "cannot tell". ⑤ Look at (1, 0) of "Hill and saddle" at step 5. The determinant is 12 and the trace is 8 → bottom.

8. Work it out by hand: the stopping points of x³ − 3x + y²

  1. Find the gradient. ∇f = (3x² − 3, 2y).
  2. Set it to 0. 3x² − 3 = 0 gives x = 1 or −1, and 2y = 0 gives y = 0. There are two stopping points, (1, 0) and (−1, 0).
  3. Find the Hessian. [6x 0 / 0 2].
  4. (1, 0): Hessian [6 0 / 0 2]. Eigenvalues 6 and 2, both + → bottom. Height 1 − 3 + 0 = −2. With the shortcut: determinant 12 > 0, f_xx = 6 > 0.
  5. (−1, 0): Hessian [−6 0 / 0 2]. Eigenvalues 2 and −6, different signs → saddle point. Height −1 + 3 + 0 = 2. With the shortcut: determinant −12 < 0.

Here is the same work written as formulas.

∇f=(3x2−3,2y)=(0,0)⇒(x,y)∈{(1,0),(−1,0)}

H=[fxxfxyfyxfyy]=[6x002]

H(1,0)=[6002]:detH=12>0,fxx=6>0⇒local minimum,f(1,0)=1−3+0=−2

H(−1,0)=[−6002]:detH=−12<0⇒saddle point,f(−1,0)=−1+3+0=2

On the derivative page, x = −1 was a top of x³ − 3x. Adding y² makes the ground bend up in the y direction, so the same spot becomes a saddle point instead of a top. Looking in only one direction can miss things.

Try this. With "Hill and saddle": ① At the start, P = (0.5, 1) has gradient (−2.25, 2), so "This is not a stopping point". ② Press "Go to a stopping point". P moves to the nearest one, (1, 0), and the eigenvalues 6 and 2 make it a bottom. ③ Move P to (−1, 0). The eigenvalues 2 and −6 make it a saddle point. In the 3D picture the green slice bends up and the blue slice bends down. ④ At the origin of "Diagonal saddle xy" the eigenvalues are 1 and −1, and the two lines lie along the diagonals. ⑤ In "Flat valley x²", put P at (0, 0.7). The eigenvalues are 2 and 0, so it says "Cannot tell". On this ground, the whole line x = 0 is the bottom.

9. The quadratic approximation and Newton's method

Even away from a stopping point, the Hessian lets you approximate the ground near that spot with a paraboloid (a curved surface shaped like a bowl or a saddle). It is the flat plane you get from the slope, with the bending added.

f(P+𝐝)≈f(P)+∇f·𝐝+12𝐝𝖳H𝐝

This is the Taylor series up to second order (Taylor series). Example: at P = (0.5, 1), f = −0.375, ∇f = (−2.25, 2) and the Hessian is [3 0 / 0 2]. For d = (0.5, 0) the quadratic approximation is −0.375 + (−2.25 × 0.5) + ½ × 3 × 0.5² = −1.125, and the real height f(1, 1) is −1. For d = (0.1, 0) you get −0.585 and −0.584, almost the same. The closer you are, the better it fits.

Newton's method jumps straight to the place where this paraboloid is flat. Setting the paraboloid's gradient ∇f + H d to 0 gives d = −H⁻¹ ∇f (H⁻¹ is the inverse matrix). With one input it is x ← x − f′(x) ÷ f″(x).

Try this. Turn on "Show the quadratic approximation". ① At P = (0.5, 1), the orange net hugs the ground near P and pulls away further out. The orange ring on the map (one Newton step) is at (1.25, 0). ② Move P to (−0.5, 1). The net becomes saddle-shaped, and the ring is at (−1.25, 0). ③ On "Bowl", the ring is at (0, 0) wherever you put P. ④ On "Flat valley", the determinant of the Hessian is 0, so no ring appears.

10. Convex functions: bowl-shaped everywhere

Pick two points on the ground and lay a straight stick between them. If, for any two points you pick, the stick never cuts into the ground (it stays above it or touches it), the function is convex. For a function you can take the derivative of twice, you can say the same thing with the Hessian: it is convex when the eigenvalues of the Hessian are 0 or more at every spot. It bends up or stays flat everywhere, and never bends down.

Why convex is nice. Any place where the gradient is 0 is the lowest place of all. You do not have to worry "is this bottom only low nearby?", and as long as the step size is right, gradient descent reaches the lowest height from any starting point. If the eigenvalues are above 0 everywhere, there is only one lowest point. The losses of least squares and logistic regression are convex, so where gradient descent stops is the lowest place.

Press "Roll the balls" and balls roll down from twelve starting points (hollow circles) all at once, using gradient descent. The starting points come from a fixed seed (the starting value for the random numbers), so they are the same every time. The strip under the slider shows the range of step sizes η. The green part is the range where balls do not fly away from the bottom (up to 2 ÷ λ), and the orange part is beyond it.

Try this. ① On "Bowl" with η = 0.3, all 12 balls stop at (0, 0) (the slowest takes 9 steps). The ground is convex, so every start ends at the same bottom. ② "Four wells" is not convex. Roll with η = 0.05 and the balls split up: 4 at (1, 1), 3 at (1, −1), 3 at (−1, 1) and 2 at (−1, −1). Which well a ball starts near decides where it ends.

11. The step size limit: 2 ÷ λ

On bowl-shaped ground, the Hessian decides how large the step size can be. For a bowl f = ½ dᵀ H d with its bottom at the origin, the gradient is H d. Split one gradient descent step d ← d − η H d along the eigen directions, and the distance along each direction gets multiplied by (1 − η λ) in one step.

The bowl x² + y² has the Hessian [2 0 / 0 2], so λ = 2 and the limit is 1. With η = 0.5, the ball reaches the bottom in one step.

Long bowls are slow. x² + 10y² has eigenvalues 20 (the y direction) and 2 (the x direction). The steep y direction sets the limit at 2 ÷ 20 = 0.1. But with such a small step, the gentle x direction only shrinks to about 1 − 0.1 × 2 = 0.8 times per step. The largest eigenvalue ÷ the smallest eigenvalue is called the condition number. Here it is 10. The larger the condition number, the more the steep direction zigzags and the more the gentle direction crawls, so it takes a long time to reach the bottom.

Try this. ① On "Bowl", set η to 0.5 and every ball stops in 1 step. At 0.9 they zigzag and take 37 steps. At 1, none of the 12 balls stops within 1000 steps (they bounce back and forth). From 1.01 up, they all fly off. ② On "Very long bowl", the starting η = 0.09 zigzags and takes 46 steps. Wherever you move the slider below 0.1, it never gets faster than 44 steps. At η = 0.105, they all fly off. ③ The bottoms of "Four wells" have the Hessian [8 0 / 0 8], so the limit is 0.25. Roll with η = 0.25 and the balls bounce back and forth around the bottoms without stopping.

Methods like momentum and Adam, which reduce this zigzag, can be compared directly on the gradient descent page.

12. The loss landscape of a neural network

The loss of a neural network is a landscape with millions of weights or more. Here is what is known about it, stated carefully.

The Hessian is too big. With n weights, the Hessian has n × n entries. With a million weights that is a trillion (10¹²) entries, and even at 4 bytes per number that is 4 TB. Solving with it the way Newton's method does takes even more work. So large models do not use the Hessian directly.

13. Properties to know

PropertyIn plain words
Jacobian: rows = outputs, columns = inputsOne column is "the arrow the output follows when you move only that input a little". With one output it has one row, and that row is the gradient
F(P + d) ≈ F(P) + J × dVery close up, even a curved function moves things like a single matrix
Determinant of the Jacobian = area factor at that spotNegative means flipped, 0 means squashed. For polar coordinates it is r
Chain rule = product of JacobiansThe later step goes on the left. Backpropagation multiplies from the back
Hessian = Jacobian of the gradient, always symmetricReal eigenvalues, eigen directions at right angles. Eigenvalue = how much it bends in that direction
Gradient 0 + signs of the eigenvalues → shapeBoth + bottom, both − top, different signs saddle point, a 0 means cannot tell
Convex = eigenvalues ≥ 0 everywhereWhere it stops is the lowest place
Step size < 2 ÷ λ_maxBeyond it, balls fly off. A large condition number means slow zigzags

Where is it used?

Frequently asked questions

What is the difference between the Jacobian and the gradient?

The gradient collects the partial derivatives of a function with one output. The Jacobian is the table you get when there are several outputs, with one row for each output. If there is only one output, the Jacobian has one row, and that row is the gradient.

Why is the Hessian always symmetric?

For a smooth function (one whose second derivatives do not jump), taking the derivative by x first and then by y gives the same result as doing it in the other order. Because of this, the eigenvalues of the Hessian are always real numbers, and its two eigen directions are at right angles.

When does the test fail even though the gradient is 0?

When one of the eigenvalues of the Hessian is 0. The bending (second order) alone cannot tell you the shape in that direction. For example, x² + y⁴ and x² − y⁴ have the same Hessian at the origin, [2 0 / 0 0], but the first one is a bottom and the second one is a saddle point.

Why is convexity nice?

For a convex function, any place where the gradient is 0 is the lowest place of all. You never get stuck in a bottom that is only low nearby, and as long as the step size is right, gradient descent reaches the lowest height from any starting point.

Why don't people use the Hessian directly to train neural networks?

With n weights, the Hessian has n × n entries, so a million weights give a trillion entries. That is hard to store and hard to compute. So people use only the gradient, compute only the Hessian times one arrow, or use methods like Adam that remember how large the slopes are for each weight and adjust the step for each weight.

Words

What this page saysWhat textbooks call it
table of all the partial derivativesJacobian matrix. J, ∂(x, y)/∂(r, θ)
determinant of the Jacobian, area factor at that spotJacobian determinant. Some books call only this "the Jacobian"
up close, it is a matrixlinear approximation, linearization
one row × Jacobianvector-Jacobian product (VJP)
table of second derivativesHessian matrix. H, ∇²f
derivative by x, then by ymixed partial derivative. f_xy, ∂²f/∂x∂y
the order of the derivatives does not matterSchwarz's theorem, Clairaut's theorem
stopping point (where the gradient is 0)critical point, stationary point
bottom / toplocal minimum / local maximum
uphill one way, downhill anothersaddle point
telling them apart by the signs of the eigenvaluessecond derivative test
all eigenvalues + / all 0 or morepositive definite / positive semidefinite
bowl-shaped everywhereconvex function
lowest place of allglobal minimum
paraboloid estimate at that spotquadratic approximation, second-order Taylor expansion
jumping to where the paraboloid is flatNewton's method
methods that use an estimate of the Hessianquasi-Newton methods. BFGS, L-BFGS
Hessian × one arrowHessian-vector product
largest eigenvalue ÷ smallest eigenvaluecondition number
step size ηlearning rate, step size

Sources

← Taylor approximationProbability and Bayes' theorem →