Simple Algorithm
Machine Learning · Convergence · 28 min

PCA in Depth

Variance, reconstruction, the SVD and probabilistic PCA.

PCA fits in one line, yet a century of theory went into knowing when its components mean anything. This lesson proves the theorem behind both of PCA's optimality properties, turns PCA into a probability model with a closed-form likelihood, uses random-matrix theory to tell signal components from noise, and extends PCA to curved structure, gross corruptions and sparse directions.

What you’ll learn

  • Prove Ky Fan's maximum principle and derive from it PCA's optimality for variance and reconstruction, with the uniqueness condition λk>λk+1\lambda_k>\lambda_{k+1}.
  • Derive the maximum-likelihood solution of probabilistic PCA, run its EM algorithm, and contrast it with factor analysis.
  • State the BBP phase transition of the spiked covariance model, compute the limiting eigenvalue and eigenvector overlap, and use random-matrix thresholds to choose the number of components.
  • Formulate kernel PCA (centering in feature space, the Gram eigenproblem, new points, pre-images), robust PCA by principal component pursuit, and sparse PCA, with their guarantees and limits.

Ky Fan’s theorem: one optimum, two meanings

Let SS be the sample covariance of centered data, with eigenvalues λ1≥⋯≥λd≥0\lambda_1\ge\dots\ge\lambda_d\ge0 and orthonormal eigenvectors v1,…,vd\mathbf v_1,\dots,\mathbf v_d. The Descent lesson Dimensionality Reduction showed that for every V∈Rd×kV\in\R^{d\times k} with V⊤V=IkV^\top V=I_k, the mean squared reconstruction error of projecting onto span⁡(V)\operatorname{span}(V) equals tr⁡S−tr⁡(V⊤SV)\operatorname{tr}S-\operatorname{tr}(V^\top SV). Both of PCA's optimality properties therefore rest on a single statement about tr⁡(V⊤SV)\operatorname{tr}(V^\top SV).

DerivationProof
  1. tr⁡(V⊤AV)=tr⁡(AP)=∑j=1dλj vj⊤Pvj=∑j=1dλj wj\operatorname{tr}(V^\top AV)=\operatorname{tr}(AP)=\sum_{j=1}^d\lambda_j\,\mathbf v_j^\top P\mathbf v_j=\sum_{j=1}^d\lambda_j\,w_j

    Let P=VV⊤P=VV^\top, the orthogonal projection onto span⁡(V)\operatorname{span}(V). Expanding AA in its eigenbasis turns the objective into a weighted sum of eigenvalues, with weights wj=vj⊤Pvj=∥Pvj∥2w_j=\mathbf v_j^\top P\mathbf v_j=\norm{P\mathbf v_j}^2:

  2. 0≤wj≤1,∑j=1dwj=tr⁡P=k0\le w_j\le1,\qquad\sum_{j=1}^dw_j=\operatorname{tr}P=k

    A projection never lengthens a vector, and the weights add up to the trace of PP, which equals its rank kk:

  3. ∑jλjwj−∑j≤kλj=∑j≤k(λj−λk)(wj−1)+∑j>k(λj−λk) wj ≤ 0\sum_{j}\lambda_jw_j-\sum_{j\le k}\lambda_j=\sum_{j\le k}(\lambda_j-\lambda_k)(w_j-1)+\sum_{j>k}(\lambda_j-\lambda_k)\,w_j\ \le\ 0

    So the objective can be no better than spending a total weight kk, at most 1 per eigenvalue, on the top kk. Formally, subtract λ1+⋯+λk\lambda_1+\dots+\lambda_k and use ∑jwj=k\sum_jw_j=k. Both sums on the right are ≤0\le0, because λj−λk≥0\lambda_j-\lambda_k\ge0 and wj≤1w_j\le1 in the first, and λj−λk≤0\lambda_j-\lambda_k\le0 and wj≥0w_j\ge0 in the second:

  4. λk>λk+1⟹span⁡(V⋆)=span⁡(v1,…,vk)  for every maximizer V⋆\lambda_k>\lambda_{k+1}\quad\Longrightarrow\quad\operatorname{span}(V^\star)=\operatorname{span}(\mathbf v_1,\dots,\mathbf v_k)\ \text{ for every maximizer }V^\star

    Equality holds at V=[v1,…,vk]V=[\mathbf v_1,\dots,\mathbf v_k], where wj=1w_j=1 for j≤kj\le k and 00 after. If λk>λk+1\lambda_k>\lambda_{k+1}, equality forces wj=0w_j=0 for all j>kj>k, hence wj=1w_j=1 for j≤kj\le k: span⁡(V)\operatorname{span}(V) contains v1,…,vk\mathbf v_1,\dots,\mathbf v_k and so equals their span. With a tie λk=λk+1\lambda_k=\lambda_{k+1} the maximizer is not unique: the part of the subspace that lies in the tied eigenspace can be any subspace of the right dimension.

With A=SA=S this settles both readings of PCA at once: the top-kk eigenvectors maximize the captured variance and minimize the mean squared reconstruction error, λk+1+⋯+λd\lambda_{k+1}+\dots+\lambda_d. Three consequences:

  • Greedy is optimal. Hotelling's one-component-at-a-time construction (deflation) reaches the joint optimum, which most greedy procedures do not.
  • Only the subspace is identified. V↦VRV\mapsto VR with orthogonal RR changes nothing, and with a near-tie λk≈λk+1\lambda_k\approx\lambda_{k+1} even the subspace is ill-determined: by the Davis–Kahan theorem (Linear Algebra for ML: Eigenvectors & the SVD), an estimated subspace can rotate by up to about the perturbation divided by the eigengap.
  • No rank-kk matrix does better (Eckart–Young). For any BB of rank at most kk, let PP project onto a kk-dimensional subspace that contains the row space of BB. Every row of BB lies in that subspace, so row by row ∥X~−B∥F≥∥X~−X~P∥F\norm{\tilde X-B}_F\ge\norm{\tilde X-\tilde XP}_F, and Ky Fan bounds the right side: ∥X~−X~P∥F2=n(tr⁡S−tr⁡(PS))≥n(λk+1+⋯+λd)=∑j>kσj2\norm{\tilde X-\tilde XP}_F^2=n\big(\operatorname{tr}S-\operatorname{tr}(PS)\big)\ge n(\lambda_{k+1}+\dots+\lambda_d)=\sum_{j>k}\sigma_j^2. The truncated SVD X~VkVk⊤\tilde XV_kV_k^\top attains it, so no linear encoder–decoder of width kk, orthonormal or not, beats PCA. Centering played no role: with S=X⊤X/nS=X^\top X/n the same lines prove the Frobenius-norm Eckart–Young theorem for any matrix XX. (The spectral-norm case is in Linear Algebra for ML: Eigenvectors & the SVD.)

Probabilistic PCA and factor analysis

DerivationProof sketch
  1. ∂ℓ∂W=n(C−1SC−1W−C−1W)=0⟹SC−1W=W\frac{\partial\ell}{\partial W}=n\big(C^{-1}SC^{-1}W-C^{-1}W\big)=0\quad\Longrightarrow\quad SC^{-1}W=W

    Differentiate, using ∂Wln⁡det⁡C=2C−1W\partial_W\ln\det C=2C^{-1}W and ∂Wtr⁡(C−1S)=−2C−1SC−1W\partial_W\operatorname{tr}(C^{-1}S)=-2C^{-1}SC^{-1}W. Stationary points satisfy

  2. Suj=(σ2+lj2) uj⟹lj=λ(j)−σ2  for some eigenvalue λ(j) of SS\mathbf u_j=(\sigma^2+l_j^2)\,\mathbf u_j\qquad\Longrightarrow\qquad l_j=\sqrt{\lambda_{(j)}-\sigma^2}\ \text{ for some eigenvalue }\lambda_{(j)}\text{ of }S

    Write the thin SVD W=ULR⊤W=ULR^\top with L=diag⁡(lj)L=\diag(l_j), lj>0l_j>0. Each column uj\mathbf u_j of UU is an eigenvector of CC with eigenvalue lj2+σ2l_j^2+\sigma^2, so C−1W=U(L2+σ2I)−1LR⊤C^{-1}W=U(L^2+\sigma^2I)^{-1}LR^\top, and the stationarity condition makes every uj\mathbf u_j an eigenvector of SS:

  3. ℓ=−n2[dln⁡2π+∑j∈Kln⁡λj+(d−k)ln⁡(1d−k∑j∉Kλj)+d]\ell=-\frac n2\Big[d\ln2\pi+\sum_{j\in K}\ln\lambda_j+(d-k)\ln\Big(\frac1{d-k}\sum_{j\notin K}\lambda_j\Big)+d\Big]

    Plug back in, with KK the set of chosen eigenvalues. On their eigenvectors CC agrees with SS; on the other d−kd-k it equals σ2\sigma^2. So ln⁡det⁡C=∑j∈Kln⁡λj+(d−k)ln⁡σ2\ln\det C=\sum_{j\in K}\ln\lambda_j+(d-k)\ln\sigma^2 and tr⁡(C−1S)=k+σ−2∑j∉Kλj\operatorname{tr}(C^{-1}S)=k+\sigma^{-2}\sum_{j\notin K}\lambda_j. Maximizing over σ2\sigma^2 gives the average of the discarded eigenvalues, and

  4. ln⁡1d−k∑j∉Kλj(∏j∉Kλj)1/(d−k) ≥ 0(AM–GM)\ln\frac{\frac1{d-k}\sum_{j\notin K}\lambda_j}{\big(\prod_{j\notin K}\lambda_j\big)^{1/(d-k)}}\ \ge\ 0\qquad\text{(AM–GM)}

    Since ∑j∈Kln⁡λj=∑jln⁡λj−∑j∉Kln⁡λj\sum_{j\in K}\ln\lambda_j=\sum_j\ln\lambda_j-\sum_{j\notin K}\ln\lambda_j, maximizing ℓ\ell means minimizing (d−k)(d-k) times the log of the ratio between the arithmetic and geometric means of the discarded eigenvalues, which is zero only when they are all equal. Among choices that keep every λj>σ2\lambda_j>\sigma^2 (needed for real ljl_j), the optimum discards the d−kd-k smallest: the noise model wants the leftover spectrum as flat as possible.

Predict before you look

A sample covariance in d=5d=5 dimensions has eigenvalues 5, 3, 1.2, 0.5, 0.35,\ 3,\ 1.2,\ 0.5,\ 0.3. Fit probabilistic PCA with k=2k=2. What is σML2\sigma^2_{\mathrm{ML}}?

Show the answer

0.67

σML2=(1.2+0.5+0.3)/3≈0.667\sigma^2_{\mathrm{ML}}=(1.2+0.5+0.3)/3\approx0.667. The columns of WMLW_{\mathrm{ML}} (with R=IR=I) have lengths 5−0.667≈2.08\sqrt{5-0.667}\approx2.08 and 3−0.667≈1.53\sqrt{3-0.667}\approx1.53. The fitted covariance has eigenvalues 5,3,0.667,0.667,0.6675,3,0.667,0.667,0.667, so its trace, 10, equals that of SS: the model keeps the total variance and flattens the tail.

What the likelihood buys:

  • PCA is the zero-noise limit. As σ2→0\sigma^2\to0, M−1W⊤→(W⊤W)−1W⊤M^{-1}W^\top\to(W^\top W)^{-1}W^\top: the posterior mean becomes the coordinates of the orthogonal projection onto the principal subspace.
  • Denoising by shrinkage. At the optimum, the posterior-mean reconstruction is ∑j≤k(1−σ2/λj) ujuj⊤(x−xˉ)\sum_{j\le k}(1-\sigma^2/\lambda_j)\,\mathbf u_j\mathbf u_j^\top(\mathbf x-\bar{\mathbf x}): weak components are shrunk most.
  • Model choice. ℓ\ell can be compared across kk with a complexity penalty; the covariance has dk−k(k−1)/2+1dk-k(k-1)/2+1 free parameters.
  • EM. The EM algorithm fits PPCA without forming SS, at about ndkndk operations per iteration, and handles missing entries. As σ2→0\sigma^2\to0 it becomes alternating least squares converging to the principal subspace (Roweis, 1998).
text
EM-PPCA(centered data rows x_1..x_n in R^d, latent dimension k)
  initialize W (d x k) at random, sigma2 > 0
  repeat until the log-likelihood stops increasing:
      M = W^T W + sigma2 * I_k                                  # k x k
      E-step:  m_i = M^{-1} W^T x_i                             # posterior means
               G   = n * sigma2 * M^{-1} + sum_i m_i m_i^T      # sum of E[z_i z_i^T]
      M-step:  W_new  = (sum_i x_i m_i^T) G^{-1}
               sigma2 = (1/(n d)) * sum_i ( |x_i|^2 - 2 m_i^T W_new^T x_i )
                        + (1/(n d)) * trace(G W_new^T W_new)
               W = W_new

Each iteration never decreases the likelihood (as for any EM algorithm; see Latent Variables & EM) and converges to the closed-form maximum from almost every start; the fitted WW is WMLW_{\mathrm{ML}} up to the rotation RR.

Factor analysis, which goes back to Spearman's 1904 "general intelligence" factor, gives every feature its own noise variance: ε∼N(0,Ψ)\boldsymbol\varepsilon\sim\mathcal N(\mathbf 0,\Psi) with Ψ\Psi diagonal. The closed form is lost (EM fits it: Rubin & Thayer, 1982), but the model becomes scale-equivariant: rescaling feature jj rescales row jj of WW and ψj\psi_j, nothing else. Factor analysis explains correlations with shared factors and puts each feature's private variance in Ψ\Psi; PCA spends components on whatever varies most.

AspectPCAProbabilistic PCAFactor analysis
Noise modelnone: a projectionisotropic, σ2I\sigma^2Idiagonal, Ψ\Psi
Fiteigenvectors of SSclosed form, or EMEM; no closed form
Equivariant underrotationsrotationsrescaling single features
Latent axesunique if eigenvalues are distinctup to a rotation RRup to a rotation

How many components are real? Spikes and the BBP transition

Classical asymptotics fix dd and let n→∞n\to\infty, so that S→ΣS\to\Sigma and every sample eigenvalue converges to the truth. When dd is comparable to nn, the sample spectrum is distorted in a precise way. For pure noise, Σ=σ2Id\Sigma=\sigma^2I_d with d/n→γ∈(0,1]d/n\to\gamma\in(0,1], the eigenvalues of SS spread over the Marchenko–Pastur interval [σ2(1−γ)2, σ2(1+γ)2]\big[\sigma^2(1-\sqrt\gamma)^2,\ \sigma^2(1+\sqrt\gamma)^2\big] (Marchenko & Pastur, 1967) although every population eigenvalue is σ2\sigma^2. The largest converges to the upper edge (Geman, 1980) with fluctuations of order n−2/3n^{-2/3} that follow the Tracy–Widom law (Johnstone, 2001). Johnstone also proposed the model that makes "which components are real?" a precise question.

DerivationWhere the threshold comes from
  1. det⁡(zI−WΣ)=det⁡(zI−W) (1−ℓ v⊤(zI−W)−1Wv)\det(zI-W\Sigma)=\det(zI-W)\,\big(1-\ell\,\mathbf v^\top(zI-W)^{-1}W\mathbf v\big)

    Write S=Σ1/2WΣ1/2S=\Sigma^{1/2}W\Sigma^{1/2}, with WW the sample covariance of white noise. SS has the same eigenvalues as WΣ=W+ℓ Wvv⊤W\Sigma=W+\ell\,W\mathbf v\mathbf v^\top, a rank-one perturbation of WW. For zz not an eigenvalue of WW, the matrix determinant lemma gives

  2. v⊤(zI−W)−1Wv ⟶ ∫xz−x dμγ(x)=z mγ(z)−1,mγ(z)=∫dμγ(x)z−x\mathbf v^\top(zI-W)^{-1}W\mathbf v\ \longrightarrow\ \int\frac{x}{z-x}\,d\mu_\gamma(x)=z\,m_\gamma(z)-1,\qquad m_\gamma(z)=\int\frac{d\mu_\gamma(x)}{z-x}

    So an eigenvalue of SS outside the noise spectrum must solve ℓ v⊤(zI−W)−1Wv=1\ell\,\mathbf v^\top(zI-W)^{-1}W\mathbf v=1. Gaussian WW is rotation-invariant, so for a fixed unit v\mathbf v the quadratic form converges to an integral against the Marchenko–Pastur law μγ\mu_\gamma:

  3. γz m2−(z−1+γ) m+1=0,z m=1+1ℓ⟹m=1ℓ+γ,z=(1+ℓ)(1+γℓ)\gamma z\,m^2-(z-1+\gamma)\,m+1=0,\qquad z\,m=1+\frac1\ell\quad\Longrightarrow\quad m=\frac1{\ell+\gamma},\qquad z=(1+\ell)\Big(1+\frac\gamma\ell\Big)

    The transform mγm_\gamma solves a quadratic, and the outlier condition reads z mγ(z)=1+1/ℓz\,m_\gamma(z)=1+1/\ell. The value m=1/(ℓ+γ)m=1/(\ell+\gamma) satisfies both equations at once, which locates the outlier:

  4. 1ℓ+γ<1γ+γ  ⟺  ℓ>γ\frac1{\ell+\gamma}<\frac1{\sqrt\gamma+\gamma}\iff\ell>\sqrt\gamma

    Right of the edge λ+=(1+γ)2\lambda_+=(1+\sqrt\gamma)^2, mγm_\gamma decreases from mγ(λ+)=1/(γ+γ)m_\gamma(\lambda_+)=1/(\sqrt\gamma+\gamma) to 00. The candidate m=1/(ℓ+γ)m=1/(\ell+\gamma) lies in that range only if ℓ>γ\ell>\sqrt\gamma; otherwise no eigenvalue separates from the noise and λ^1\hat\lambda_1 sticks to the edge. At ℓ=γ\ell=\sqrt\gamma the formula gives exactly λ+\lambda_+. The eigenvector limit comes from the derivative of the same transform.

Predict before you look

Data have d=n/4d=n/4 dimensions (γ=0.25\gamma=0.25), and one spike doubles the variance along v\mathbf v (ℓ=1\ell=1). In the limit, what is the squared cosine ∣⟨v^,v⟩∣2\abs{\langle\hat{\mathbf v},\mathbf v\rangle}^2 between the top sample eigenvector and the truth?

Show the answer

0.6

The spike is above the threshold γ=0.5\sqrt\gamma=0.5, so ∣⟨v^,v⟩∣2→(1−0.25)/(1+0.25)=0.6\abs{\langle\hat{\mathbf v},\mathbf v\rangle}^2\to(1-0.25)/(1+0.25)=0.6, an angle of about 39°. The eigenvalue is inflated: λ^1→2×1.25=2.5\hat\lambda_1\to2\times1.25=2.5, although the true variance along v\mathbf v is 2. A simulation with n=4000n=4000 and d=1000d=1000 (four runs) gives 2.49 and 0.61. With ℓ=0.4\ell=0.4, below the threshold, it gives λ^1≈2.23\hat\lambda_1\approx2.23, just below the noise edge 2.252.25, and a squared overlap of a few hundredths at most: the spike is invisible.

What this means for choosing kk:

  • The noise edge. A component whose eigenvalue sits inside the noise bulk is indistinguishable from noise, so σ2(1+γ)2\sigma^2(1+\sqrt\gamma)^2, with σ2\sigma^2 estimated robustly, is a natural cutoff. Horn's (1965) parallel analysis is its empirical version: keep components whose eigenvalues beat those of random data of the same size (in a common variant, the data with each column independently permuted).
  • Above the edge is not enough. Just past the transition the estimated direction is nearly orthogonal to the truth, and keeping it can add more error than it removes. For an n×nn\times n matrix in white noise of known level σ\sigma, whose noise singular values reach about 2n σ2\sqrt n\,\sigma, the best hard threshold on singular values is (4/3)n σ≈2.309n σ(4/\sqrt3)\sqrt n\,\sigma\approx2.309\sqrt n\,\sigma, or 2.8582.858 times the median singular value when σ\sigma is unknown (Gavish & Donoho, 2014). Optimal shrinkage of each eigenvalue does better still (Donoho, Gavish & Johnstone, 2018).
  • Likelihood. Minka (2000) approximates the Bayesian evidence of probabilistic PCA for each kk (scikit-learn's PCA(n_components='mle')).
  • Cross-validation, done right. Held-out rows cannot choose kk: the fitted subspaces are nested, so their reconstruction error only falls as kk grows. Hold out individual entries instead (Wold, 1978; Bro, Kjeldahl, Smilde & Kiers, 2008).

Kernel PCA: components in a feature space

Map each input to φ(x)\varphi(\mathbf x) in a feature space H\mathcal H with kernel k(x,x′)=⟨φ(x),φ(x′)⟩k(\mathbf x,\mathbf x')=\langle\varphi(\mathbf x),\varphi(\mathbf x')\rangle (The Kernel Trick). PCA in H\mathcal H finds directions that are nonlinear in the input, but H\mathcal H may be infinite-dimensional, so everything must be written through kernel values (Schölkopf, Smola & Müller, 1998). Even centering needs care: the centered features φ~(xi)=φ(xi)−1n∑mφ(xm)\tilde\varphi(\mathbf x_i)=\varphi(\mathbf x_i)-\frac1n\sum_m\varphi(\mathbf x_m) cannot be computed, but their inner products can. With H=I−1n11⊤H=I-\frac1n\mathbf 1\mathbf 1^\top, the centered Gram matrix is K~=HKH\tilde K=HKH, that is K~ij=Kij−Kˉi⋅−Kˉ⋅j+Kˉ⋅⋅\tilde K_{ij}=K_{ij}-\bar K_{i\cdot}-\bar K_{\cdot j}+\bar K_{\cdot\cdot} (row, column and grand means of KK).

DerivationThe kernel PCA eigenproblem, and new points
  1. Cv=λv⟹v=1nλ∑i=1nφ~i ⟨φ~i,v⟩=∑i=1nαi φ~iC\mathbf v=\lambda\mathbf v\quad\Longrightarrow\quad\mathbf v=\frac1{n\lambda}\sum_{i=1}^n\tilde\varphi_i\,\langle\tilde\varphi_i,\mathbf v\rangle=\sum_{i=1}^n\alpha_i\,\tilde\varphi_i

    Let C=1n∑iφ~iφ~i⊤C=\frac1n\sum_i\tilde\varphi_i\tilde\varphi_i^\top be the feature-space covariance, with φ~i=φ~(xi)\tilde\varphi_i=\tilde\varphi(\mathbf x_i). Any eigenvector with eigenvalue λ>0\lambda>0 is a combination of the data, because CvC\mathbf v is:

  2. 1nK~2α=λK~α⟸K~α=μα,μ=nλ\frac1n\tilde K^2\boldsymbol\alpha=\lambda\tilde K\boldsymbol\alpha\quad\Longleftarrow\quad\tilde K\boldsymbol\alpha=\mu\boldsymbol\alpha,\qquad\mu=n\lambda

    Substitute and take inner products with every φ~l\tilde\varphi_l. The result involves only K~\tilde K, and it is solved by the eigenvectors of K~\tilde K (other solutions differ by null vectors of K~\tilde K, which give the same v\mathbf v):

  3. αj=ajμj,training scores  ⟨φ~l,vj⟩=(K~αj)l=μj alj\boldsymbol\alpha_j=\frac{\mathbf a_j}{\sqrt{\mu_j}},\qquad\text{training scores }\ \langle\tilde\varphi_l,\mathbf v_j\rangle=(\tilde K\boldsymbol\alpha_j)_l=\sqrt{\mu_j}\,a_{lj}

    Normalize in H\mathcal H, not in Rn\R^n: ∥v∥2=α⊤K~α=μ∥α∥2\norm{\mathbf v}^2=\boldsymbol\alpha^\top\tilde K\boldsymbol\alpha=\mu\norm{\boldsymbol\alpha}^2. So if aj\mathbf a_j is a unit eigenvector of K~\tilde K with eigenvalue μj\mu_j, take

  4. zj(x)=∑i=1nαij k~(xi,x),k~(xi,x)=k(xi,x)−1n∑mk(xm,x)−Kˉi⋅+Kˉ⋅⋅z_j(\mathbf x)=\sum_{i=1}^n\alpha_{ij}\,\tilde k(\mathbf x_i,\mathbf x),\qquad\tilde k(\mathbf x_i,\mathbf x)=k(\mathbf x_i,\mathbf x)-\frac1n\sum_mk(\mathbf x_m,\mathbf x)-\bar K_{i\cdot}+\bar K_{\cdot\cdot}

    A new point is projected through kernel values against the training set, centered with the training means, exactly as linear PCA reuses the training mean:

With the linear kernel this is ordinary PCA computed from the n×nn\times n Gram matrix, the cheaper route when d≫nd\gg n. With a Gaussian (RBF) kernel the components are nonlinear in the input and depend strongly on the bandwidth. The price is an n×nn\times n eigenproblem, O(n3)\order{n^3} time and O(n2)\order{n^2} memory, which Nyström and random-feature approximations reduce (Scaling Kernel Methods). Laplacian eigenmaps and LLE can be read as kernel PCA with kernels built from the data (Bengio et al., 2004).

The pre-image problem. The reconstruction φ^(x)=φˉ+∑j≤kzj(x) vj\hat\varphi(\mathbf x)=\bar\varphi+\sum_{j\le k}z_j(\mathbf x)\,\mathbf v_j lives in H\mathcal H and is generally the image of no input. Denoising needs an approximate pre-image z\mathbf z minimizing ∥φ(z)−φ^(x)∥2\norm{\varphi(\mathbf z)-\hat\varphi(\mathbf x)}^2: a fixed-point iteration for Gaussian kernels that can stall in local minima (Mika et al., 1999), a closed-form estimate from distance constraints to nearby training points (Kwok & Tsang, 2004), or an inverse map learned by regression, as scikit-learn's KernelPCA(fit_inverse_transform=True) does with kernel ridge regression.

Robust and sparse PCA, and open problems

PCA's squared loss lets one wild entry wreck the fit. Robust PCA splits a data matrix as M=L0+S0M=L_0+S_0, low rank plus sparse corruptions, by principal component pursuit: minimize ∥L∥∗+λ∥S∥1\norm{L}_*+\lambda\norm{S}_1 subject to L+S=ML+S=M. The nuclear norm ∥L∥∗=∑iσi(L)\norm{L}_*=\sum_i\sigma_i(L) is the convex stand-in for rank, as ∥S∥1=∑ij∣Sij∣\norm{S}_1=\sum_{ij}\abs{S_{ij}} is for the number of nonzeros.

A constant fraction of entries may be corrupted by any amounts, and λ\lambda needs no tuning. Augmented-Lagrangian solvers alternate singular value thresholding (for LL) with soft-thresholding (for SS); in surveillance video LL is the static background and SS the moving foreground. Both assumptions matter: e1e1⊤\mathbf e_1\mathbf e_1^\top is sparse and low rank, and corruptions confined to one column form a rank-one matrix themselves.

Sparse PCA. In a single-spike model the top sample eigenvector is consistent only if d/n→0d/n\to0 (Johnstone & Lu, 2009), as the BBP formula suggests. If the true direction has only ss nonzero entries, maximize u⊤Su\mathbf u^\top S\mathbf u over unit vectors with at most ss nonzeros. That is NP-hard in general, so methods relax it: PCA on the highest-variance coordinates (Johnstone & Lu), lasso-type penalties on the loadings (Zou, Hastie & Tibshirani, 2006), or a semidefinite relaxation (d'Aspremont, El Ghaoui, Jordan & Lanckriet, 2007). A sparse spike is statistically detectable once its strength exceeds about slog⁡d/n\sqrt{s\log d/n}; the semidefinite test needs about s2log⁡d/n\sqrt{s^2\log d/n}, and Berthet & Rigollet (2013) showed that doing better in polynomial time would solve planted clique instances believed to be hard.

Key takeaways

  • Ky Fan: max⁡V⊤V=Iktr⁡(V⊤SV)=λ1+⋯+λk\max_{V^\top V=I_k}\operatorname{tr}(V^\top SV)=\lambda_1+\dots+\lambda_k, so the top-kk eigenvectors maximize captured variance and minimize reconstruction error at once; the subspace is unique exactly when λk>λk+1\lambda_k>\lambda_{k+1}.
  • Probabilistic PCA has a closed-form maximum likelihood: σ2\sigma^2 is the average discarded eigenvalue and W=Uk(Λk−σ2I)1/2RW=U_k(\Lambda_k-\sigma^2I)^{1/2}R. PCA is its zero-noise limit, EM fits it in about ndkndk operations per iteration, and factor analysis frees the noise to a diagonal Ψ\Psi, gaining scale-equivariance.
  • With d/n→γd/n\to\gamma, a spike of strength ℓ\ell separates from the noise only if ℓ>γ\ell>\sqrt\gamma; then λ^1→(1+ℓ)(1+γ/ℓ)\hat\lambda_1\to(1+\ell)(1+\gamma/\ell) and ∣⟨v^,v⟩∣2→(1−γ/ℓ2)/(1+γ/ℓ)\abs{\langle\hat{\mathbf v},\mathbf v\rangle}^2\to(1-\gamma/\ell^2)/(1+\gamma/\ell). Choose kk against the noise edge, with parallel analysis, the Gavish–Donoho threshold, likelihoods or entry-wise cross-validation.
  • Kernel PCA diagonalizes the centered Gram matrix HKHHKH, scales each eigenvector by 1/μj1/\sqrt{\mu_j}, projects new points through training-centered kernel values, and needs approximate pre-images to map back to inputs.
  • Principal component pursuit (∥L∥∗+∥S∥1/n\norm{L}_*+\norm{S}_1/\sqrt n) recovers low rank plus sparse corruption exactly under incoherence and random support; sparse PCA restores consistency when d≳nd\gtrsim n, at an apparent statistical–computational price.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A covariance matrix has eigenvalues 5, 2, 2, 15,\ 2,\ 2,\ 1. Is the best 2-dimensional PCA subspace unique?

  1. Yes: it is span⁡(v1,v2)\operatorname{span}(\mathbf v_1,\mathbf v_2)
  2. No: every plane through the origin captures the same variance
  3. No: any plane spanned by v1\mathbf v_1 and a unit vector of span⁡(v2,v3)\operatorname{span}(\mathbf v_2,\mathbf v_3) captures the maximum, 7
  4. Yes, once the features are standardized
Show the answer

C. No: any plane spanned by v1\mathbf v_1 and a unit vector of span⁡(v2,v3)\operatorname{span}(\mathbf v_2,\mathbf v_3) captures the maximum, 7

Ky Fan's bound is 5+2=75+2=7, attained by any VV with w1=1w_1=1 and its other unit of weight in the tied eigenspace. Uniqueness needs λ2>λ3\lambda_2>\lambda_3, which fails, so "the second principal component" is not determined by the data.

Question 2

In probabilistic PCA with a fixed WW of full column rank, what does the posterior mean E[z∣x]\E[\mathbf z\mid\mathbf x] become as σ2→0\sigma^2\to0?

  1. 0\mathbf 0, because the prior dominates
  2. (W⊤W)−1W⊤(x−μ)(W^\top W)^{-1}W^\top(\mathbf x-\boldsymbol\mu), the coordinates of the orthogonal projection onto span⁡(W)\operatorname{span}(W)
  3. W⊤(x−μ)W^\top(\mathbf x-\boldsymbol\mu) for every WW
  4. It is undefined, because MM becomes singular
Show the answer

B. (W⊤W)−1W⊤(x−μ)(W^\top W)^{-1}W^\top(\mathbf x-\boldsymbol\mu), the coordinates of the orthogonal projection onto span⁡(W)\operatorname{span}(W)

E[z∣x]=M−1W⊤(x−μ)\E[\mathbf z\mid\mathbf x]=M^{-1}W^\top(\mathbf x-\boldsymbol\mu) with M=W⊤W+σ2I→W⊤WM=W^\top W+\sigma^2I\to W^\top W, which is invertible. The limit is the least-squares coordinates of x−μ\mathbf x-\boldsymbol\mu in the columns of WW: PCA's projection, recovered as the noiseless limit of a probability model.

Question 3

In the spiked model with d/n→0.25d/n\to0.25, a single spike has strength ℓ=0.4\ell=0.4. What do the top sample eigenvalue and eigenvector tell you as n→∞n\to\infty?

  1. λ^1→1.4\hat\lambda_1\to1.4, the true variance along v\mathbf v, and v^→v\hat{\mathbf v}\to\mathbf v
  2. λ^1→(1+0.4)(1+0.25/0.4)=2.275\hat\lambda_1\to(1+0.4)(1+0.25/0.4)=2.275, and v^\hat{\mathbf v} is partly aligned with v\mathbf v
  3. λ^1\hat\lambda_1 is inflated above the edge, and ∣⟨v^,v⟩∣2\abs{\langle\hat{\mathbf v},\mathbf v\rangle}^2 tends to about 0.5
  4. λ^1→(1+0.25)2=2.25\hat\lambda_1\to(1+\sqrt{0.25})^2=2.25, the noise edge, and v^\hat{\mathbf v} becomes orthogonal to v\mathbf v: PCA cannot see the spike
Show the answer

D. λ^1→(1+0.25)2=2.25\hat\lambda_1\to(1+\sqrt{0.25})^2=2.25, the noise edge, and v^\hat{\mathbf v} becomes orthogonal to v\mathbf v: PCA cannot see the spike

The threshold is γ=0.5>0.4\sqrt\gamma=0.5>0.4, so no eigenvalue separates from the Marchenko–Pastur bulk, and the top eigenvector carries asymptotically no information about v\mathbf v. Only extra structure, such as sparsity of v\mathbf v, can help.

Question 4

You denoise images with kernel PCA and an RBF kernel: project each noisy image onto the top kk feature-space components. Why do you not simply get a clean image back?

  1. Because the kernel matrix was not centered
  2. Because the projection lies in the feature space and is generally the image of no input; an approximate pre-image must be computed
  3. Because kernel PCA can only be applied to the training images
  4. Because RBF kernel PCA keeps only dd components, too few for images
Show the answer

B. Because the projection lies in the feature space and is generally the image of no input; an approximate pre-image must be computed

The reconstruction φˉ+∑jzjvj\bar\varphi+\sum_jz_j\mathbf v_j is a point of H\mathcal H, and the exact images φ(z)\varphi(\mathbf z) form a curved low-dimensional surface in it that the reconstruction usually misses. Denoising ends with an optimization, or a learned inverse map, that finds an input whose image is closest.

Further reading

  • M. E. Tipping & C. M. Bishop, "Probabilistic principal component analysis," Journal of the Royal Statistical Society B 61(3), 611–622 (1999).
  • J. Baik, G. Ben Arous & S. Péché, "Phase transition of the largest eigenvalue for nonnull complex sample covariance matrices," Annals of Probability 33(5), 1643–1697 (2005).
  • B. Schölkopf, A. Smola & K.-R. Müller, "Nonlinear component analysis as a kernel eigenvalue problem," Neural Computation 10(5), 1299–1319 (1998).
  • E. J. Candès, X. Li, Y. Ma & J. Wright, "Robust principal component analysis?," Journal of the ACM 58(3), article 11 (2011).
  • C. M. Bishop, Pattern Recognition and Machine Learning (Springer, 2006), chapter 12.