Hello! In our last lesson, we explored the many roles of the Gaussian distribution in deep learning, from justifying the mean squared error loss to enabling the reparameterization trick in VAEs and driving the noise process in diffusion models. A recurring theme was the "shift and scale" or affine property: any Gaussian can be generated by applying a linear transformation and a shift to a standard normal variable.
Today, we will formalize this idea. Your objective is to derive the multivariate Gaussian density via an affine transformation of standard normal variables. We will start with the simplest possible building block—a vector of independent, standard normal variables—and use the change of variables formula from calculus to see how its density function transforms under an affine map. This will demystify the somewhat intimidating formula for the multivariate Gaussian PDF, showing you precisely where each component comes from.
Let's begin with a high-level roadmap of this derivation. The image below provides a fantastic, hand-drawn sketch of the entire process, which we will follow step-by-step.

1. The Geometric Intuition: A Constructive Approach
Before we dive into the calculus, let's build a strong geometric intuition for the transformation. If we start with samples from a simple distribution, what sequence of geometric operations would produce the characteristic ellipsoidal shape of a general multivariate Gaussian?
The following video provides an excellent constructive visualization. It demonstrates how to generate samples from an arbitrary 2D Gaussian by starting with independent, standard normal samples (a spherical cloud of points) and then sequentially applying scaling, rotation, and shifting.
Multivariate Gaussian distributions
This video from Alexander Ihler's course provides a clear, step-by-step visualization of how an affine transformation shapes a distribution of points.
Please watch the section on sampling from a Gaussian. Observe how the initial, spherically symmetric data is first scaled, then rotated, and finally shifted. This sequence of operations—scaling, rotation, and translation—is precisely what an affine transformation x = Az + \mu accomplishes. The matrix A handles the scaling and rotation, while the vector \mu handles the shift.
This constructive process shows that any multivariate Gaussian can be seen as a "distorted" version of a standard, spherical Gaussian. Our goal now is to derive the mathematical formula that describes the probability density of this distorted distribution.
2. The Mathematical Derivation
To derive the probability density function (PDF) of the transformed variable , we need three ingredients:
- The PDF of the original standard normal variable .
- The affine transformation relating and .
- The change of variables formula, which tells us how a PDF changes under a transformation.
The following resource walks through this derivation clearly. It methodically introduces each component before putting them together to arrive at the final result.
Derivations of the Univariate and Multivariate Normal Density
This document by Noah Golmant provides a very clear, step-by-step derivation of the multivariate normal PDF. It is more pedagogical than a compact textbook proof.
First, read the section The Basic Case (Section 2.1) to see the simple joint PDF for our starting point: a vector Z of independent, standard normal variables. Next, read about the tool we will use in PDF of a Transformed Random Vector (Section 2.3). This section introduces the change of variables formula and the crucial role of the Jacobian determinant. Finally, read The Multivariate Normal PDF (Section 2.4), which puts all the pieces together. Pay close attention to how the simple PDF of Z is transformed into the general PDF of X.
Let's break down the key steps from that reading, as this is the core of our lesson.
Step 1: The Base Distribution
We start with a -dimensional random vector , where each component is an independent standard normal variable, . Because they are independent, the joint probability density is the product of their individual densities:
This describes a "spherical" probability cloud centered at the origin.
Step 2: The Affine Transformation
We now create a new random variable by applying a general affine transformation to :
where is an invertible matrix and is a -dimensional vector. As we saw in the video, applies rotation and scaling, while applies a shift.
Step 3: Applying the Change of Variables Formula
To find the PDF of , , we use the change of variables formula. First, we express in terms of : . The formula is:
The term is the absolute value of the determinant of the Jacobian matrix of the transformation from to . Since , the Jacobian is simply .
Substituting the components into the formula, we get:
Step 4: Re-parameterizing in terms of the Covariance Matrix
The expression above is correct, but it's parameterized by and . It's more conventional to parameterize it by the mean and covariance of .
The mean of is .
The covariance of is:
Since the components of are independent with unit variance, (the identity matrix). Thus, we arrive at the crucial relationship:
Now we can rewrite the PDF in terms of and :
- The exponent term: .
- The normalization constant: . Since , we have . Therefore, the normalization term is .
Putting it all together, we arrive at the familiar PDF for the multivariate Gaussian distribution:
This derivation confirms that the multivariate Gaussian is not just an arbitrary formula, but the natural result of applying a linear transformation to independent normal variables.
For an alternative, more condensed presentation of the same derivation, you can refer to the bonus slides of the UBC lecture notes.
Advanced Machine Learning - Multivariate Gaussian
This is a bonus section from a different resource that presents the same derivation in a more compact format, which you may appreciate.
Review the two slides titled Multivariate Gaussian from Univariate Gaussians. This condenses the entire derivation we just walked through into a few lines, reinforcing the core logic.
Conclusion
In this lesson, we have demystified the multivariate Gaussian distribution by deriving its probability density function from first principles. We started with the simple, intuitive case of independent standard normal variables and showed how an affine transformation warps their distribution, introducing a mean, and more importantly, a covariance structure.
Key Takeaways:
- The multivariate Gaussian distribution can be generated by applying an affine transformation to a standard normal vector .
- The covariance matrix is directly related to the linear part of the transformation via . It captures the scaling and rotation that distorts the initial spherical distribution into an ellipsoid.
- The change of variables formula from calculus provides the mathematical machinery to derive the PDF of the transformed variable, connecting the Jacobian determinant of the transformation to the normalization constant.
We now have a robust understanding of not just what the multivariate Gaussian is, but why it has the form it does. In the next lesson, we will leverage this structural understanding to compute the marginal and conditional distributions of a multivariate Gaussian. These operations are fundamental building blocks for many generative models, where we often need to reason about parts of a variable vector while holding others fixed or integrating them out.