CS计算机代考程序代写 More on Multivariate Gaussians

More on Multivariate Gaussians
Chuong B. Do November 21, 2008
Up to this point in class, you have seen multivariate Gaussians arise in a number of appli- cations, such as the probabilistic interpretation of linear regression, Gaussian discriminant analysis, mixture of Gaussians clustering, and most recently, factor analysis. In these lec- ture notes, we attempt to demystify some of the fancier properties of multivariate Gaussians that were introduced in the recent factor analysis lecture. The goal of these notes is to give you some intuition into where these properties come from, so that you can use them with confidence on your homework (hint hint!) and beyond.
1 Definition
A vector-valued random variable x ∈ Rn is said to have a multivariate normal (or Gaus- sian) distribution with mean μ ∈ Rn and covariance matrix Σ ∈ Sn++1 if its probability density function is given by
p(x;μ,Σ) = 1 exp􏰁−1(x−μ)TΣ−1(x−μ)􏰂. (2π)n/2|Σ|1/2 2
We write this as x ∼ N(μ,Σ).
2 Gaussian facts
Multivariate Gaussians turn out to be extremely handy in practice due to the following facts: • Fact #1: If you know the mean μ and covariance matrix Σ of a Gaussian random
variable x, you can write down the probability density function for x directly.
1Recall from the section notes on linear algebra that Sn++ is the space of symmetric positive definite n×n
matrices, defined as
Sn++ =􏰇A∈Rn×n :A=AT andxTAx>0forallx∈Rn suchthatx̸=0􏰈.
1

• Fact #2: The following Gaussian integrals have closed-form solutions: 􏰞􏰞∞􏰞∞
p(x;μ,Σ)dx = ··· p(x;μ,Σ)dx1 …dxn = 1 x∈Rn −∞ −∞
􏰞x∈Rn n
xip(x; μ, σ2)dx = μi 􏰞x∈R (xi −μi)(xj −μj)p(x;μ,σ2)dx=Σij.
• Fact #3: Gaussians obey a number of closure properties:
– The sum of independent Gaussian random variables is Gaussian. – The marginal of a joint Gaussian distribution is Gaussian.
– The conditional of a joint Gaussian distribution is Gaussian.
At first glance, some of these facts, in particular facts #1 and #2, may seem either intuitively obvious or at least plausible. What is probably not so clear, however, is why these facts are so powerful. In this document, we’ll provide some intuition for how these facts can be used when performing day-to-day manipulations dealing with multivariate Gaussian random variables.
3 Closure properties
In this section, we’ll go through each of the closure properties described earlier, and we’ll either prove the property using facts #1 and #2, or we’ll at least give some type of intuition as to why the property is true.
The following is a quick roadmap of what we’ll cover:
sums marginals conditionals why is it Gaussian? no yes yes resulting density function yes yes yes
3.1 Sum of independent Gaussians is Gaussian
The formal statement of this rule is:
Suppose that y ∼ N(μ,Σ) and z ∼ N(μ′,Σ′) are independent Gaussian dis- tributed random variables, where μ, μ′ ∈ Rn and Σ, Σ′ ∈ Sn++. Then, their sum is also Gaussian:
y + z ∼ N (μ + μ′, Σ + Σ′). Before we prove anything, here are some observations:
2

1. The first thing to point out is that the importance of the independence assumption in the above rule. To see why this matters, suppose that y ∼ N(μ,Σ) for some mean vector μ and covariance matrix Σ, and suppose that z = −y. Clearly, z also has a Gaussian distribution (in fact, z ∼ N (−μ, Σ), but y + z is identically zero!
2. The second thing to point out is a point of confusion for many students: if we add together two Gaussian densities (“bumps” in multidimensional space), wouldn’t we get back some bimodal (i.e., “two-humped” density)? Here, the thing to realize is that the density of the random variable y + z in this rule is NOT found by simply adding the densities of the individual random variables y and z. Rather, the density of y + z will actually turn out to be a convolution of the densities for y and z.2 To show that the convolution of two Gaussian densities gives a Gaussian density, however, is beyond the scope of this class.
Instead, let’s just use the observation that the convolution does give some type of Gaus- sian density, along with Fact #1, to figure out what the density, p(y + z|μ, Σ) would be, if we were to actually compute the convolution. How can we do this? Recall that from Fact #1, a Gaussian distribution is fully specified by its mean vector and covariance matrix. If we can determine what these are, then we’re done.
But this is easy! For the mean, we have
E[yi +zi]=E[yi]+E[zi]=μi +μ′i
from linearity of expectations. Therefore, the mean of y + z is simply μ + μ′. Also, the (i,j)th entry of the covariance matrix is given by
E[(yi + zi)(yj + zj)] − E[yi + zi]E[yj + zj]
= E[yiyj + ziyj + yizj + zizj] − (E[yi] + E[zi])(E[yj] + E[zj])
= E[yiyj] + E[ziyj] + E[yizj] + E[zizj] − E[yi]E[yj] − E[zi]E[yj] − E[yi]E[zj] − E[zi][zj] = (E[yiyj ] − E[yi]E[yj ]) + (E[zizj ] − E[zi]E[zj ])
+ (E[ziyj ] − E[zi]E[yj ]) + (E[yizj ] − E[yi]E[zj ]).
Using the fact that y and z are independent, we have E[ziyj] = E[zi]E[yj] and E[yizj] =
E[yi]E[zj]. Therefore, the last two terms drop out, and we are left with,
E[(yi + zi)(yj + zj)] − E[yi + zi]E[yj + zj]
= (E[yiyj] − E[yi]E[yj]) + (E[zizj] − E[zi]E[zj]) = Σ i j + Σ ′i j .
2For example, if y and z were univariate Gaussians (i.e., y ∼ N(μ,σ2), z ∼ N(μ′,σ′2)), then the convolution of their probability densities is given by
􏰞∞
p(y + z;μ,μ′,σ2,σ′2) = p(w;μ,σ2)p(y + z − w;μ′,σ′2)dw
−∞
􏰞∞1􏰁1 2􏰂1􏰁1 ′2􏰂
= √ exp − 2 (w − μ) · √ ′ exp − ′2 (y + z − w − μ ) dw
−∞ 2πσ 2σ 2πσ 2σ 3

From this, we can conclude that the covariance matrix of y + z is simply Σ + Σ′.
At this point, take a step back and think about what we have just done. Using some simple properties of expectations and independence, we have computed the mean and co- variance matrix of y + z. Because of Fact #1, we can thus write down the density for y + z
immediately, without the need to perform a convolution!3
3.2 Marginal of a joint Gaussian is Gaussian
The formal statement of this rule is: Suppose that
􏰊xA􏰋 ∼ N􏰁􏰊μA􏰋,􏰊ΣAA ΣAB􏰋􏰂, xB μB ΣBAΣBB
where xA ∈ Rm, xB ∈ Rn, and the dimensions of the mean vectors and covariance matrix subblocks are chosen to match xA and xB. Then, the marginal densities,
are Gaussian:
p(xA) = 􏰞 p(xA,xB;μ,Σ)dxB xB ∈Rn
p(xB) = 􏰞 p(xA,xB;μ,Σ)dxA xA ∈Rm
xA ∼N(μA,ΣAA) xB ∼N(μB,ΣBB).
To justify this rule, let’s just focus on the marginal distribution with respect to the variables xA .4
First, note that computing the mean and covariance matrix for a marginal distribution is easy: simply take the corresponding subblocks from the mean and covariance matrix of the joint density. To make sure this is absolutely clear, let’s look at the covariance between xA,i and xA,j (the ith component of xA and the jth component of xA). Note that xA,i and xA,j are also the ith and jth components of
􏰊xA􏰋 xB
3Of course, we needed to know that y + z had a Gaussian distribution in the first place.
4In general, for a random vector x which has a Gaussian distribution, we can always permute entries of x so long as we permute the entries of the mean vector and the rows/columns of the covariance matrix in the corresponding way. As a result, it suffices to look only at xA, and the result for xB follows immediately.
4

(since xA appears at the top of this vector). To find their covariance, we need to simply look at the (i,j)th element of the covariance matrix,
􏰊ΣAA ΣAB 􏰋 . ΣBA ΣBB
The (i,j)th element is found in the ΣAA subblock, and in fact, is precisely ΣAA,ij. Using this argument for all i, j ∈ {1, . . . , m}, we see that the covariance matrix for xA is simply ΣAA. A similar argument can be used to find that the mean of xA is simply μA. Thus, the above argument tells us that if we knew that the marginal distribution over xA is Gaussian, then we could immediately write down a density function for xA in terms of the appropriate submatrices of the mean and covariance matrices for the joint density!
The above argument, though simple, however, is somewhat unsatisfying: how can we actually be sure that xA has a multivariate Gaussian distribution? The argument for this is slightly long-winded, so rather than saving up the punchline, here’s our plan of attack up front:
1. Write the integral form of the marginal density explicitly.
2. Rewrite the integral by partitioning the inverse covariance matrix.
3. Use a “completion-of-squares” argument to evaluate the integral over xB. 4. Argue that the resulting density is Gaussian.
Let’s see each of these steps in action.
3.2.1 The marginal density in integral form
Suppose that we wanted to compute the density function of xA directly. Then, we would need to compute the integral,
p(xA) = 􏰞 p(xA,xB;μ,Σ)dxB xB ∈Rn
3.2.2
=
1 􏰞 exp􏰍−1􏰊xA−μA􏰋T􏰊ΣAA ΣAB􏰋−1􏰊xA−μA􏰋􏰎dx . (2π)m+n 􏰉􏰉ΣAA ΣAB􏰉􏰉1/2 xB∈Rn 2 xB − μB ΣBA ΣBB xB − μB B
2 􏰉􏰉 Σ B A Σ B B 􏰉􏰉
Partitioning the inverse covariance matrix
To make any sort of progress, we’ll need to write the matrix product in the exponent in a slightly different form. In particular, let us define the matrix V ∈ R(m+n)×(m+n) as5
V = 􏰊VAA VAB􏰋 = Σ−1. VBA VBB
5Sometimes, V is called the “precision” matrix.
5

It might be tempting to think that
􏰊VAA VAB􏰋 􏰊ΣAA ΣAB􏰋−1 􏰊Σ−1 Σ−1 􏰋 V= = “=”AAAB
VBA VBB ΣBA ΣBB Σ−1 Σ−1 BA BB
However, the rightmost equality does not hold! We’ll return to this issue in a later step; for now, though, it suffices to define V as above without worrying what actual contents of each submatrix are.
Using this definition of V , the integral expands to
p(xA) = 1 􏰞 exp􏰛−􏰟1(xA − μA)T VAA(xA − μA) + 1(xA − μA)T VAB(xB − μB)
Z xB∈Rn 2 2
+ 21(xB − μB)T VBA(xA − μA) + 21(xB − μB)T VBB(xB − μB)􏰠􏰜dxB,
where Z is some constant not depending on either xA or xB that we’ll choose to ignore for the moment. If you haven’t worked with partitioned matrices before, then the expansion above may seem a little magical to you. It is analogous to the idea that when defining a quadratic form based on some 2 × 2 matrix A, then
xTAx=􏰓􏰓Aijxixj =x1A11x1 +x1A12x2 +x2A21x1 +x2A22x2. ij
Take some time to convince yourself that the matrix generalization above also holds.
3.2.3 Integrating out xB
To evaluate the integral, we’ll somehow want to integrate out xB. In general, however, Gaussian integrals are hard to compute by hand. Is there anything we can do to save time? There are, in fact, a number of Gaussian integrals for which the answer is already known (see Fact #2). The basic idea in this section, then, will be to transform the integral we had in the last section into a form where we can apply one of the results from Fact #2 in order to perform the required integration easily.
The key to this is a mathematical trick known as “completion of squares.” Consider the quadratic function zT Az + bT z + c where A is a symmetric, nonsingular matrix. Then, one can verify directly that
12zT Az + bT z + c = 21􏰙z + A−1b􏰚T A􏰙z + A−1b􏰚 + c − 21bT A−1b.
This is the multivariate generalization of the “completion of squares” argument used in single variable algebra:
12 1􏰁b􏰂2b2 2az +bz+c=2a z+a +c−2a
6

To apply the completion of squares in our situation above, let
z = xB − μB A = VBB
b = VBA(xA − μA)
c = 21(xA − μA)T VAA(xA − μA).
Then, it follows that the integral can be rewritten as
p(xA) = 1 􏰞 exp􏰍−􏰏1􏰙xB − μB + V −1VBA(xA − μA)􏰚T VBB􏰙xB − μB + V −1VBA(xA − μA)􏰚 Z xB∈Rn 2 BB BB
+ 1(xA − μA)T VAA(xA − μA) − 1(xA − μA)T VABV −1VBA(xA − μA)􏰐􏰎dxB 2 2 BB
We can factor out the terms not including xB to obtain, p(xA)=exp􏰁−1(xA −μA)TVAA(xA −μA)+ 1(xA −μA)TVABV−1VBA(xA −μA)􏰂
2 2 BB
· 1 􏰞 exp􏰍−1􏰏􏰙xB − μB + V −1VBA(xA − μA)􏰚T VBB􏰙xB − μB + V −1VBA(xA − μA)􏰚􏰐􏰎dxB
Z xB∈Rn 2 BB BB
At this point, we can now apply Fact #2. In particular, we know that generically speaking, for a multivariate Gaussian distributed random variable x with mean μ and covariance matrix Σ, the density function normalizes, i.e.,
1 􏰞 exp 􏰁−1(x − μ)T Σ−1(x − μ)􏰂 = 1, (2π)n/2|Σ|1/2 Rn 2
􏰞 exp 􏰁−1(x − μ)T Σ−1(x − μ)􏰂 = (2π)n/2|Σ|1/2. Rn 2
We use this fact to get rid of the remaining integral in our expression for p(xA): p(xA)= 1 ·(2π)n/2|VBB|1/2 ·exp􏰁−1(xA −μA)T(VAA −VABV−1VBA)(xA −μA)􏰂.
3.2.4 Arguing that resulting density is Gaussian
At this point, we are almost done! Ignoring the normalization constant in front, we see that the density of xA is the exponential of a quadratic form in xA. We can quickly recognize that our density is none other than a Gaussian with mean vector μA and covariance matrix
(VAA −VABV −1VBA)−1. Although the form of the covariance matrix may seem a bit complex, BB
7
or equivalently,
Z 2 BB

we have already achieved what we set out to show in the first place—namely, that xA has a marginal Gaussian distribution. Using the logic before, we can conclude that this covariance matrix must somehow reduce to ΣAA.
But, in case you are curious, it’s also possible to show that our derivation is consistent with this earlier justification. To do this, we use the following result for partitioned matrices:
􏰊A B􏰋−1 􏰊 M−1 −M−1BD−1 􏰋 C D = −D−1CM−1 D−1 +D−1CM−1BD−1 .
where M = A−BD−1C. This formula can be thought of as the multivariable generalization of the explicit inverse for a 2 × 2 matrix,
􏰊a b􏰋−1 1 􏰊d −b􏰋 cd =ad−bc−ca.
Using the formula, it follows that
􏰊ΣAA ΣAB 􏰋 = 􏰊VAA VAB 􏰋−1 ΣBA ΣBB VBA VBB
􏰊 (VAA − VABV −1VBA)−1 =−1 BB−1 −1
BB
−(VAA − VABV −1VBA)−1VABV −1􏰋 BB−1 −1BB
−VBBVBA(VAA − VABVBBVBA)
We immediately see that (VAA − VABV −1VBA)−1 = ΣAA, just as we expected!
3.3 Conditional of a joint Gaussian is Gaussian
The formal statement of this rule is: Suppose that
􏰊xA􏰋 ∼ N􏰁􏰊μA􏰋,􏰊ΣAA ΣAB􏰋􏰂, xB μB ΣBAΣBB
where xA ∈ Rm, xB ∈ Rn, and the dimensions of the mean vectors and covariance matrix subblocks are chosen to match xA and xB. Then, the conditional densities
p(xA,xB;μ,Σ)
p(xA | xB) = 􏰝xA∈Rm p(xA,xB;μ,Σ)dxA
p(xA,xB;μ,Σ)
p(xB | xA) = 􏰝xB∈Rn p(xA,xB;μ,Σ)dxB
(VBB − VBAVAAVAB)
are also Gaussian:
xA |xB ∼N􏰙μA +ΣABΣ−1 (xB −μB),ΣAA −ΣABΣ−1 ΣBA􏰚
xB |xA ∼N􏰙μB +ΣBAΣ−1(xA −μA),ΣBB −ΣBAΣ−1ΣAB􏰚. AA AA
8
BB BB

As before, we’ll just examine the conditional distribution xB | xA, and the other result will hold by symmetry. Our plan of attack will be as follows:
1. Write the form of the conditional density explicitly.
2. Rewrite the expression by partitioning the inverse covariance matrix. 3. Use a “completion-of-squares” argument.
4. Argue that the resulting density is Gaussian.
Let’s see each of these steps in action.
3.3.1 The conditional density written explicitly
Suppose that we wanted to compute the density function of xB given xA directly. Then, we would need to compute
p(xA,xB;μ,Σ)
p(xB | xA) = 􏰝xB∈Rm p(xA,xB;μ,Σ)dxA
=1exp􏰍−1􏰊xA−μA􏰋T􏰊ΣAA ΣAB􏰋−1􏰊xA−μA􏰋􏰎 Z′ 2 xB−μB ΣBA ΣBB xB−μB
where Z′ is a normalization constant that we used to absorb factors not depending on xB. Note that this time, we don’t even need to compute any integrals – the value of the integral does not depend on xB, and hence the integral can be folded into the normalization constant Z′.
3.3.2 Partitioning the inverse covariance matrix
As before, we reparameterize our density using the matrix V , to obtain p(xB |xA)= 1 exp􏰍−1􏰊xA −μA􏰋T 􏰊VAA VAB􏰋􏰊xA −μA􏰋􏰎
Recall that
Z′ 2 xB−μB VBA VBB xB−μB
= 1 exp􏰛−􏰟1(xA − μA)T VAA(xA − μA) + 1(xA − μA)T VAB(xB − μB)
Z′2 2
+ 21(xB − μB)T VBA(xA − μA) + 21(xB − μB)T VBB(xB − μB)􏰠􏰜.
3.3.3 Use a “completion of squares” argument
21zT Az + bT z + c = 21􏰙z + A−1b􏰚T A􏰙z + A−1b􏰚 + c − 21bT A−1b 9

provided A is a symmetric, nonsingular matrix. As before, to apply the completion of squares in our situation above, let
z = xB − μB A = VBB
b = VBA(xA − μA)
c = 21(xA − μA)T VAA(xA − μA).
Then, it follows that the expression for p(xB | xA) can be rewritten as
p(xB | xA) = 1 exp􏰍−􏰏1􏰙xB − μB + V −1VBA(xA − μA)􏰚T VBB􏰙xB − μB + V −1VBA(xA − μA)􏰚
Z′ 2 BB BB
+ 1(xA − μA)T VAA(xA − μA) − 1(xA − μA)T VABV −1VBA(xA − μA)􏰐􏰎
2 2 BB
Absorbing the portion of the exponent which does not depend on xB into the normalization
constant, we have
p(xB | xA) = 1 exp􏰍−1􏰙xB − μB + V −1VBA(xA − μA)􏰚T VBB􏰙xB − μB + V −1VBA(xA − μA)􏰚􏰎 Z′′ 2 BB BB
3.3.4 Arguing that resulting density is Gaussian
Looking at the last form, p(xB | xA) has the form of a Gaussian density with mean μB − V −1VBA(xA − μA) and covariance matrix V −1. As before, recall our matrix identity,
BB BB
ΣAB􏰋 􏰊 (VAA − VABV −1VBA)−1 =−1 BB−1 −1
−(VAA − VABV −1VBA)−1VABV −1􏰋 BB−1 −1BB.
􏰊ΣAA
ΣBA ΣBB −VBBVBA(VAA − VABVBBVBA)
From this, it follows that
(VBB − VBAVAAVAB) μB|A =μB −V−1VBA(xA −μA)=μB +ΣBAΣ−1(xA −μA).
Conversely, we can also apply our matrix identity to obtain:
VAB􏰋 􏰊 (ΣAA − ΣABΣ−1 ΣBA)−1 =−1 BB−1 −1
−(ΣAA − ΣABΣ−1 ΣBA)−1ΣABΣ−1 􏰋 BB−1 −1BB,
􏰊VAA
VBA VBB −ΣBBΣBA(ΣAA − ΣABΣBBΣBA)
from which it follows that
And, we’re done!
(ΣBB − ΣBAΣAAΣAB) ΣB|A =V−1 =ΣBB −ΣBAΣ−1ΣAB.
10
BB AA
BB AA

4 Summary
In these notes, we used a few simple properties of multivariate Gaussians (plus a couple matrix algebra tricks) in order to argue that multivariate Gaussians satisfy a number of closure properties. In general, multivariate Gaussians are exceedingly useful representations of probability distributions because the closure properties ensure that most of the types of operations we would ever want to perform using a multivariate Gaussian can be done in closed form. Analytically, integrals involving multivariate Gaussians are often nice in practice since we can rely on known Gaussian integrals to avoid having to ever perform the integration ourselves.
5 Exercise
Test your understanding! Let A ∈ Rn×n be a symmetric nonsingular square matrix, b ∈ Rn,
and c. Prove that
􏰞 􏰁1T T 􏰂 (2π)n/2 exp−xAx−xb−cdx= 1/2 T −1 .
x∈Rn 2 |A| exp(c−bA b)
References
For more information on multivariate Gaussians, see
Bishop, Christopher M. Pattern Recognition and Machine Learning. Springer, 2006.
11