MIT 18.701 — Lecture 19

Applications of the Spectral Theorem

Today will be dedicated to applying the Spectral Theorem in three broader contexts.

§ Spectral Application #1: Classifying Quadric Surfaces

We've done enough foreshadowing already.

Let's get to the punchline of this foreshadowing.

Definition (Quadric Surface). A quadric surface in Rn\mathbb{R}^n is a subset of the form {xRnxAx+bx+c=0}\{x \in \mathbb{R}^n \mid x^{\top}Ax + b^{\top}x + c = 0 \} for some symmetric matrix ARn×nA \in \mathbb{R}^{n \times n}, bRnb \in \mathbb{R}^n, and cRc \in \mathbb{R}.

Example. We already know the n=1n = 1 and n=2n = 2 cases from high school.

We now use a special case of the Spectral Theorem in the context of R\mathbb{R}.

Theorem. (Spectral Theorem over Rn\mathbb{R}^n) If ARn×nA \in \mathbb{R}^{n \times n} is symmetric, its eigenvectors form an orthonormal basis.

In other words, there exists some TOn(R)T \in O_n(\mathbb{R}) such that TAT=ΛT^{\top}AT = \Lambda, where Λ\Lambda is diagonal. Thus,

xAx+bx+c=0      (T1x)(TAT)(T1x)+(Tb)(T1x)+c=0 by plain computation       yΛy+(Tb)y+c=0 where y=T1x      (λ1y12++λnyn2)+(b1y1++bnyn)+c=0\begin{align*}& x^{\top}Ax + b^{\top}x + c = 0 \\ \iff ~~ & \textcolor{#bf0140}{(T^{-1}x)}^{\top} (T^{\top}AT)\textcolor{#bf0140}{(T^{-1}x)} + (T^{\top}b)^{\top}\textcolor{#bf0140}{(T^{-1}x)} + c = 0 & \text{ by plain computation } \\ \iff ~~ & y^{\top}\Lambda y + (T^{\top}b)^{\top}y + c = 0 & \text{ where } \textcolor{#bf0140}{y = T^{-1}x} \\ \iff ~~ & \left(\lambda_1y_1^2 + \dots + \lambda_ny_n^2\right) + \left(b_1'y_1 + \dots + b_n'y_n\right) + c = 0\end{align*}

The point is that y=T1xy = T^{-1}x represents an orthonormal change of basis because TOn(R)T \in O_n(\mathbb{R}). Therefore,

Theorem. (Quadric Classification) All quadric surfaces, up to an orthonormal change of basis, look like:

{yRn:(i=1nλiyi2)+(i=1nbiyi)+c=0}\left\{ y \in \mathbb{R}^n : \left(\sum_{i = 1}^n \lambda_i y_i^2\right) + \left(\sum_{i = 1}^n b_i y_i \right) + c = 0 \right \}

Furthermore, if detA0\det A \neq 0, then each λi\lambda_i is nonzero, so we can complete the square, leaving i=1nλiyi2=k\sum_{i = 1}^n \lambda_i y_i^2 = k for some constant kk. When k0k \neq 0, we can also scale, yielding…

Theorem. (Non-Singular Quadric Classification) All nonsingular quadric surfaces—those with detA0\det A \neq 0 and k0k \neq 0—are affinely equivalent to:

{yRn:i=1nλiyi2=1}, where each λi is either +1 or 1.\left\{ y \in \mathbb{R}^n : \sum_{i = 1}^n \lambda_i y_i^2 = 1 \right \}, \text{ where each $\lambda_i$ is either $+1$ or $-1$.}

Some corollaries of these observations:

§ Spectral Application #2: Principal Component Analysis

For this section, here's the setup:

Setup. Take nn random variables {Xi}i=1n\{X_i\}_{i = 1}^n in a column vector XRnX \in \mathbb{R}^n.
Normalize the XiX_i so that E[Xi]=0\mathbb{E}[X_i] = 0 for all ii. (In other words, E[X]=0\mathbb{E}[X] = 0.)

We'll first build all necessary mathematical foundations, up to the Rayleigh-Ritz theorem.

Definition (Variance, Covariance, Covariance Matrix). Let AA and BB be random variables in XX.

Theorem. (Variance of Linear Combinations) Let M:=Cov(X)M := \mathrm{Cov}(X). Then for any cRnc \in \mathbb{R}^n, we have Var(cX)=cMc\Var(c^{\top}X) = c^{\top}Mc.

Proof: Just plain computation.

Var(cX)=Var(i=1nciXi)=E[(i=1nciXi)2]=cMc.   \Var(c^{\top}X) = \Var\left(\sum_{i = 1}^n c_iX_i\right) = \mathbb{E}\left [ \left(\sum_{i = 1}^n c_i X_i \right)^2 \right ] = c^{\top}Mc. ~~~ \blacksquare

Theorem. (Rayleigh-Ritz) Let MM be any symmetric matrix with normalized eigenvectors {v1,,vn}\{v_1, \dots, v_n\} and corresponding eigenvalues λ1λn\lambda_1 \geq \dots \geq \lambda_n. Then:

maxcRn{0}cMccc=λ1,  and more generally,  maxcRn{0}cvi for all i<kcMccc=λk.\max_{c \in \mathbb{R}^n \setminus \{0\}} \dfrac{c^{\top}Mc}{c^{\top}c} = \lambda_1, ~ \text{ and more generally, } ~ \max_{\substack{c \in \mathbb{R}^n \setminus \{0\} \\ c \perp v_i \text{ for all } i < k}} \dfrac{c^{\top}Mc}{c^{\top}c} = \lambda_k.

Proof: By the Spectral theorem, {v1,,vn}\{v_1, \dots, v_n\} is an orthonormal basis. Writing c=i=1nαivic = \sum_{i = 1}^n \alpha_i v_i yields:

cMccc=i=1nαi2λii=1nαi2=i=1n(αi2j=1nαj2)λi.\dfrac{c^{\top}Mc}{c^{\top}c} = \dfrac{\sum_{i = 1}^n \alpha_i^2 \lambda_i}{\sum_{i = 1}^n \alpha_i^2} = \sum_{i = 1}^n \left(\dfrac{\alpha_i^2}{\sum_{j = 1}^n \alpha_j^2}\right) \lambda_i.

This is a weighted average of {λi}i=1n\{\lambda_i\}_{i = 1}^n, and the maximum possible weighted average is max{λi}i=1n=λ1\max\{\lambda_i\}_{ i = 1}^n = \lambda_1.

More generally, when cvic \perp v_i for all i<ki < k, we're forced to have αi=0\alpha_i = 0 for all i<ki < k. Then we instead have a weighted average of {λi}i=kn\{\lambda_i\}_{i = k}^n, for which the maximum possible value is λk\lambda_k.   \blacksquare

Mathematics aside, here's what we wish to do with our random variables {Xi}i=1n\{X_i\}_{i = 1}^n from earlier.

Intuition. Many samples from XX form a point cloud in Rn\mathbb{R}^n. We wish to look at
this point cloud from a certain angle—a certain orthonormal basis, perhaps—so that
the axes of our orthonormal basis point in “meaningful directions”.

What qualifies as a “meaningful direction”, then? The Rayleigh-Ritz theorem proposes a good candidate.

Theorem. (Rayleigh-Ritz Corollary) Let MM be the covariance matrix of XX. Then Var(cX)cc\frac{\Var(c^{\top}X)}{c^{\top}c} is maximized when cc is the eigenvector of MM with greatest eigenvalue.

Think of our point cloud as a messy ellipsoid centered at the origin. Then the cc that maximizes Var(cX)cc\frac{\Var(c^{\top}X)}{c^{\top} c} will be the cc that points along the highest-variance axis of XX—that is, the longest axis of the ellipsoid!

In fact, the more general case of Rayleigh-Ritz indicates that the set of all eigenvectors of MM will point along orthogonal axes of this ellipsoid! In conclusion,

— Conclusion (PCA) —

Given a point cloud XX of data with covariance matrix MM,
we can identify the most “principal components” of the point cloud
by picking out the eigenvectors of MM with the greatest eigenvalues.

Naturally, the strategy of using the eigenvectors of MM to analyze XX is called Principal Component Analysis (PCA).

In the particular context of facial recognition, eigenfaces are a set of eigenvectors whose linear combination with unique coefficients yields distinct faces.

§ Spectral Application #3: Singular Value Decomposition

Here's the setup this time.

Setup. We have nn normalized random variables {Xi}i=1n\{X_i\}_{i = 1}^n, and we sample each one mm times.
This gives us a matrix XRm×nX \in \mathbb{R}^{m \times n}, where Xi,jX_{i, j} gives the ithi^{\text{th}} sample of XjX_j.

We'll first state the necessary mathematics, then show its applications, and finally prove the mathematics.

Definition (Sample Covariance). The sample covariance matrix of XX is the n×nn \times n matrix Cov(X):=1m1XX\mathrm{Cov}(X) := \frac{1}{m - 1} X^{\top}X.

Intuitively, Cov(X)i,j\mathrm{Cov}(X)_{i, j} gives the sample covariance of XiX_i and XjX_j.

Theorem. (Singular Value Decomposition) Every matrix ARm×nA \in \mathbb{R}^{m \times n} factors in the following way:

A=VΣW   for some   VOm(R), WOn(R), and diagonal ΣRm×n.A = V \Sigma W^{\top} ~~ \text{ for some } ~~ V \in O_m(\mathbb{R}), ~ W \in O_n(\mathbb{R}), \text{ and diagonal } \Sigma \in \mathbb{R}^{m \times n}.

If Σ\Sigma has diagonal entries σ1σ20\sigma_1 \geq \sigma_2 \geq \dots \geq 0, then we say {σi}\{\sigma_i\} are the singular values of AA.

If XX factors in this way as X=VΣWX = V \Sigma W^{\top} with singular values {σi}\{\sigma_i\}, then the sample covariance matrix is:

Cov(X)=1m1(WΣV)(VΣW)=1m1W(ΣΣ)W=1m1W[σ1200σn2]W\mathrm{Cov}(X) = \dfrac{1}{m - 1} (W \Sigma^{\top} V^{\top}) (V \Sigma W^{\top}) = \dfrac{1}{m - 1} W (\Sigma^{\top} \Sigma)W^{\top} = \dfrac{1}{m - 1} W \left[\begin{smallmatrix} \sigma_1^2 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & \sigma_n^2 \end{smallmatrix}\right]W^{\top}

The way ΣΣ\Sigma^{\top}\Sigma is written above assumes mnm \geq n. If m<nm < n, then the remaining nmn - m diagonal entries are zeroes.

— Conclusion (SVD on Covariance Matrices) —

Consider a matrix XRm×nX \in \mathbb{R}^{m \times n} of data. Assume mnm \geq n.
Factor XX as VΣWV \Sigma W^{\top} with singular values σ1σ20\sigma_1 \geq \sigma_2 \geq \dots \geq 0.

Then Cov(X)\mathrm{Cov}(X) has eigenvalues {σi2m1}i=1n\left\{\tfrac{\sigma_i^2}{m - 1}\right\}_{i = 1}^n and eigenvectors being the columns of WW.

(If m<nm < n, then the remaining nmn - m eigenvalues are zeroes.)

Some useful diagrams depicting object-level examples of what SVD does.

Some good things to keep in mind while we prove SVD.

Proof: Assume without loss of generality that nmn \leq m. (If instead nmn \geq m, work with AA^{\top} instead of AA.)

We begin by rephrasing our win condition.

Claim. It suffices to find orthonormal bases {v1,,vm}Rm\{v_1, \dots, v_m\} \subseteq \mathbb{R}^m and {w1,,wn}Rn\{w_1, \dots, w_n\} \subseteq \mathbb{R}^n and constants {σ1,,σn}\{\sigma_1, \dots, \sigma_n\} such that Awi=σiviAw_i = \sigma_i v_i for all i=1,2,,ni = 1, 2, \dots, n.

Proof: Use the {vi}i=1m\{v_i\}_{i = 1}^m and {wi}i=1n\{w_i\}_{i = 1}^n as columns of VV and WW, and use the {σi}i=1n\{\sigma_i\}_{i = 1}^n as the diagonal of Σ\Sigma.

To show A=VΣWA = V\Sigma W^{\top}, it suffices to check that AA and VΣWV \Sigma W^{\top} agree on the images of every element in some basis of the domain Rn\mathbb{R}^n. Let's use the basis {wi}i=1n\{w_i\}_{i = 1}^n.

(1)   A(wi)=σivi by assumption.           (2)   VΣW(wi)=σivi by computation.(1) ~~~ A(w_i) = \sigma_i v_i \text{ by assumption.} ~~~~~~~~~~~ (2) ~~~ V \Sigma W^{\top}(w_i) = \sigma_i v_i \text{ by computation.}

Hooray—they match.   \square

Observe the following properties of AARn×nA^{\top}A \in \mathbb{R}^{n \times n}.

Great! We've already found {wi}i=1n\{w_i\}_{i = 1}^n and {σi}i=1n\{\sigma_i\}_{i = 1}^n.

For {vi}i=1m\{v_i\}_{i = 1}^m, we'll just take vi=Awiσiv_i = \frac{Aw_i}{\sigma_i} for ini \leq n, then fill in the rest arbitrarily (maintaining orthonormality).

Well, it's pretty obvious that Awi=σiviAw_i = \sigma_i v_i will hold for all ii. Now we just need to show {vi}i=1m\{v_i\}_{i = 1}^m is orthonormal.

vi,vj=vivj=wjAAwiσiσj=wj(σi2wi)σiσj=σiσjwj,wi={1 if i=j0 if ij\langle v_i, v_j \rangle = v_i^{\top}v_j = \frac{w_j^{\top}A^{\top}Aw_i}{\sigma_i \sigma_j} = \frac{w_j^{\top}(\sigma_i^2 w_i)}{\sigma_i \sigma_j} = \frac{\sigma_i}{\sigma_j}\langle w_j, w_i \rangle = \begin{cases} 1 & \text{ if } i = j \\ 0 & \text{ if } i \neq j \end{cases}

We've checked everything we needed, so we're done.   \clubsuit

Well, okay, fine—there's one issue we missed, shown in orange. If σi=0\sigma_i = 0, then vi=Awiσiv_i = \frac{Aw_i}{\sigma_i} doesn't make sense. Fortunately, if σi=0\sigma_i = 0, there's an easy fix.

σi=0.      AAwi=0.      wi,AAwi=0.      Awi,Awi=0.      Awi=0.\sigma_i = 0 . ~ \implies ~ A^{\top}Aw_i = 0. ~ \implies ~ \langle w_i, A^{\top}Aw_i \rangle = 0. ~ \implies ~ \langle Aw_i, Aw_i \rangle = 0. ~ \implies ~ Aw_i = 0.

Thus, the constraint Awi=σiviAw_i = \sigma_i v_i holds trivially—again just pick viv_i arbitrarily, maintaining orthonormality.   \blacksquare

Unlike some of our previous “factorization” theorems, this one applies to all matrices!

Remark. Despite how long the above proof is, it's actually extremely motivated—in particular, AAAA^{\top} and AAA^{\top}A tell us what VV, WW, and Σ\Sigma have to be, and then it remains to check that everything remains consistent.

Hint: It is rumored that the SVD may be useful for Problem Set #10.

§ Linear Groups

We're about to transition to a new topic: embedding groups into geometric objects.

Example. There exists a natural bijection SO2(R)S1SO_2(\mathbb{R}) \leftrightarrow S^1, where S1S^1 is the unit circle.

The interesting point, however, is that it's surprisingly difficult to embed SO3(R)SO_3(\mathbb{R}) into a geometric object!

Here are some failed attempts:

Spoilers: it turns out S3S^3 and the quaternions will be the most natural parametrization of SO3(R)SO_3(\mathbb{R}).