Welcome back to our journey through the mathematics of deep learning. In our last lesson, we leveraged the concept of orthogonality to build projection matrices, which gave us a geometric understanding of least-squares solutions and data preprocessing techniques like whitening. We've been assembling a toolkit for interpreting linear transformations geometrically.
Today, we will add two more powerful—and perhaps surprisingly related—tools to this kit: the determinant and the trace. You've likely encountered these as computational recipes, but our goal is to understand them as fundamental measures of how a linear map transforms space. We will connect the determinant to the change in volume, and the trace to the infinitesimal change in volume. This isn't just a theoretical curiosity; this exact concept is the mathematical engine behind normalizing flows—a class of models you plan to implement—and their extension into continuous-time models like Neural ODEs.
The Determinant: A Measure of Volume Change
Before we dive into its applications, let's refresh our geometric intuition for the determinant. A linear transformation can stretch, compress, shear, and rotate space. The determinant is a single scalar that tells us the net effect of this transformation on volume (or area in 2D). Specifically, it's the factor by which the volume of any region is scaled.
The 3Blue1Brown video series, "Essence of linear algebra," offers an unparalleled visual explanation of this concept.
The determinant | Chapter 6, Essence of linear algebra
This video provides the essential geometric intuition for the determinant.
Please watch the following segments to solidify the core ideas: The Scaling Factor: This part introduces the determinant as the factor by which the area of the unit square is scaled, and explains why this scaling factor applies to any area. Determinant of Zero: This explains the crucial case where the determinant is zero, corresponding to the transformation collapsing space into a lower dimension. Negative Determinants: Here, the concept of orientation is introduced to explain negative determinant values. Extension to 3D: This part confirms that the same intuition extends to three dimensions, where the determinant measures the scaling of volume.
The key takeaways from the video are:
- The absolute value of the determinant of a matrix , , is the factor by which the transformation scales volume.
- If , the transformation collapses space into a lower dimension (e.g., a plane into a line). This is equivalent to the columns of being linearly dependent.
- The sign of indicates whether the transformation preserves or inverts the orientation of space.
Application: The Change of Variables in Normalizing Flows
This concept of volume change becomes critically important when we work with probability densities. Normalizing flows, a powerful class of generative models, are built directly on this idea. The goal of a flow is to learn a complex distribution by transforming samples from a simple base distribution (e.g., a standard Gaussian) through an invertible function .
Let , where . We want to find the probability density of , . A naive guess might be that , but this ignores how distorts the space.

If a small region around with volume is mapped to a region around with a larger volume , the probability density at must be lower to conserve the total probability (). The factor by which the volume changes locally is given by the determinant of the transformation's Jacobian matrix. This leads to the change of variables formula:
where is the Jacobian of the inverse transformation evaluated at . Using the property that , we can write this in terms of the forward transformation :
where . This is often expressed in terms of log-probabilities, as it's more numerically stable and turns products into sums. The log-likelihood of observing a data point is:
Training a normalizing flow like RealNVP, one of the papers on your implementation list, involves maximizing this log-likelihood over a dataset. The core computational challenge is calculating the log-determinant of the Jacobian.
The following video provides an excellent walkthrough of these ideas.
This video by Ari Seff connects the change of variables formula, the Jacobian determinant, and the architecture of normalizing flows.
Please focus on these segments: Change of Variables: This section derives the formula and uses a 2D example to show why the determinant term is necessary to account for the local expansion/contraction of space. Maximum Likelihood Objective: This part shows how the change of variables formula leads to the log-likelihood objective used to train flows, highlighting the log-determinant term. The Triangular Trick: This explains a key architectural constraint (used in RealNVP) that makes the Jacobian matrix triangular, reducing the \mathcal{O}(D^3) cost of computing the determinant to \mathcal{O}(D).
From Volume to Infinitesimal Change: The Trace
The determinant calculation is a major bottleneck in normalizing flows, leading to architectural constraints. What if we could reframe the problem to avoid it? This is the motivation behind continuous-time models like Neural Ordinary Differential Equations (Neural ODEs) and Continuous Normalizing Flows (CNFs).
Consider a discrete transformation like in a residual network:
If we consider as a continuous variable and take infinitesimal steps, this becomes an ordinary differential equation:
Here, the final state is the result of integrating these dynamics over time, .
Now, let's see what happens to our change of variables formula. In the discrete case, a composition of flows leads to a sum of log-determinants. In the continuous limit, this sum becomes an integral. It can be shown that the change in log-density over time is governed by the trace of the Jacobian of the dynamics function :
This is a profound result. The computationally expensive determinant of the transformation in the discrete setting becomes the trace of the dynamics' Jacobian in the continuous setting. Since computing the trace is an operation, this allows for much more flexible and scalable models.
This result comes from Jacobi's formula for the derivative of a determinant. For a matrix that is close to the identity, , we have . The trace, the sum of the diagonal elements of , governs the infinitesimal change in volume away from the identity transformation. The derivation in the context of Neural ODEs formalizes this intuition.
The following reading walks through this specific derivation. Given your background, you should find the argument straightforward and illuminating.
[PDF] 6 - Neural Ordinary Differential Equations - Depth First Learning
These notes from the "Depth First Learning" course provide a concise derivation of the trace formula for continuous normalizing flows.
Please read the section "Distribution Transformation by ODE" (Section 3 in the document). Focus on the derivation that starts with the discrete change of variables formula and arrives at the continuous dynamics for the log-probability. The key step, labeled "where we used Jacobi formula," is the transition from log det to tr. Pay close attention to how the limit s -> 0 transforms the problem.
This transition from determinant to trace is not just a mathematical convenience; it's a fundamental shift in perspective. It tells us that the trace of a matrix is the instantaneous rate of change of the volume element under the flow defined by that matrix.
Conclusion
In this lesson, we have imbued the determinant and trace with deep geometric meaning, connecting them directly to the engines of modern generative models.
Key Takeaways:
- The determinant of a transformation matrix measures the factor by which it scales volume.
- In Normalizing Flows, the determinant of the Jacobian is essential in the change ofvariables formula to ensure probability conservation. The log-determinant term is a core part of the training objective.
- The trace of a matrix can be interpreted as the infinitesimal change in log-volume.
- In Continuous-Time Models (like Neural ODEs), the computationally expensive log-determinant term simplifies to the integral of the trace of the dynamics' Jacobian, enabling more flexible model architectures.
We have now examined two key scalar properties of matrices. In our next lesson, we will explore another way to summarize a matrix's properties into a single number: matrix norms. We will see how norms allow us to measure the "size" or "magnitude" of a transformation, which is critical for analyzing the stability of deep neural networks and understanding the behavior of optimization algorithms.