Skip to content
BIASED

The multivariate Gaussian

Block 1 of 7~3 min

Random vectors and the covariance matrix

The topic Joint distributions and independence gave us the words for several variables at once: a joint density, marginals, conditional distributions, and covariance as a measure of how two variables move together. It also showed the price. A joint distribution of dd variables is a function of dd arguments, and nothing forces it to be simple. This topic studies the one family that machine learning reaches for first, because a vector of means and a table of covariances describe it completely.

Stack the variables into a random vector X=(X1,…,Xd)⊤X = (X_1, \dots, X_d)^\top, for example dd features of one object in a dataset. Its mean vector collects the means, μi=E[Xi]\mu_i = \mathbb E[X_i]. Its covariance matrix collects all the covariances:

Σij=Cov⁡(Xi,Xj),Σ=E[(X−μ)(X−μ)⊤].\Sigma_{ij} = \operatorname{Cov}(X_i, X_j), \qquad \Sigma = \mathbb E\big[(X - \mu)(X - \mu)^\top\big].

A one-line reminder on matrices: v⊤v^\top turns a column into a row, and a column times a row, vw⊤vw^\top, is a table with entries viwjv_i w_j. So the second formula is just the first one written for all pairs (i,j)(i, j) at once. The diagonal holds the variances, since Cov⁡(Xi,Xi)=Var⁡(Xi)\operatorname{Cov}(X_i, X_i) = \operatorname{Var}(X_i).

The running example of this topic has two features measured from their averages, so μ=0\mu = 0, and

Σ=(21.21.21).\Sigma = \begin{pmatrix} 2 & 1.2 \\ 1.2 & 1 \end{pmatrix}.

Feature 1 varies more (Var⁡(X1)=2\operatorname{Var}(X_1) = 2), feature 2 less (Var⁡(X2)=1\operatorname{Var}(X_2) = 1), and the positive covariance 1.21.2 says they tend to rise together.

Not every table of numbers can be a covariance matrix. It is symmetric, because Cov⁡(Xi,Xj)=Cov⁡(Xj,Xi)\operatorname{Cov}(X_i, X_j) = \operatorname{Cov}(X_j, X_i). And for any fixed weights aa, the number a⊤X=a1X1+⋯+adXda^\top X = a_1 X_1 + \dots + a_d X_d has variance

Var⁡(a⊤X)=∑i,jaiajΣij=a⊤Σa,\operatorname{Var}(a^\top X) = \sum_{i, j} a_i a_j \Sigma_{ij} = a^\top \Sigma a,

which is the rule Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)+2Cov⁡(X,Y)\operatorname{Var}(X + Y) = \operatorname{Var}(X) + \operatorname{Var}(Y) + 2\operatorname{Cov}(X, Y) from the previous topic, extended to dd weighted terms. A variance is never negative, so a⊤Σa≥0a^\top \Sigma a \ge 0 for every aa: the matrix is positive semidefinite. For a symmetric 2×22 \times 2 matrix this comes down to a nonnegative diagonal and a nonnegative determinant Σ11Σ22−Σ122\Sigma_{11}\Sigma_{22} - \Sigma_{12}^2, which is the familiar ∣ρ∣≤1\lvert\rho\rvert \le 1 once more. The course Mathematics for ML covers such matrices in the topic Symmetric matrices and quadratic forms.

Answers are saved on the server and tied to this browser until you sign in.