The Jacobian and the Hessian

The first derivative says which way is downhill. The second says how far you can safely go.

The Jacobian and the Hessian

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

The gradient collects the first partial derivatives: one number per input, saying which way is uphill.
The Jacobian generalises it to functions with several outputs — one row per output, one column per input.
The Hessian collects the second derivatives. It describes curvature: how the gradient itself changes.
Backpropagation is repeated Jacobian multiplication, done right to left because that keeps the intermediate object a vector rather than a matrix.

Overview

First derivatives as a matrix

For f: ℝⁿ → ℝᵐ, the Jacobian has one row per output and one column per input. Its entry Jᵢⱼ is ∂fᵢ/∂xⱼ. For a scalar output (m = 1), it contains the gradient components, with row-versus-column convention depending on notation.

Jᵢⱼ = ∂fᵢ / ∂xⱼ

For f(x,y) = (x² + y, xy), the Jacobian is [[2x, 1], [y, x]]. It describes the best local linear approximation to the function near a point. The multivariable chain rule multiplies Jacobians in composition order; see the chain rule.

In this guide
  1. Curvature as a second-derivative matrix
  2. Read dimensions before multiplying derivatives
  3. Try this above
  4. Sources and next steps

Jacobian and Hessian

The Jacobian collects first derivatives of a vector function; the Hessian collects second derivatives of a scalar function.

Curvature as a second-derivative matrix

For scalar f, the Hessian Hᵢⱼ = ∂²f/(∂xᵢ∂xⱼ). For f(x,y) = x² + 3y², H = [[2, 0], [0, 6]], so curvature is stronger along y. Positive curvature in every direction indicates a strict local minimum; mixed positive and negative curvature indicates a saddle, under the usual smoothness conditions.

Newton's method uses curvature to choose a step, but a neural-network Hessian is enormous and can be indefinite. Large-scale optimisers therefore use approximations or first-order methods. See matrix calculus and convexity.

Read dimensions before multiplying derivatives

If f maps n inputs to m outputs, its Jacobian has shape m×n under the row-output convention. A small input change Δx produces the first-order approximation Δf≈JΔx. For f(x,y)=(x²+y, xy), the Jacobian is [[2x,1],[y,x]], a 2×2 matrix because there are two outputs and two inputs. The multivariable chain rule composes these local linear approximations by matrix multiplication; reversing their order is a common shape and meaning error.

For a scalar-valued function, the Hessian is the matrix of second partial derivatives. When second derivatives are continuous, mixed partials agree and the Hessian is symmetric. At a stationary point, positive curvature in every direction identifies a strict local minimum; mixed positive and negative curvature identifies a saddle. Positive semidefinite curvature alone may be inconclusive, and a local minimum need not be global unless additional conditions such as convexity hold. Newton's method uses curvature to scale an update, but an indefinite Hessian or ill-conditioned matrix can make that step unsafe.

Try this above

Compare the Jacobian entries as you move the input, then inspect how the Hessian changes the local curvature estimate.

In a one-dimensional problem, the Jacobian reduces to the ordinary derivative and the Hessian to the second derivative. In several dimensions, the Hessian stores how each gradient component changes with each input. For f=x²+3y², the diagonal entries 2 and 6 indicate the quadratic bowl is steeper along y. Off-diagonal terms describe interaction in curvature. The Hessian is local: it describes curvature near one point and can change elsewhere. For a nonconvex function, checking curvature at one point does not establish global behaviour.

The Hessian can guide a local quadratic approximation, but forming it explicitly costs memory proportional to the square of the number of parameters. For a neural network with millions of parameters, that is often impractical. First-order methods use gradients; second-order methods may use Hessian-vector products or approximations instead. A small Hessian example teaches curvature, but implementation should account for shape, symmetry, conditioning, and computational scale.

Sources and next steps

Check yourself

0 of 3

Answer without scrolling back up.

  1. What does the Hessian tell you that the gradient does not?

  2. Why is Newton's method not used to train large neural networks?

  3. Why does backpropagation multiply Jacobians right to left?

Cheat sheet

The Jacobian and the Hessian

Compute the Jacobian and Hessian for small functions. See how optimisers use first and second derivatives to choose direction and step size.

MATHS · vizlearn.in/maths/jacobian_and_hessian.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.