The Gaussian Cheatsheet
Apr 22, 2020
Last updated: Sep 13, 2021
This is a collection of key derivations involving Gaussian distributions
which commonly arise almost everywhere in Machine Learning.
A Gaussian distribution with mean and variance is given by
To derive the normalizing constant for this density, consider the following integral
First using change of variables and , we have
Transforming to polar coordinates and
using the standard change of variables, we require the Jacobian determinant
Solving this final integral requires another change of variable. Let ,
This implies and hence the complete distribution is now written as
The Gaussian Integral by Keith Conrad shows at least ten other ways to prove this integral!
As a Maximum Entropy Distribution
Interestingly, the Gaussian distribution also turns out to be the maximum entropy
distribution on the infinite support for a finite second moment .
The differential entropy is defined as the expected information
of a random variable .
To find the maximum entropy distribution, we formally write the constrained optimization
problem stated before
The constraints correspond to the normalization of probability distributions,
finite mean (first moment) and finite variance (finite second moment). This
can be converted into an unconstrained optimization problem using Lagrange multipliers .
The complete objective becomes
Setting the functional derivative (see Appendix D in Bishop ) , we get
To recover the precise values of the Lagrange multipliers, we substitute them back
into the constraints. The derivation is involved but straightforward. We first manipulate the exponent by
completing the squares by noting that for any general quadratic , which will allow us to re-use results from the previous section. We also further always make use of the subsitution .
Putting back these new definitions the normalization constraint is,
Using another change of variable , we reduce this integral to a familiar form and can evaluate using the polar coordinate transformation trick as earlier.
Similarly, we put this into the finite first moment constraint and re-apply
the substitution . The first term is an integral
of an odd function over the full domain and is nullified.
Combining (1) with (2), we get . Substituting and
as defined earlier, we get
With similar approaches and substitutions, we substitute values in the integral for finite
second moment constraint.
Focusing on the remaining term, we first apply the change of variable and note
that this is an even function. This allows us to use the next change of variables.
To allow a change of variable further, we first note that this is an even function and symmetric around .
Using this knowledge, we can change the limits of integration to positive values and use
where we utilize the fact that , where is the Gamma function, and . Plugging
everything back and using , we get
Using this, we get
Substituting back in (1), we have
Substituting back into gives us the form for . For maximum entropy distributions under other constraints, see examples on this Wikipedia entry
Conditional Gaussian distributions are common in machine learning - common
examples being Gaussian Processes and Gaussian Linear dynamical systems. Here
we discuss the algebraic manipulations on a joint Gaussian distribution. Consider
a joint distribution on two random variables p(x, y) where both x,y may be vectors.
We are interested in ( and are exchangeable throughout). Noting
by the chain rule of probabilities that we focus on quadratic
part of the exponent.
The Schur complement
We take a digression and discuss the Schur complement .
Consider a matrix decomposed into blocks
We want to (block) diagonalize this so that inversion is easy.
The inverse is now easy to compute by using the property that the inverse of a
block diagonal matrix is the inverse of each of the diagonal blocks. We also define
is called the Schur complement of with respect to .
Getting back to our original equation, we can now utilize this result.
Let's start by resolving the first and last two terms. Remember
that we are working with block vectors and matrices. Transpose operators must be
preserved and block matrix algebra works like the usual matrix multiplications.
We are already seeing a pattern. This can be finalize into two separate terms because
the central matrix is already block diagonalized.
We recover the familiar pattern of quadratic terms in the Gaussian exponent. The
exponent can now be written as the product of two exponents such that
Linear Dynamical Systems
The classic results on a linear dynamical system defined by
can be derived pretty easily now by reverse engineering the above equations. For
instance, the full joint of this linear dynamical system is given by
Computing the joint, marginals and other conditionals now should be a matter of
plugging in the right values.