To generate complex data distributions from simple ones, normalizing flows rely on a specific mathematical rule. When we pass a random variable through a mathematical function, its probability density changes. The change of variables theorem tells us exactly how to calculate that new density. This theorem is the mathematical engine that drives all normalizing flow architectures.
We can build an understanding of this theorem by starting with a single dimension. Imagine a simple one-dimensional continuous random variable . Let us assume follows a standard normal distribution. We want to apply an invertible function to to create a new random variable , resulting in the equation . Because is an invertible mapping, we can also map backward using the inverse function .
What is the probability density of our new variable, denoted as ? A common mistake is to assume that is simply equal to the base density . However, probability is determined by the area under the density curve, and the total area must always integrate to 1. When the function stretches or squishes the number line, the probability density must adjust accordingly to conserve total probability.
The conservation of probability dictates that the probability mass in a small region must equal the probability mass in the corresponding transformed region :
By rearranging this equation, we get the change of variables formula for a single dimension:
The term is the derivative of the inverse function with respect to . We take the absolute value because probability densities must be strictly non-negative. Without the absolute value, a function with a negative slope would compute a mathematically impossible negative probability density.
Flow of a random variable through an invertible transformation showing forward and inverse mappings.
In machine learning, we rarely work with one-dimensional data. We deal with high-dimensional vectors representing images, audio, or text. If and are vectors in an -dimensional space , the simple scalar derivative is no longer sufficient. We must evaluate how every dimension of changes with respect to every dimension of . This multidimensional relationship is captured by a matrix of partial derivatives called the Jacobian matrix.
The change of variables theorem for multivariate distributions replaces the scalar derivative with the determinant of the Jacobian matrix:
We can also write this equation explicitly using the inverse function :
We can break down the components of this formula to understand how density estimation works in practice.
For this theorem to hold true, the function must be a bijection. A bijection is a mathematical function that is both one-to-one and onto. This strict requirement guarantees two specific properties. First, every vector maps to exactly one vector , and every maps back to exactly one . Second, the input and output dimensions are identical, which ensures the Jacobian is a square matrix. Determinants can only be computed for square matrices. If the function is not a bijection, probability mass could overlap or disappear.
Sometimes it is more convenient to define the change of variables using the forward transformation rather than the inverse. By applying the properties of inverse matrices, we know that the determinant of the inverse Jacobian is equal to the inverse of the determinant of the forward Jacobian. This gives us an alternative representation:
When training neural networks, multiplying many small probabilities together leads to numerical underflow. To maintain numerical stability, normalizing flows compute the log-likelihood of the data instead of the raw probability density. Taking the natural logarithm of both sides transforms the product into a sum:
This logarithmic form is the exact objective function you will optimize when training flow models in PyTorch. The first term evaluates how well the model maps data to high-probability regions of the simple base distribution. The second term, the log determinant, acts as a penalty that prevents the volume of the space from collapsing to zero during training.
Was this section helpful?
© 2026 ApX Machine LearningAI Ethics & Transparency•