12. Multivariable Differentiation — From Gradients to Jacobians and Hessians
Calculus 4/5. The moment the input becomes a vector, "one slope" is no longer enough. Because differentiation was defined as the "best linear approximation," the extension is natural: the linear approximation is merely promoted from a number to a vector (gradient), then from a vector to a matrix (Jacobian). Every derivative in deep learning is written in the language of this page.
Partial derivatives
For , differentiate only in the direction while holding the other variables fixed:
A partial derivative is only the slope of a cross-section along a coordinate axis. Unlike the single-variable case, a function may fail to be "differentiable" even when every partial derivative exists—there are functions that appear well-behaved along the axes but are discontinuous in a diagonal direction. The real multivariable definition therefore uses linear approximation.
Total differentiability = existence of a linear approximation
A function is differentiable at if a linear map (matrix) exists such that
This is the Jacobian matrix, whose entries are partial derivatives:
A sufficient condition: if every partial derivative exists and is continuous (), the function is differentiable. Most functions used in practice fall into this category.
Gradient — when the output is scalar
When , the Jacobian is a row vector, and its transpose is called the gradient:
Directional derivative and steepest ascent
The rate of change in the direction of a unit vector (the directional derivative) is
By Cauchy–Schwarz, this is maximized when points in the direction of . Therefore:
- The gradient points in the direction of the function's steepest increase, and its magnitude is the slope in that direction.
- It is always perpendicular to the level set.
- Moving in the direction therefore gives the fastest local decrease—the reason gradient descent () exists.
Multivariable chain rule = product of Jacobians
For and ,
The "product of slopes" from one variable has merely been promoted to a matrix product; the content is identical ("the composition of linear approximations is the product of linear maps"). The gradient of a neural network is exactly this product of layerwise Jacobians. The order of multiplication (left-to-right versus right-to-left) creates the distinction between forward- and reverse-mode automatic differentiation.
Written along scalar paths, it takes the familiar form. If and ,
"Add the contribution from every path"—this is the backpropagation rule that sums every gradient entering a node in a computational graph.
Hessian — second-order information
For , collect the second partial derivatives into a matrix:
- Schwarz's theorem: if the second partial derivatives are continuous, —the Hessian is symmetric.
- Second-order Taylor expansion:
- Classification at a critical point (): if (positive definite), it is a minimum; if , a maximum; and if the eigenvalues have mixed signs, a saddle point. It is known that high-dimensional loss landscapes contain overwhelmingly more saddle points than maxima or minima.
- If the ratio between the Hessian's eigenvalues (condition number) is large, the loss landscape becomes a narrow valley and gradient descent zigzags slowly—the problem that preconditioning, momentum, and Adam try to alleviate.
- Statistical connection: the negative expected Hessian of the log-likelihood is the Fisher information matrix, and it acts as the inverse covariance matrix of the posterior in the Laplace approximation.
Matrix differentiation cheatsheet
These identities recur in ML papers. ( and are constant vectors, is a constant matrix, and denominator layout is used.)
| Note | ||
|---|---|---|
| Linear term | ||
| when is symmetric | ||
| Special case above () | ||
| Least squares | ||
| Gaussian log-likelihood |
Example — normal equations for least squares: solving gives
The closed-form solution to linear regression emerges from one gradient calculation. The MLE of a multivariate Gaussian (estimating mean and covariance) is derived the same way, including the identity.
Summary
- Multivariable differentiation has the same definition as single-variable differentiation: the "best linear approximation." A scalar output gives a gradient; a vector output gives a Jacobian.
- Existence of partial derivatives ≠ differentiability. is safe.
- The gradient points in the direction of steepest ascent (perpendicular to level sets)—the basis of gradient descent.
- The chain rule is a product of Jacobian matrices, and choosing the multiplication order gives forward/reverse-mode automatic differentiation.
- The Hessian is second-order information that determines convexity, saddle points, condition numbers, and Fisher information.
Next: Differentiation, Optimization, and Automatic Differentiation