Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 52

The Jacobian Matrix

Recommended resources

Hello! In our previous lesson, we established the concept of the gradient for scalar-valued functions (). We saw that the gradient, , is a vector of partial derivatives that points in the direction of steepest ascent and allows us to linearly approximate the function's change via the differential .

This lesson extends that crucial idea to vector-valued functions, those of the form , which take a vector as input and produce a vector as output. This is the standard scenario in deep learning, where each layer of a network can be seen as a vector-valued function. The derivative of such a function is no longer a vector, but a matrix called the Jacobian matrix.

Our goal in this lesson is to understand what the Jacobian represents and, most importantly, how to compute it for a given vector-valued function.


1. What is the Jacobian? The Intuitive View

Just as the derivative of a single-variable function gives the slope of the tangent line, the Jacobian matrix gives us the best linear transformation that approximates a complex, non-linear vector function near a specific point. It tells us how a small change in the input vector is transformed into a change in the output vector.

The best way to build this intuition is to see it visually. The following video from Khan Academy does an excellent job of explaining this concept. It shows how the columns of the Jacobian matrix correspond to where the basis vectors of the input space land after being transformed.

The Jacobian matrix

Watch this video to develop a strong geometric intuition for the Jacobian. It explains how a nonlinear transformation looks linear when you zoom in on a point, and how the Jacobian matrix captures that local linear behavior.

Watch the entire video (about 6 minutes). Pay close attention to how a tiny step in the x-direction and a tiny step in the y-direction in the input space determine the two columns of the Jacobian matrix in the output space.

As the video illustrates, for a function , the Jacobian is a 2x2 matrix that describes the local stretching, rotating, and shearing of the space.

Jacobian Matrix Transformation of the x-y Plane
This image visualizes the effect of a transformation across the x-y plane. The light gray arrows are the original vectors at different points, and the purple arrows are the results of applying the Jacobian matrix at those points. Notice how the transformation's effect (the purple arrows) changes depending on the location, reflecting that the Jacobian itself can be a function of the input variables.

2. The Formal Definition and Computation

Now, let's formalize the structure of the Jacobian matrix. Consider a vector function defined as:

Here, each is a scalar-valued function that gives the -th component of the output vector.

The Jacobian matrix of with respect to , denoted or , is the matrix of all first-order partial derivatives.

In a more compact form, the entry at row and column is .

Connecting to the Gradient

Notice the structure of the Jacobian. The first row contains all the partial derivatives of the first component function, . The second row contains all the partial derivatives of , and so on.

Recall from our previous lesson that we defined the gradient of a scalar function, , as a column vector of its partial derivatives. The rows of the Jacobian matrix are therefore the transposes of the gradients of the component functions:

This definition neatly organizes the derivatives of a vector function into a matrix.

This specific layout, an matrix where rows correspond to output functions, is known as the numerator layout and is common in mathematics and deep learning literature. You might also encounter the denominator layout (the transpose of this matrix), which is more common in physics and some engineering fields. Being aware of both conventions is important. For this course, we will stick to the numerator layout for Jacobians.


3. Step-by-Step Example

Let's compute the Jacobian for a concrete example. This is a purely mechanical process once you understand the definition. You simply need to calculate each partial derivative and place it in the correct spot in the matrix.

The next video from Khan Academy walks through the exact calculation for the function used in the first video.

Computing a Jacobian matrix

This video demonstrates the computational steps to find the Jacobian matrix for a specific function and evaluate it at a point.

Watch the video up to the 2:57 mark. Follow along as each of the four partial derivatives is calculated and placed into the 2x2 Jacobian matrix. Then, see how the numerical Jacobian is found by substituting the coordinates of a specific point.

Let's do one more example ourselves.

Example: Polar to Cartesian Coordinates

Consider the function that converts polar coordinates to Cartesian coordinates . Our input vector is . The function is:

Here, and . The Jacobian is a 2x2 matrix:

Now we compute the four partial derivatives:

Assembling them gives the Jacobian matrix:

Test your understanding!

Find the Jacobian matrix for the function defined by:

Show answer

The function has two component functions: and . The input vector has 3 components and the output has 2, so the Jacobian will be a matrix.

Computing the partials for the first row (from ):

Computing the partials for the second row (from ):

The Jacobian matrix is:

For a concise, text-based summary of these concepts, the following article is an excellent reference.

The Matrix Calculus You Need For Deep Learning

This article provides a clear, formal definition of the Jacobian by framing it as a collection of gradients. It also explicitly discusses the different layout conventions, which is very helpful.

Read the sections 'Matrix calculus' and 'Generalization of the Jacobian'. Notice how it defines the Jacobian by stacking the gradients of the component functions. This reinforces the connection we made earlier.



Conclusion

In this lesson, we have generalized the concept of a derivative from scalar functions to vector functions, leading us to the Jacobian matrix.

Key Takeaways:

  • The Jacobian matrix is the best linear approximation of a vector-valued function at a point.
  • It is an matrix where the entry is the partial derivative of the -th output component with respect to the -th input component, .
  • The rows of the Jacobian are the transposed gradients of the function's scalar components: .
  • Computing the Jacobian is a systematic process of calculating all the necessary partial derivatives and arranging them into a matrix.

Preview of the Next Lesson:

Now that we can find the derivative of a single vector-valued function, the next logical step is to consider compositions of functions, like . This is exactly what a multi-layer neural network is. To find the derivative of such a composite function, we need a version of the chain rule that works for Jacobians. This will be the topic of our next lesson, and it is the key to the backpropagation algorithm in deep learning.