Calculus and gradients

J=∂y∂x\mathbf{J} = \frac{\partial \mathbf{y}}{\partial \mathbf{x}} Jacobian matrix

The Jacobian ∂y/∂x is the matrix of every output’s derivative with respect to every input.

In ML papers

When a function maps a vector x∈Rn\mathbf{x} \in \mathbb{R}^n to a vector y∈Rm\mathbf{y} \in \mathbb{R}^m, its Jacobian ∂y∂x\frac{\partial \mathbf{y}}{\partial \mathbf{x}} is the m×nm \times n matrix with entries Jij=∂yi∂xjJ_{ij} = \frac{\partial y_i}{\partial x_j}. Row ii is the gradient of output ii. For a linear layer y=Wx\mathbf{y} = W\mathbf{x}, the Jacobian is just WW.

Backpropagation is the chain rule for Jacobians: the Jacobian of a composition is the product of the layers' Jacobians, and autograd computes vector-Jacobian products without building the matrices. Normalizing flows need log⁡∣det⁡J∣\log \lvert \det \mathbf{J} \rvert (Determinant) to track how a transformation stretches volume.

How to type it

LaTeXShows
\frac{\partial \mathbf{y}}{\partial \mathbf{x}}∂y∂x\frac{\partial \mathbf{y}}{\partial \mathbf{x}}
\mathbf{J}_fJf\mathbf{J}_f
\nabla_{\mathbf{x}} \mathbf{f} some papers∇xf\nabla_{\mathbf{x}} \mathbf{f}

A worked example

f(x1,x2)=(x1x2, x1+x2)  ⇒  J=(x2x111)\mathbf{f}(x_1, x_2) = (x_1 x_2,\ x_1 + x_2) \;\Rightarrow\; \mathbf{J} = \begin{pmatrix} x_2 & x_1 \\ 1 & 1 \end{pmatrix}

Two outputs, two inputs: a 2×22 \times 2 Jacobian. At (3,5)(3, 5) it is (5311)\begin{pmatrix} 5 & 3 \\ 1 & 1 \end{pmatrix}.

Common confusions

Related

∂L∂w\frac{\partial \mathcal{L}}{\partial w}Partial derivative∇θL\nabla_\theta \mathcal{L}Nabla (gradient)H=∇2f(x)\mathbf{H} = \nabla^2 f(\mathbf{x})Hessian matrixdet⁡(A)\det(A)Determinant

Decode this example →