Dive into Deep Learning · §34.2
Multivariable Calculus
partial derivatives · the gradient · directional derivatives · level sets · the Hessian · critical points · Lagrange multipliers
Motivation
Coordinate Slices
First-Order Linear Model
Differentiability Pitfall
Numerical Verification
Differentiability promises only that the linear approximation error is o(\|\boldsymbol{\epsilon}\|), but for smooth functions like log-sum-exp, cutting the step \boldsymbol{\epsilon} = (0.01, -0.03) tenfold shrinks the gap a hundredfold:
gradient: [0.33333333 0.66666667]
|eps| 3.2e-02: linear 1.08194562, true 1.08212418, gap 1.786e-04
|eps| 3.2e-03: linear 1.09694562, true 1.09694740, gap 1.779e-06
|eps| 3.2e-04: linear 1.09844562, true 1.09844564, gap 1.778e-08
At \|\boldsymbol{\epsilon}\| = 3.2 \times 10^{-2}, the linear model misses by 1.786 \times 10^{-4}; shrinking \|\boldsymbol{\epsilon}\| by 10\times and 100\times drops the gap to 1.779 \times 10^{-6} and 1.778 \times 10^{-8}, demonstrating quadratic O(\|\boldsymbol{\epsilon}\|^2) error decay.
Projections of the Gradient
First-Order Optimization
Contour Geometry
Surface Linearization
First-Order Optimality
Second Partial Derivatives
Mixed Partials
Quadratic Approximation
Second-Order Accuracy
For log-sum-exp at (0, \log 2) with step \boldsymbol{\epsilon} = (0.01, -0.03), the quadratic term \tfrac{1}{2}\boldsymbol{\epsilon}^\top \mathbf{H}_f \boldsymbol{\epsilon} = \tfrac{1}{9}(\epsilon_1 - \epsilon_2)^2 = \tfrac{1}{9}(0.04)^2 \approx 1.7778 \times 10^{-4} predicts the measured gap 1.786 \times 10^{-4} to three digits:
9 H = [[2.0, -2.0], [-2.0, 2.0]]
eigenvalues: [0. 0.444444]
|eps| 3.2e-02: predicted gap 1.7778e-04
|eps| 3.2e-03: predicted gap 1.7778e-06
The tiny residual difference (\approx 8 \times 10^{-7}) between the true gap and \tfrac{1}{2}\boldsymbol{\epsilon}^\top \mathbf{H}_f \boldsymbol{\epsilon} is the third-order O(\|\boldsymbol{\epsilon}\|^3) Taylor term, which drops a thousandfold when \|\boldsymbol{\epsilon}\| shrinks tenfold.
3D Quadratic Fit
Third-Order Remainder
Evaluating \psi(x, y) and its second-order quadratic approximation q(x, y) at steps (-1 + d, d) away from (-1, 0) confirms that the remainder scales as O(d^3):
step 0.00: psi = -0.367879, quadratic = -0.367879, gap = 0.000000
step 0.05: psi = -0.384315, quadratic = -0.384434, gap = 0.000119
step 0.10: psi = -0.396388, quadratic = -0.397310, gap = 0.000921
step 0.30: psi = -0.391929, quadratic = -0.412025, gap = 0.020096
Doubling the coordinate step d from 0.05 to 0.10 multiplies the gap |\psi - q| by nearly 8 = 2^3 (0.000119 \to 0.000921). Jumping directly to the minimizer of this local quadratic model at each step is multivariable Newton’s method.
Critical Point Classification
At a critical point \nabla f(\mathbf{x}_0) = \mathbf{0}, expanding \mathbf{v} in the orthonormal eigenbasis \{(\lambda_i, \mathbf{q}_i)\} of the symmetric Hessian \mathbf{H} = \mathbf{H}_f(\mathbf{x}_0) diagonalizes the quadratic form:
\mathbf{v}^\top \mathbf{H} \mathbf{v} = \sum_{i=1}^n \lambda_i (\mathbf{q}_i^\top \mathbf{v})^2
Proposition (Second-Order Optimality Conditions at \nabla f(\mathbf{x}_0) = \mathbf{0}):
Geometric Classification
Finite-Difference Hessians
Computing a 2 \times 2 Hessian from centered second differences and classifying critical points by their eigenvalues requires a positive zero-tolerance tol so finite-difference truncation error along flat quartic directions is not mistaken for genuine curvature:
(-0.7071, 0): eigenvalues +0.858, +1.716 -> minimum
(+0.7071, 0): eigenvalues -1.716, -0.858 -> maximum
(+0.0000, 0): eigenvalues -4.000, +4.000 -> saddle
(+0.0000, 0): eigenvalues +0.000, +2.000 -> inconclusive
On the trough x^2 + y^4 at (0, 0), the true second partial \partial_{yy} f(0, 0) is 0, but finite differences with step h = 10^{-4} return 2h^2 = 2 \times 10^{-8} > 0. Setting tol=1e-6 rightly flags the second-order test as inconclusive.
Random Matrix Theory
Constraint Surfaces
Review & Practice
Test your understanding of directional derivatives, Hessian eigenvalues, and Lagrange multipliers:
Answers:
Key Takeaways
| Mathematical Object / Rule | Formula & Condition | Geometric & Deep Learning Interpretation |
|---|---|---|
| Multivariable Linear Model | \ell(\mathbf{w}+\boldsymbol{\epsilon}) = \ell(\mathbf{w}) + \boldsymbol{\epsilon}\cdot\nabla_{\mathbf{w}}\ell(\mathbf{w}) + o(\|\boldsymbol{\epsilon}\|) | Holds when partials are continuous (C^1); predicts joint weight moves |
| Directional Derivative | D_{\mathbf{u}}\ell(\mathbf{w}) = \mathbf{u} \cdot \nabla_{\mathbf{w}}\ell(\mathbf{w}) (\|\mathbf{u}\|_2 = 1) | Instantaneous slope along ray \mathbf{u}; bounded in [-\|\nabla\ell\|_2, +\|\nabla\ell\|_2] |
| Steepest Descent & Contours | \mathbf{u}^\star = -\nabla\ell / \|\nabla\ell\|_2; \mathbf{v}_{\text{tangent}} \cdot \nabla\ell = 0 | -\nabla\ell points downhill perpendicular to level sets \{\ell = c\} |
| Symmetric Hessian \mathbf{H}_f | [\mathbf{H}_f]_{ij} = \frac{\partial^2 f}{\partial x_i \partial x_j} = \frac{\partial^2 f}{\partial x_j \partial x_i} | Captures surface curvature; for log-sum-exp, \mathbf{H} = \operatorname{diag}(\mathbf{p}) - \mathbf{p}\mathbf{p}^\top |
| Second-Order Taylor Model | f(\mathbf{x}_0+\boldsymbol{\delta}) \approx f(\mathbf{x}_0) + \nabla f\cdot\boldsymbol{\delta} + \tfrac{1}{2}\boldsymbol{\delta}^\top\mathbf{H}_f\boldsymbol{\delta} | Local quadratic bowl; accounts for the O(\|\boldsymbol{\delta}\|^2) gap of the tangent plane |
| Second-Derivative Test | \mathbf{v}^\top\mathbf{H}\mathbf{v} = \sum_i \lambda_i (\mathbf{q}_i^\top\mathbf{v})^2 at \nabla f(\mathbf{x}_0)=\mathbf{0} | \lambda_i > 0 \Rightarrow strict min; \lambda_i < 0 \Rightarrow strict max; mixed signs \Rightarrow saddle |
| Lagrange Multipliers | \nabla f(\mathbf{x}^\star) = \mu\,\nabla g(\mathbf{x}^\star) on g(\mathbf{x}) = c | Level set of f is tangent to constraint surface (\nabla g(\mathbf{x}^\star) \ne \mathbf{0}) |