The Shape of a Random Vector

Covariance is a geometry

A face is a random vector

Four thousand numbers that move together

Top: ten of 400 portraits. Middle: one of them read row by row into a vector of 4096 numbers. Bottom: the mean face, the per-pixel spread, and the covariance of the pixels along one row through the eyes.

Neighboring pixels are not independent: a face is a shape, and the pixels move together. This week is about describing that shape, and about choosing the coordinates in which it is simplest.

The plan for the week

The geometry we borrow. Inner products, angles, right angles and projections, for ordinary vectors.

Covariance is that geometry. Two random variables have an angle between them; many have a covariance matrix, which is an ellipsoid.

Choosing the coordinates. Linear maps reshape the ellipsoid; the eigenvectors make it a sphere (whitening) or keep only what matters (the KLT). For a Gaussian vector, that is the whole story.

In the notes Vectors, Inner Products, and Orthogonality · Covariance and Correlation · Sums of Dependent Random Variables · Mean Vector and Covariance Matrix · Proper Complex Random Vectors · Linear Transforms of Random Vectors · Decorrelation, Whitening, and Coloring · Normal Random Vectors

The geometry we borrow

Inner product, length, distance

Euclidean inner product \[\ip{\mathbf x,\mathbf y}=\mathbf y\herm\mathbf x=\sum_{k=1}^Nx_k\,y_k\conj,\qquad \norm{\mathbf x}^2=\ip{\mathbf x,\mathbf x}=\sum_k\abs{x_k}^2 .\]

Complex from the start, because signals demand it. The conjugate is what makes \(\norm{\mathbf x}^2\ge0\), zero only at \(\mathbf 0\): for a signal, it is the energy. Distance is \(\norm{\mathbf x-\mathbf y}\), so “closest” always means the smallest norm of a difference.

Angle, and Cauchy–Schwarz

\[\abs{\ip{\mathbf x,\mathbf y}}\le\norm{\mathbf x}\,\norm{\mathbf y},\qquad \cos\theta=\frac{\abs{\ip{\mathbf x,\mathbf y}}}{\norm{\mathbf x}\norm{\mathbf y}}\in[0,1] .\]

Length, alignment, and the right angle.

\(\mathbf x\perp\mathbf y\) when \(\ip{\mathbf x,\mathbf y}=0\). That extreme case is the one this course lives on: orthogonality is the algebraic form of “carrying no information about each other”.

Pythagoras and the projection

\(\mathbf x\perp\mathbf y\ \Rightarrow\ \norm{\mathbf x+\mathbf y}^2=\norm{\mathbf x}^2+\norm{\mathbf y}^2\). The closest point of a subspace \(\mathcal S\) to \(\mathbf y\) is characterized by a right angle:

Projection theorem \[\norm{\mathbf y-\widehat{\mathbf y}}=\min_{\mathbf s\in\mathcal S}\norm{\mathbf y-\mathbf s} \iff(\mathbf y-\widehat{\mathbf y})\perp\mathcal S .\]

Pythagoras and the projection

The projection onto the plane spanned by \(\mathbf x_1,\mathbf x_2\); the error stands perpendicular to the whole plane.

Nothing here used that a vector is a list of numbers, only that there is an inner product. Any space carrying one inherits all of it.

Coordinates in a basis

Left: an orthonormal pair, where the coefficients are the perpendicular shadows. Middle: an oblique pair, where the true coefficients differ from the shadows. Right: the Gram matrix that corrects them.

In an orthonormal basis each coefficient is one inner product. In an oblique basis the coefficients come from a linear system whose matrix, the Gram matrix, holds all the pairwise inner products of the basis.

Functions are vectors too

The first harmonics of the Fourier basis on an interval, partial sums of a square wave, and their Gram matrix: the identity.

With \(\ip{f,g}=\int f\,g\conj\), a function is a vector with a continuum of coordinates. The Fourier basis is orthonormal, so adding a harmonic never changes the earlier coefficients.

Same subspace, two bases

Monomials and Legendre polynomials span the same subspace; the best approximation is the same in both. Only the Gram matrix differs: dense for the monomials, identity for Legendre.

The projection depends only on the subspace; the basis only changes how hard it is to compute. Keep that distinction: this week is about choosing good bases.

Two variables: covariance

A population as three vectors

Height, weight and income of 240 people, each read as a centered list with one coordinate per person. Right: the cosines between the three lists.

A zero-mean random variable is such a list, with one coordinate per outcome, weighted by its probability. Weight follows height; income does not. That is an angle.

Only the angles enter

Weight \(\mathbf y\) from height \(\mathbf x_1\) and income \(\mathbf x_2\): three vectors of 240 coordinates each, redrawn from their pairwise angles alone. The Gram matrix is the whole input of the solve.

\(\mathbf R_{\mathbf{xx}}\) and \(\mathbf r_{\mathbf{xy}}\) are inner products, not coordinates: the projection depends on the pairwise angles, whatever the dimension of the vectors.

Covariance is variance for a pair

Covariance and correlation coefficient \[C_{XY}=\E{(X-m_X)(Y-m_Y)\conj},\qquad \rho_{XY}=\frac{C_{XY}}{\sigma_X\sigma_Y},\qquad R_{XY}=\E{XY\conj}.\]

Covariance is variance for a pair

The joint density, the weight \((x-m_X)(y-m_Y)\) with the sign of each quadrant, and their product, whose signed volume is \(C_{XY}\).

The correlation coefficient is a cosine

Cauchy–Schwarz applied to the centered variables, with \(\ip{U,V}=\E{UV\conj}\): \[\abs{C_{XY}}\le\sigma_X\sigma_Y\quad\Longrightarrow\quad\abs{\rho_{XY}}\le1,\] with equality exactly when \(Y\) is an affine function of \(X\).

Top: jointly Gaussian pairs for several \(\rho\). Bottom: four laws, all with \(\rho=0\), only the first of them independent.

Uncorrelated is not independent

\(Y=X^2\) with a symmetric \(X\): \(Y\) is a function of \(X\), and yet \(C_{XY}=0\). Shift \(X\) and the same parabola gives \(\rho=0.97\).

Covariance sees only the straight-line part of the dependence. Zero covariance means “no linear relationship”, not “no relationship”.

Orthogonal is not uncorrelated

\(X,Y\) are uncorrelated when \(C_{XY}=0\), orthogonal when \(R_{XY}=\E{XY\conj}=0\). They differ by the means: \(C_{XY}=R_{XY}-m_Xm_Y\conj\).

One pair with \(\rho=-0.75\), placed so that \(\E{XY}=0\): quadrants about the origin cancel (left), quadrants about the mean do not (right).

independent \(\Rightarrow\) uncorrelated \(\overset{\text{zero mean}}{\iff}\) orthogonal, and no arrow reverses in general. This is why the course mostly works with zero-mean variables.

The dictionary

geometry random variables (zero mean)
inner product \(\ip{\mathbf x,\mathbf y}\) covariance \(\E{XY\conj}\)
squared length variance
\(\cos\theta\) correlation coefficient \(\rho_{XY}\)
orthogonal uncorrelated
Pythagoras variances of uncorrelated terms add
projection onto a subspace the best guess buildable from those variables

Nothing on the left knew about randomness, and nothing on the right will need a new proof.

How many measurements do you really have?

The variance of a sum keeps its cross terms: \[\Var{\overline X_N}=\frac{1}{N^2}\sum_{k,l}C_{X_kX_l} =\frac{\sigma^2}{N_{\text{eff}}},\qquad N_{\text{eff}}=\frac{N}{1+(N-1)\rho}\] for a common correlation \(\rho\) between any two readings.

A slowly wandering thermometer: 8 readings, 64 readings, and the variance of their average.

Correlated readings repeat each other. With \(\rho=0.5\), a million readings are worth two. The \(1/\sqrt N\) of independent averaging was a property of independence, not of averaging.

Many variables: the covariance matrix

Moments become a vector and a matrix

Mean vector and covariance matrix \[\mathbf m_{\mathbf X}=\E{\mathbf X},\qquad \mathbf C_{\mathbf{XX}}=\E{(\mathbf X-\mathbf m_{\mathbf X})(\mathbf X-\mathbf m_{\mathbf X})\herm},\qquad \mathbf R_{\mathbf{XX}}=\E{\mathbf X\mathbf X\herm}.\]

The diagonal holds the variances, the off-diagonal entries the pairwise covariances. Two properties: Hermitian, \(\mathbf C_{\mathbf{XX}}\herm=\mathbf C_{\mathbf{XX}}\), and positive semidefinite, \[\mathbf a\herm\mathbf C_{\mathbf{XX}}\mathbf a=\Var{\mathbf a\herm\mathbf X}\ge0\qquad\text{for every }\mathbf a .\]

Not a technicality: positive semidefiniteness licenses every square root, inverse and eigen- decomposition used from here to the end of the course.

The covariance matrix is a shape

Figure 1: Samples and 1σ, 2σ ellipses for three covariances; red arrows are the eigenvectors scaled by the square root of their eigenvalue.

Uncorrelated components: the ellipse is axis-aligned. Correlation tilts it. Decorrelating the data means diagonalizing \(\mathbf C_{\mathbf{XX}}\), an eigenproblem and nothing more.

The variance in every direction

Figure 2: Variance of aᴴX as the unit direction a sweeps half a circle, against the two eigenvalues.

Every direction has its own marginal

A linear combination \(\mathbf a\herm\mathbf X\) is a directional marginal: the joint law squashed onto direction \(\mathbf a\).

The extremes are the eigenvalues, reached along the eigenvectors; every other direction is trapped between them.

Distance in the data’s own units

Mahalanobis distance \[d_M(\mathbf x)=\sqrt{(\mathbf x-\mathbf m_{\mathbf X})\herm\,\mathbf C_{\mathbf{XX}}^{-1}\,(\mathbf x-\mathbf m_{\mathbf X})}.\] Its level sets are the covariance ellipsoids. For \(N=1\) it is the \(z\)-score.

Distance in the data’s own units

The marked point lies within one standard deviation in each coordinate, inside the dashed box, yet at \(d_M\approx2.8\).

An outlier cannot be judged coordinate by coordinate: this point is unusual because it disobeys the correlation the rest of the data obey.

The covariance matrix from data

\[\widehat{\mathbf m}_{\mathbf X}=\frac1M\sum_m\mathbf x^{(m)},\qquad \widehat{\mathbf C}_{\mathbf{XX}}=\frac{1}{M-1}\sum_m(\mathbf x^{(m)}-\widehat{\mathbf m}_{\mathbf X})(\mathbf x^{(m)}-\widehat{\mathbf m}_{\mathbf X})\herm:\] a sum of rank-one outer products, positive semidefinite by construction.

Figure 3: 200 students, three measurements each: the covariance matrix (dominated by whichever variable has the largest units) and the correlation matrix (unit-free).

The largest covariance tells you which variable has the biggest units, not which relationship is strongest. Normalizing to correlations makes the matrix readable.

Complex random variables: the conjugate matters

\(Z=X+jY=Re^{j\Phi}\) is a pair of real variables on one outcome, and its size is measured with a conjugate: \(\E{ZZ\conj}=\E{\abs Z^2}\ge0\).

Figure 4: A unit-amplitude signal with uniformly random phase: averaging Z or Z² gives zero, averaging ZZ* gives one.

Without the conjugate, the second moment of a phase-rotating signal vanishes however large the signal is. With it, \(\mathbf C_{\mathbf{ZZ}}=\E{(\mathbf Z-\mathbf m)(\mathbf Z-\mathbf m)\herm}\) is Hermitian and positive semidefinite, exactly as in the real case.

Proper: one matrix is enough

\(\mathbf Z=\mathbf X+j\mathbf Y\) has \(2N\) real degrees of freedom; the missing half is the complementary covariance \(\widetilde{\mathbf C}_{\mathbf{ZZ}}=\E{(\mathbf Z-\mathbf m)(\mathbf Z-\mathbf m)\tran}\). A vector is proper when it vanishes.

Figure 5: Proper (left) and improper (right) complex variables with the same Hermitian variance.

Properness is rotational symmetry: no phase is privileged. A uniformly random carrier phase produces it, which makes it the standard model for communication and array signals.

Where proper signals come from

A narrowband tone across an array of microphones: one frequency, phases marching by a constant step, and an absolute phase the geometry does not fix.

The snapshot is \(\mathbf Z=Ae^{j\Theta}\mathbf v+\mathbf N\) with \(\Theta\) uniform. Its covariance \(\abs A^2\mathbf v\mathbf v\herm+\sigma_N^2\mathbf I\) is one strong direction lifted above an isotropic noise floor.

The unknown absolute phase is what makes the snapshot proper, and the rank-one term is where the direction of the source is written.

Linear maps

The most used fact at this level

Moments under a linear map For \(\mathbf Y=\mathbf A\mathbf X+\mathbf b\): \[\mathbf m_{\mathbf Y}=\mathbf A\mathbf m_{\mathbf X}+\mathbf b,\qquad \mathbf C_{\mathbf{YY}}=\mathbf A\,\mathbf C_{\mathbf{XX}}\,\mathbf A\herm .\]

One line of proof: linearity of expectation. The offset moves the mean and cannot touch the covariance. For one row, \(\Var{\mathbf a\herm\mathbf X}=\mathbf a\herm\mathbf C_{\mathbf{XX}}\mathbf a\) again.

Every filter, beamformer and transform is an \(\mathbf A\), and this is what it does to the second-order description, whatever the distribution.

Three elementary maps

Scaling, rotation and shear, each applied to a colored grid and to a law.

Scaling changes variances and leaves the correlation coefficient alone. A rotation keeps every length and eigenvalue and changes only which direction is which. A shear creates correlation.

Choosing \(\mathbf A\) is the whole game

In \(\mathbf C_{\mathbf{YY}}=\mathbf A\mathbf C_{\mathbf{XX}}\mathbf A\herm\), choose \(\mathbf A\) to make

  • \(\mathbf C_{\mathbf{YY}}\) diagonal: the outputs are uncorrelated (decorrelation);
  • \(\mathbf C_{\mathbf{YY}}=\mathbf I\): uncorrelated and of unit scale (whitening);
  • \(\mathbf C_{\mathbf{YY}}\) equal to a target: a signal with prescribed statistics (coloring).

The law of the slide before, rotated through a full turn. Four times per turn the off-diagonal of \(\mathbf C_{\mathbf{YY}}\) passes through zero: there \(\mathbf A=\mathbf U\herm\), and the outputs are uncorrelated.

The full density: one Jacobian

When the whole density is wanted, a bijection \(\mathbf Y=\mathbf g(\mathbf X)\) rescales it by the local volume change:

Change of variables \[f_{\mathbf Y}(\mathbf y)=\frac{f_{\mathbf X}(\mathbf x)}{\abs{\det\mathbf J(\mathbf x)}}\Big|_{\mathbf x=\mathbf g^{-1}(\mathbf y)} .\]

For a linear map the Jacobian is the constant \(\mathbf A\): \(f_{\mathbf Y}(\mathbf y)=f_{\mathbf X}\paren{\mathbf A^{-1}(\mathbf y-\mathbf b)}/\abs{\det\mathbf A}\).

Choosing the coordinates

The natural axes: eigenvectors

\[\mathbf C_{\mathbf{XX}}=\mathbf U\boldsymbol\Lambda\mathbf U\herm,\qquad \mathbf U\herm\mathbf U=\mathbf I,\quad \lambda_i\ge0 .\]

Hermitian gives the orthonormal \(\mathbf U\); positive semidefinite gives \(\lambda_i\ge0\). Transform by \(\mathbf U\herm\): \(\mathbf C_{\mathbf{WW}}=\mathbf U\herm\mathbf C_{\mathbf{XX}}\mathbf U=\boldsymbol\Lambda\), diagonal.

Figure 6: A correlated cloud with its principal axes, and the same cloud after the rotation Uᴴ.

Whitening: ellipsoid into sphere

\(\mathbf A\) whitens \(\mathbf X\) if \(\mathbf A\mathbf C_{\mathbf{XX}}\mathbf A\herm=\mathbf I\). The eigenvectors solve it on sight: \(\mathbf A_{\text{PCA}}=\boldsymbol\Lambda^{-1/2}\mathbf U\herm\), rotate, then divide each axis by its own standard deviation.

Figure 7: The two steps of whitening: the rotation keeps the shape, the rescaling makes it a sphere.

In whitened coordinates the Mahalanobis distance is ordinary Euclidean distance. Whitening is a change of metric, and every \(\mathbf C^{-1}\) that appears later in the course is this change of metric at work.

Whitening is never unique

All whiteners \(\mathbf A\) whitens \(\mathbf X\) if and only if \(\mathbf A=\mathbf Q\,\boldsymbol\Lambda^{-1/2}\mathbf U\herm\) for some unitary \(\mathbf Q\).

A sphere looks the same from every angle, so any rotation after whitening whitens just as well. And every whitener maps \(d_M\) onto Euclidean distance: \(\mathbf Q\) decides which direction becomes which coordinate, never how far apart two points are.

So choosing \(\mathbf Q\) is choosing what else the transform should do.

Three whiteners, three extra properties

PCA, ZCA and Cholesky on one correlated cloud: same destination, three routes.
whitener \(\mathbf A\) what else it buys
PCA \(\boldsymbol\Lambda^{-1/2}\mathbf U\herm\) coordinates ordered by variance
ZCA \(\mathbf U\boldsymbol\Lambda^{-1/2}\mathbf U\herm=\mathbf C^{-1/2}\) the output changes least from the input
Cholesky \(\mathbf D^{-1/2}\mathbf L^{-1}\) causal: output \(i\) uses only inputs \(1,\dots,i\)

→ Demo: the covariance ellipse, Mahalanobis distance, and three whiteners

Coloring: the same factor, backwards

To generate a vector with covariance \(\mathbf C\), factor it and push white noise through:

Coloring \[\mathbf C=\mathbf L\mathbf L\herm,\qquad \mathbf X=\mathbf L\mathbf W,\quad \mathbf C_{\mathbf{WW}}=\mathbf I \quad\Longrightarrow\quad\mathbf C_{\mathbf{XX}}=\mathbf L\mathbf L\herm=\mathbf C .\]

Any whitening factor run backwards will do: the symmetric root \(\mathbf C^{1/2}\) or a Cholesky factor. If \(\mathbf W\) is Gaussian, so is \(\mathbf X\).

Whitening and coloring are one matrix used in two directions: \(\mathbf L^{-1}\) pre-whitens an observation, \(\mathbf L\) generates correlated test signals.

Coloring, drawn

Figure 8: White samples W (left) mapped through the Cholesky factor L of a target covariance C (right), with the target’s 2σ ellipse.

The circle is stretched and sheared into the target ellipse; the sample covariance matches the target. This is how correlated test noise is made.

Keeping only what matters: the KLT

A different question: among all orthonormal bases, which one lets you throw the most away?

Karhunen–Loève Keeping the \(K\) leading eigen-coordinates minimizes the mean-square truncation error over all orthonormal bases, and the minimum is the tail of the spectrum, \(\E{\norm{\mathbf X-\widehat{\mathbf X}_K}^2}=\sum_{i=K+1}^N\lambda_i\).

Why. In any orthonormal basis the error is the discarded energy; the total \(\tr\mathbf C=\sum\lambda_i\) does not depend on the basis; and the largest energy any \(K\)-dimensional subspace can capture is \(\sum_{i\le K}\lambda_i\), on the leading eigenvectors.

The spectrum is the price list

Figure 9: Left: an eigenvalue spectrum and its cumulative energy. Right: the truncation error against K, measured on 4000 draws and predicted by the tail of the spectrum.

The optimal subspace is unique; the basis inside it is not. Energy compaction fixes the subspace; decorrelation is what singles out the eigenbasis within it.

Eigenfaces

The mean face and the eight leading eigenvectors of the pixel covariance, the eigenvalue spectrum, and reconstructions from a growing number of them.

Coarse illumination first, fine detail last. A few dozen numbers describe a face of 4096 pixels, because the pixels move together. Nothing about faces was built into the method: the basis was read off the covariance alone.

Where compression is impossible

No correlation, no compression Faces occupy a tiny, strongly correlated corner of pixel space. Where the data have no such structure, \(\mathbf C_{\mathbf{XX}}\) is near-isotropic, the spectrum is flat, and the theorem promises nothing.

The optimal basis depends on \(\mathbf C_{\mathbf{XX}}\) and must be shipped with every file. That is why practical codecs use a fixed basis and accept a little suboptimality.

The Gaussian vector

Two moments are the whole law

Jointly Gaussian vector \[f_{\mathbf X}(\mathbf x)=\frac{1}{\sqrt{(2\pi)^N\det\mathbf C_{\mathbf{XX}}}} \exp\paren{-\tfrac12\,d_M^2(\mathbf x)} .\]

Two moments are the whole law

Figure 10: Left: the quadratic form d_M², a bowl. Right: exp(−d_M²/2), a bell with the same contours.

The level sets of the density are exactly the covariance ellipsoids. For a Gaussian vector the mean and the covariance are not a summary; they are everything.

The 68–95–99.7 rule does not survive dimension

Left: level sets of a 2-D Gaussian and the probability each encloses. Right: \(d_M^2\sim\chi^2_N\), so the same radius encloses less and less as \(N\) grows.

In one dimension \(d_M\le1\) holds 68% of the mass, in two 39%, in three 20%. In high dimension almost all the mass lies far from the mean, measured in standard deviations: estimation gets harder with dimension.

Two properties that carry the course

The Gaussian vector

  • Closed under linear maps. \(\mathbf A\mathbf X+\mathbf b\) is Gaussian, with covariance \(\mathbf A\mathbf C_{\mathbf{XX}}\mathbf A\herm\): filtering and beamforming never leave the family.
  • Uncorrelated means independent. A diagonal \(\mathbf C_{\mathbf{XX}}\) turns \(d_M^2\) into a sum of squares, and the density factors.

The second line is why, under a Gaussian model, the best linear estimator turns out to be the best estimator of any kind.

“Jointly” matters

Top: every projection of a correlated Gaussian pair is Gaussian. Bottom: \((X,SX)\) with a random sign \(S\): Gaussian marginals, not jointly Gaussian.

\(\mathbf X\) is jointly Gaussian if and only if every projection \(\mathbf a\herm\mathbf X\) is Gaussian. Two marginals are just two projections out of infinitely many; the diagonal one gives \((X,SX)\) away, since \(X+SX\) is exactly zero half the time.

The proper complex Gaussian

\[f_{\mathbf Z}(\mathbf z)=\frac{1}{\pi^N\det\mathbf C_{\mathbf{ZZ}}} \exp\paren{-(\mathbf z-\mathbf m)\herm\mathbf C_{\mathbf{ZZ}}^{-1}(\mathbf z-\mathbf m)}\]

Figure 11: A scalar proper complex Gaussian: a circular blob; radius and phase independent; the radius is Rayleigh.

The flat phase panel is properness seen directly. This is the standard model for receiver noise.

Why the model keeps being right

For iid random vectors with finite covariance, the normalized sum is Gaussian: \(\frac{1}{\sqrt n}\sum_i(\mathbf X_i-\mathbf m)\to\Gauss(\mathbf 0,\mathbf C)\). Proof: apply the scalar central limit theorem to every projection \(\mathbf a\herm\mathbf X\).

Figure 12: Normalized sums of n iid uniform 2-vectors, sheared so the components are correlated.

The square becomes an ellipse whose contours are set by \(\mathbf C\) alone: the first week’s answer, now for vectors.

Recap

This week

  1. Covariance is an inner product, and correlation a cosine. It sees only linear dependence, and correlated measurements are worth fewer than their number.
  1. The covariance matrix is an ellipsoid: \(\mathbf a\herm\mathbf C\mathbf a\) is the variance in direction \(\mathbf a\), and a linear map sends \(\mathbf C\) to \(\mathbf A\mathbf C\mathbf A\herm\).
  1. The eigenvectors are the natural coordinates. Rotating to them decorrelates, rescaling whitens (a change of metric), and keeping the leading ones is the best compression there is. For a Gaussian vector these two moments are the whole story.