Search

Search papers and lessons

Jacobian Matrix

Level 2 · 9 min read

The Jacobian matrix collects every partial derivative of a vector-valued function into one grid, and it is the best linear approximation of that function near a point.

On this page

  • Colour = topic mix
  • Calculus
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A function with several inputs and several outputs has a partial derivative for every pair of an output and an input. The Jacobian matrix puts all of them in one grid, with one row per output and one column per input. Near any point, the function behaves like the Jacobian applied to a small change in the input.

Where you'll see it: the backward pass of a neural network, where each layer's Jacobian passes gradients back through the layer, in coordinate changes for integrals, and in the stability analysis of dynamical systems.

Intuition

One output, many inputs, then many outputs

A function of several inputs with a single output has one partial derivative per input. Those numbers form the Gradient, which says how the output moves when each input nudges. Now suppose the function returns several numbers, say a pair of coordinates. Each output has its own gradient, and every output responds to every input. You need a table to keep track of all of it.

That table is the Jacobian. Each row is the gradient of one output. Each column says how one input moves all the outputs together.

Local straight-line behaviour

Zoom in close enough to a smooth curve and it looks like a straight line. The slope of that line is the Derivative. For a function of several variables, zoom in close enough to a point and the function looks like a flat, linear map. The Jacobian is the matrix of that map. It tells you how a tiny change in the input turns into a tiny change in the output, in every direction at once.

This is why the Jacobian shows up whenever a curved map must be studied locally. A globe is curved, but a small map of one city is nearly flat, and the Jacobian is the tool that describes that flat approximation.

flowchart LR
  A[Small change in inputs h] --> B[Multiply by Jacobian J]
  B --> C[Small change in outputs J h]
  C --> D[Output is about F of x plus J h]

The math

Definition

Definition: Jacobian matrix

Let F ⁣:Rn→Rm\mathbf{F}\colon \mathbb{R}^n \to \mathbb{R}^m be a function with component functions F1,…,FmF_1, \dots, F_m, so F(x)=(F1(x),…,Fm(x))\mathbf{F}(\mathbf{x}) = (F_1(\mathbf{x}), \dots, F_m(\mathbf{x})). Its Jacobian at a point x\mathbf{x} is the m×nm \times n matrix

JF(x)=(∂F1∂x1⋯∂F1∂xn⋮⋱⋮∂Fm∂x1⋯∂Fm∂xn).J_{\mathbf{F}}(\mathbf{x}) = \begin{pmatrix} \dfrac{\partial F_1}{\partial x_1} & \cdots & \dfrac{\partial F_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \dfrac{\partial F_m}{\partial x_1} & \cdots & \dfrac{\partial F_m}{\partial x_n} \end{pmatrix}.

The entry in row ii and column jj is ∂Fi/∂xj\partial F_i / \partial x_j.

Here x=(x1,…,xn)\mathbf{x} = (x_1, \dots, x_n) is the input and ∂Fi/∂xj\partial F_i / \partial x_j is the partial derivative of output ii with respect to input jj, computed with every other input held fixed. Row ii is the gradient of FiF_i. Column jj shows how input jj moves every output.

The key result: linear approximation

If F\mathbf{F} is differentiable at x\mathbf{x}, then for a small change h\mathbf{h} in the input,

F(x+h)≈F(x)+JF(x) h.\mathbf{F}(\mathbf{x} + \mathbf{h}) \approx \mathbf{F}(\mathbf{x}) + J_{\mathbf{F}}(\mathbf{x})\,\mathbf{h}.

The error in this approximation shrinks faster than h\mathbf{h} itself, so for small enough steps the linear term carries nearly all of the change. The right-hand side is an affine function of h\mathbf{h}: a fixed offset plus a matrix times the step. The Jacobian is the matrix in that approximation.

The chain rule in matrix form

If G\mathbf{G} is applied after F\mathbf{F}, the Jacobians multiply in the same order:

JG∘F(x)=JG(F(x))  JF(x).J_{\mathbf{G}\circ\mathbf{F}}(\mathbf{x}) = J_{\mathbf{G}}(\mathbf{F}(\mathbf{x}))\; J_{\mathbf{F}}(\mathbf{x}).

This is the chain rule written for vectors. It is the reason the chain rule works in backpropagation: the Jacobian of a whole network is the product of the Jacobians of its layers.

Special cases

  • If m=1m = 1, the Jacobian is a single row, which is the gradient written as a row vector.
  • If n=m=1n = m = 1, the Jacobian is the ordinary derivative, a 1×11 \times 1 matrix.
  • If m=nm = n, the Determinant of the Jacobian measures how much F\mathbf{F} scales volume near x\mathbf{x}. The sign tells you whether it flips orientation.

Worked examples

Example
A small map, step by step

Let F(x,y)=(x2y, 5x+sin⁡y)\mathbf{F}(x, y) = (x^2 y,\ 5x + \sin y). Its Jacobian entries are

  1. ∂F1/∂x=2xy\partial F_1 / \partial x = 2xy and ∂F1/∂y=x2\partial F_1 / \partial y = x^2.
  2. ∂F2/∂x=5\partial F_2 / \partial x = 5 and ∂F2/∂y=cos⁡y\partial F_2 / \partial y = \cos y.
  3. At the point (1,0)(1, 0) the entries are 00, 11, 55 and 11, so J=(0151)J = \begin{pmatrix} 0 & 1 \\ 5 & 1 \end{pmatrix}.
  4. At (1,0)(1, 0), F=(0,5)\mathbf{F} = (0, 5). Take a step h=(0.1,0.1)\mathbf{h} = (0.1, 0.1). The linear prediction is (0,5)+Jh=(0,5)+(0.1, 0.6)=(0.1,5.6)(0, 5) + J\mathbf{h} = (0, 5) + (0.1,\ 0.6) = (0.1, 5.6).
  5. The exact value at (1.1,0.1)(1.1, 0.1) is (1.21⋅0.1, 5.5+sin⁡0.1)=(0.121,5.5998)(1.21 \cdot 0.1,\ 5.5 + \sin 0.1) = (0.121, 5.5998).
  6. The second entry is predicted to within 0.00020.0002 (5.65.6 against 5.59985.5998). The first entry differs by 0.0210.021 (0.10.1 against 0.1210.121), which is the second-order part the approximation ignores. It is the larger error because x2yx^2 y has a sizeable 2x hxhy2x\,h_x h_y-type cross term, while sin⁡y\sin y is nearly linear for small yy.
Example
Polar coordinates and area

Let F(r,θ)=(rcos⁡θ, rsin⁡θ)\mathbf{F}(r, \theta) = (r\cos\theta,\ r\sin\theta), which turns a radius and an angle into ordinary xx and yy coordinates.

  1. The Jacobian is J=(cos⁡θ−rsin⁡θsin⁡θrcos⁡θ)J = \begin{pmatrix} \cos\theta & -r\sin\theta \\ \sin\theta & r\cos\theta \end{pmatrix}.
  2. Its determinant is rcos⁡2θ+rsin⁡2θ=rr\cos^2\theta + r\sin^2\theta = r, since cos⁡2θ+sin⁡2θ=1\cos^2\theta + \sin^2\theta = 1.
  3. Check at r=2r = 2, θ=π/2\theta = \pi/2. Then cos⁡θ=0\cos\theta = 0 and sin⁡θ=1\sin\theta = 1, so J=(0−210)J = \begin{pmatrix} 0 & -2 \\ 1 & 0 \end{pmatrix}. Its determinant is 0⋅0−(−2)(1)=20 \cdot 0 - (-2)(1) = 2, which equals rr.
  4. So a small patch of area dr dθdr\, d\theta in polar coordinates corresponds to a patch of area r dr dθr\, dr\, d\theta in the plane. This factor is why integrals in polar coordinates carry an extra rr.
Example
A realistic one: an elementwise squashing layer

Let F(x1,x2)=(tanh⁡x1, tanh⁡x2)\mathbf{F}(x_1, x_2) = (\tanh x_1,\ \tanh x_2), a common activation applied to each entry separately. Each output depends only on its own input, so the Jacobian is diagonal, with entries 1−tanh⁡2xi1 - \tanh^2 x_i on the diagonal.

  1. At x=(0,1)\mathbf{x} = (0, 1), tanh⁡0=0\tanh 0 = 0 and tanh⁡1=0.7616\tanh 1 = 0.7616.
  2. The diagonal entries are 1−02=11 - 0^2 = 1 and 1−0.76162=1−0.5800=0.42001 - 0.7616^2 = 1 - 0.5800 = 0.4200.
  3. So J=(1000.42)J = \begin{pmatrix} 1 & 0 \\ 0 & 0.42 \end{pmatrix}.
  4. Interpretation: at the first input the layer passes changes through unchanged, while at the second it shrinks them to about 42 percent. This is the vanishing-gradient effect in deep networks, seen in one number.

Tradeoffs and failure modes

The Jacobian is the right tool when you need the local, linear behaviour of a smooth map: sensitivity analysis, change of variables in integrals, stability of equilibria, and gradient-based optimisation of models with vector outputs.

It has limits. It is only a local picture, so it can mislead far from the point where it was computed. It has mnmn entries, which is too many to store for a large network. In practice, systems such as automatic differentiation never build the full matrix. They multiply a vector by it directly, which costs far less.

SituationWhat goes wrongBetter choice
Large network with millions of inputsThe full Jacobian has millions of rows and columns and cannot be storedVector-Jacobian products in reverse-mode differentiation
Predicting far from the expansion pointThe linear approximation drifts away from the true outputRecompute the Jacobian at the new point, or use a nonlinear model
Jacobian is singular, with determinant zeroThe map locally collapses a direction, and it is not invertible thereTreat the point as a critical point and check the model before inverting
Mixing row and column conventionsResults are transposed, and shapes look valid but are wrongFix the convention once, and check shapes against inputs and outputs

History

The determinant of a system of functions, now called a functional determinant, was studied by Carl Gustav Jacob Jacobi in the 1830s and 1840s. He used it to show how multiple integrals change under a change of variables. The name "Jacobian" was attached to these objects later in the nineteenth century, in honour of his work.

The idea caught on because change of variables is everywhere in physics, from mechanics to fluid flow, and because the matrix form made the chain rule for systems simple. In the twentieth century the same matrix became central to numerical optimisation and, later, to the training of neural networks.

Check yourself

QuestionA function F(x,y)=(x+y, xy)\mathbf{F}(x, y) = (x + y,\ xy) maps R2\mathbb{R}^2 to R2\mathbb{R}^2. What is its Jacobian at (2,3)(2, 3)?Show answer

The partial derivatives are ∂F1/∂x=1\partial F_1 / \partial x = 1, ∂F1/∂y=1\partial F_1 / \partial y = 1, ∂F2/∂x=y\partial F_2 / \partial x = y, and ∂F2/∂y=x\partial F_2 / \partial y = x. At (2,3)(2, 3) these are 1,1,3,21, 1, 3, 2. So J=(1132)J = \begin{pmatrix} 1 & 1 \\ 3 & 2 \end{pmatrix}.

QuestionExplain why the first row of a Jacobian is the gradient of the first output.Show answer

Row ii holds ∂Fi/∂xj\partial F_i / \partial x_j for every input jj. Those are exactly the partial derivatives of the single function FiF_i, which are the components of its gradient. Each row therefore gives how one output responds to all inputs.

QuestionA map has Jacobian determinant −3-3 at a point. What does that tell you about the area near that point?Show answer

The map scales area by a factor of ∣−3∣=3|-3| = 3 near the point, so small regions are about three times larger in the image. The negative sign means the map flips orientation there, like a mirror.

QuestionIn a two-layer network, the first layer has Jacobian J1J_1 and the second has J2J_2. Write the Jacobian of the whole network, and say why the order of the product matters.Show answer

The whole network has Jacobian J2J1J_2 J_1, evaluated at the right points: J2J_2 is taken at the output of the first layer. The order matters because matrix multiplication is not commutative, and the layer applied last must come on the left, mirroring the order in which the functions are composed.

Sources