7 routes42 sections324 units

Unit 2.2 · about 3 h

60 / 324

Jacobians, Hessians and Taylor approximations

Jacobians say how outputs move; Hessians say how gradients move. Taylor turns both into the local models that justify gradient steps and Newton steps.

  • derive

You can now

  • Assemble the Jacobian of a vector-valued map with consistent shapes under a stated layout.
  • Write first- and second-order Taylor approximations and bound the remainder from the Hessian size.
  • Classify a stationary point from Hessian eigenvalues on a small hand-worked example.

Covers

  • Jacobians, Hessians and consistent shape conventions
  • First- and second-order Taylor approximations

Study, in this order

3 steps

  1. Jacobians, Hessians and multivariate Taylor
    Mathematics for Machine Learning - Ch. 5

    Section 5.3 (pp. 149-154): vector-valued gradients, the Jacobian, the determinant-as-magnifier example, gradient of \(f(x) = Ax\) in (5.67)-(5.68). Section 5.7 (pp. 164-165): higher-order derivatives and Hessian symmetry for twice continuously differentiable functions. Section 5.8 (pp. 165-169): multivariate Taylor series (5.149)-(5.156) with the worked cubic \(f(x, y) = x^2 + 2xy + y^3\) at (1, 2): gradient (5.165), Hessian (5.171) and third derivatives (5.174)-(5.176)

  2. Second derivatives, bilinear forms and Hessians
    MIT 18.S096 - Matrix Calculus for ML

    Lecture 7, Part 2 notes (course notes Chapter 12): second derivatives as symmetric bilinear forms, Hessian matrices, minima versus maxima versus saddles

  3. Second-derivative test in two variables
    MIT 18.02SC - Multivariable Calculus Unit 2

    Session 30 (Part A): second-derivative test for two-variable functions

    Depth · Use only as the 2-D classification check; skip the Lagrange sessions.

Focus on

  • The Jacobian of \(f: \mathbb{R}^n \to \mathbb{R}^m\) is \(m \times n\) in numerator layout, and each row is one scalar gradient.
  • Hessian symmetry needs continuous second partials. Without \(C^2\), mixed partials can disagree and the Taylor form breaks.
  • The first-order remainder scales with the squared step times the Hessian size; the second-order remainder with the cubed step.
  • Eigenvalue signs classify: all positive is a strict local minimum, mixed signs a saddle, a zero eigenvalue leaves the test silent.

Reproduce closed-book

Closed-book, give the Hessian \(H = \left[\begin{smallmatrix}2&1\\1&2\end{smallmatrix}\right]\) of \(f(x_1, x_2) = x_1^2 + x_1 x_2 + x_2^2\), its eigenvalues 1 and 3 from numpy.linalg.eigvalsh, and classify the origin as a strict local minimum since \(H\) is positive definite. Verify the second-order Taylor model is exact: \(f(0.3, -0.2) = 0.07\), and \(0.5 d^\top H d\) in float64 gives 0.06999999999999999, one ulp (1.4e-17) below.

Traps

  • Calling a stationary point with positive diagonal Hessian entries a minimum. Off-diagonals matter; only definiteness decides.
  • Trusting a Taylor model far from the base point. The remainder grows with powers of the step, so recompute rather than extrapolate.
  • Switching gradient layout mid-derivation. The layout fixes the Jacobian and Hessian shapes, so a silent switch transposes everything.

Practice

TrenTorch: Hessian

Implement hessian(f, x) as the centered-difference Jacobian of the provided gradient, and classify_critical_point(H) from eigvalsh signs with a tolerance

Its tests call diag(1e-9, 2) a saddle, but a near-zero eigenvalue leaves the second-derivative test silent: \(x^4 + y^2\) has Hessian diag(0, 2) at its minimum. Pass the tests, then return a fourth label for that case in your own copy.

MIT 18.S096 Problem Set 1, Problem 0 (\(2 \times 2\) Jacobian matrices)

Problem 0, parts (a) to (d): Jacobian matrices of the rotate, hyperbolic rotate, nonlinear shear and warp maps. Official solutions exist; attempt before reading them

Do the hyperbolic rotation by hand; its Jacobian determinant returns in Problem Set 2, Problem 4(a), which calls it Problem 1b.

Self-test

  1. For \(f: \mathbb{R}^3 \to \mathbb{R}^2\), what is the Jacobian shape and what is its first row?

  2. Where is the \(C^2\) assumption used in the claim that the Hessian is symmetric?

  3. Approximate \(e^{0.1}\) with \(T_1\) about 0. Give the value, the remainder and a bound.

  4. Classify the stationary point with Hessian \(\left[\begin{smallmatrix}2&1\\1&2\end{smallmatrix}\right]\).

Completion criterion

Stop when

You write the Jacobian and second-order Taylor of a new \(\mathbb{R}^2\) map by hand, classify its stationary point, and NumPy eigvalsh plus a remainder evaluation agree.

Mark passed, then open 2.3 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

Also in this section

  • Hands-On ML - Autodiff notebook
    Aurelien Geronrequiredimplementation
    Work through numerical differentiation and both AD modes, then rebuild the essential reverse-mode engine independently.
  • PyTorch Autograd mechanics
    PyTorch documentationrequiredreference
    Consult after the handwritten engine for accumulation, graph behavior, disabled tracking and vector-Jacobian products.
  • CS231n - Linear Classification
    Stanford Universitysupportreference
    Read the Softmax classifier section for the cross-entropy loss formula with both the information-theory and MLE views, and Practical issues: Numeric stability for the max-subtraction trick. Derive the softmax gradient by hand; do not implement the course assignment here.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels