7. Dimensionality reduction
Table of contents
- Dimensionality Reduction with Principal Component Analysis
- Maximum Variance Perspective
- Projection Perspective
- Eigenvector Computation and Low-Rank Approximations
- Latent Variable Perspective
1. Dimensionality Reduction with Principal Component Analysis
High-dimensional data, such as images, presents challenges in analysis, interpretation, and storage due to its complexity and potential redundancy. Dimensionality reduction techniques, like Principal Component Analysis (PCA), aim to create more compact data representations by exploiting inherent structures and correlations, ideally without significant information loss.
PCA, a linear dimensionality reduction algorithm, is widely used for data compression, visualization, and pattern identification 1.
1.1 Challenges of High-Dimensional Data
High-dimensional data often exhibits overcompleteness, meaning many dimensions are redundant and can be explained by a combination of others. Dimensions are frequently correlated, suggesting an intrinsic lower-dimensional structure 1.
- Analysis Difficulty: Interpreting and analyzing data with many features is complex.
- Visualization Impossibility: Visualizing data in spaces with more than three dimensions is not feasible.
- Storage Costs: Storing high-dimensional data vectors can be computationally expensive.
1.2 Principal Component Analysis (PCA)
PCA, proposed by Pearson and Hotelling is a foundational algorithm for linear dimensionality reduction. It is also known as the Karhunen-Loève transform in signal processing.
PCA seeks to find a lower-dimensional representation of data that is as similar as possible to the original data, thereby minimizing information loss 1 2 .
- Core Idea: PCA identifies a lower-dimensional subspace onto which data can be projected with minimal loss of information.
- Applications: Data compression, data visualization, pattern identification, and latent factor discovery.
1.3 Problem Setting in PCA
The goal of PCA is to find projections x~n of data points xn that are similar to the original data but possess a significantly lower intrinsic dimensionality. This involves finding an M-dimensional subspace U⊆RD (M<D) and a projection matrix B=[b1,…,bM]∈RD×M, where the columns of B are orthonormal.
The projected data x~n=Bzn lives in U, and zn=B⊤xn∈RM is the compressed representation (code) 2.
- Dataset: An i.i.d. dataset X={x1,…,xN}, where xn∈RD and has a mean of 0.
- Data Covariance Matrix: S=N1∑n=1Nxnxn⊤.
- Projection Matrix: B=[b1,…,bM], with orthonormal columns bi⊤bj=δij.
- Projected Data: x~=BB⊤x∈RD 2.
📝 Consider a 2D vector x=[5,3]⊤. If we use a basis e1=[1,0]⊤ and e2=[0,1]⊤, then x=5e1+3e2. If we are interested in vectors of the form x~=[0,z]⊤, these can be represented by the single coordinate z with respect to e2. This forms a 1D subspace spanned by e2 3.
1.4 Data Representation and Compression
PCA can be viewed as an auto-encoder with linear mappings. The matrix B acts as a decoder, mapping the low-dimensional code z∈RM back to the original data space RD.
Conversely, B⊤ acts as an encoder, transforming the original data x into the compressed code z 3.
- Encoder: z=B⊤x.
- Decoder: x~=Bz.
1.5 MNIST Dataset Example
The MNIST dataset, comprising 60,000 handwritten digit images (28x28 pixels), serves as a common example. Each image can be represented as a vector in R784 4.
2. Maximum Variance Perspective
PCA can be derived by maximizing the variance of the low-dimensional representation of the data. This approach assumes that capturing the most variance in the projected data corresponds to retaining the most information.
The principal components are identified as the eigenvectors of the data covariance matrix associated with the largest eigenvalues 4 5.
2.1 Maximizing Variance in Projected Data
The objective is to find a matrix B whose columns span an M-dimensional subspace that captures the maximum variance of the data when projected. This is achieved by maximizing the variance of the first coordinate z1 of the compressed representation zn 5.
- Variance of Projected Data: V1=N1∑n=1Nz1n2, where z1n=b1⊤xn.
- Objective Function: Maximize V1=b1⊤Sb1 subject to ∥b1∥2=1 5.
2.2 Direction of Maximal Variance
The problem of maximizing b1⊤Sb1 subject to ∥b1∥2=1 is a constrained optimization problem. Using a Lagrangian, the solution is found to be the eigenvector of the covariance matrix S corresponding to the largest eigenvalue.
This eigenvector is the first principal component 6.
- Lagrangian: L(b1,λ1)=b1⊤Sb1+λ1(1−b1⊤b1).
- Eigenvalue Equation: Sb1=λ1b1.
- Variance: V1=λ1 6.
📝 For the MNIST "8" dataset, the eigenvalues of the covariance matrix are computed. Figure 10.5(a) shows the largest eigenvalues, indicating that only a few principal components capture most of the variance. Figure 10.5(b) illustrates the cumulative variance captured by an increasing number of principal components 8.
2.3 M-dimensional Subspace with Maximal Variance 9
To find an M-dimensional subspace that captures maximal variance, we sequentially find the principal components. The m-th principal component is found by considering the data projected onto the subspace orthogonal to the first m−1 principal components.
This process reveals that the principal components are the eigenvectors of the covariance matrix S associated with the M largest eigenvalues 7 8.
- Transformed Data: X^=X−Bm−1X, where Bm−1=∑i=1m−1bibi⊤.
- Variance of m-th Component: Vm=bm⊤S^bm, where S^ is the covariance matrix of X^ 7.
- Result: The m-th principal component bm is the eigenvector of S corresponding to the m-th largest eigenvalue λm 8.
| Property | Description |
|---|---|
| Principal Components | Eigenvectors of the data covariance matrix S. |
| Eigenvalues | Associated with the principal components; represent the variance captured by each component. |
| Maximum Variance Captured (M components) | VM=∑m=1Mλm |
| Variance Lost | JM=∑j=M+1Dλj=VD−VM |
3. Projection Perspective
PCA can also be derived by minimizing the average squared reconstruction error. This perspective frames PCA as finding an optimal linear projection onto a lower-dimensional subspace, such that the reconstructed data is as close as possible to the original data.
This approach highlights PCA's role as an optimal linear auto-encoder 9 10.
3.1 Setting and Objective
The objective is to find an M-dimensional subspace U⊆RD with an orthonormal basis b1,…,bM (the principal subspace) and corresponding coordinates zn∈RM such that the projected data x~n=∑m=1Mzmnbm is as similar as possible to the original data xn. Similarity is measured by minimizing the average squared Euclidean distance (reconstruction error) 10 11.
- Principal Subspace: U=span[b1,…,bM].
- Reconstruction Error: JM=N1∑n=1N∥xn−x~n∥2 11.
3.2 Finding Optimal Coordinates
For a given orthonormal basis (b1,…,bM), the optimal coordinates zmn that minimize the reconstruction error are found by orthogonal projection. This means zmn are the coordinates of the orthogonal projection of xn onto the principal subspace 11 12.
- Optimal Coordinates: zin=xn⊤bi=bi⊤xn.
- Interpretation: The optimal coordinates are the coefficients of the orthogonal projection of xn onto the subspace spanned by bi 12.
📝 In Figure 10.8, a vector x∈R2 is projected onto a 1D subspace spanned by b. The optimal projection x~ is found by scaling b with the coordinate z1=x⊤b. This x~ is the orthogonal projection of x onto the line spanned by b 12.
3.3 Finding the Basis of the Principal Subspace 15
Minimizing the reconstruction error JM leads to finding the basis vectors b1,…,bM of the principal subspace. The displacement vector xn−x~n lies in the orthogonal complement of the principal subspace 13 14.
- Displacement Vector: xn−x~n=∑j=M+1D(bj⊤xn)bj.
- Projection Matrix: The projection onto the principal subspace is BB⊤=∑m=1Mbmbm⊤ 14.
| Objective | Equivalent Formulation |
|---|---|
| Minimize average squared reconstruction error JM | Maximize variance captured by the principal subspace VM |
| Minimize projection of covariance matrix onto orthogonal complement | Maximize projection of covariance matrix onto principal subspace |
The minimization of the average squared reconstruction error JM=∑j=M+1Dλj requires selecting the D−M smallest eigenvalues. Consequently, the basis of the principal subspace consists of the eigenvectors b1,…,bM corresponding to the M largest eigenvalues of the data covariance matrix S 16.
📝 Figure 10.10 shows an embedding of MNIST digits "0" (blue) and "1" (orange) into a 2D principal subspace using PCA. The visualization reveals a clear separation between the two digit classes, demonstrating PCA's effectiveness in dimensionality reduction for visualization and pattern discovery 16.
4. Eigenvector Computation and Low-Rank Approximations
4.1 Eigenvector computation approaches
The principal subspace basis is derived from eigenvectors associated with the largest eigenvalues of the data covariance matrix S=N1∑n=1Nxnxn⊤. Two primary approaches exist for computing these eigenvectors and eigenvalues:
- Eigendecomposition: Directly compute the eigenvalues and eigenvectors of the covariance matrix S.
- Singular Value Decomposition (SVD): Utilize the SVD of the data matrix X=[x1,…,xN]∈RD×N. The eigenvalues of S are the squared singular values of X, and the columns of U from the SVD of X=UΣV⊤ are the eigenvectors of S. Specifically, λd=σd2/N 17.
4.2 PCA using low-rank matrix approximations
PCA selects the M eigenvectors corresponding to the largest eigenvalues of S to form the projection matrix B. This matrix projects data onto a lower-dimensional M-dimensional subspace, maximizing variance and minimizing reconstruction error.
The Eckart-Young theorem provides the best rank-M approximation of X as XM=UMΣMVM⊤, where UM contains the M principal eigenvectors and ΣM contains the M largest singular values 18.
📝 The Eckart-Young theorem states that the best rank-M approximation of X is XM=UMΣMVM⊤, where UM contains the M principal eigenvectors and ΣM contains the M largest singular values 18.
4.3 Practical aspects of eigenvector computation
Directly solving for eigenvalues via the characteristic polynomial is infeasible for matrices larger than 4x4 due to the Abel-Ruffini theorem. Practical computation relies on iterative methods implemented in linear algebra packages.
For applications requiring only a few eigenvectors, iterative methods that directly optimize these eigenvectors are more computationally efficient than full eigendecomposition or SVD. The power iteration method is particularly efficient for finding the single eigenvector associated with the largest eigenvalue 18.
- Power Iteration: For a matrix S, starting with a random vector x0 not in its null space, the iteration xk+1=∥Sxk∥Sxk converges to the eigenvector corresponding to the largest eigenvalue of S 19.
4.4 PCA in high dimensions
When the data dimensionality D is much larger than the number of data points N (N≪D), computing the D×D covariance matrix S is computationally prohibitive. In this scenario, PCA can be performed more efficiently by considering the N×N matrix X⊤X.
The non-zero eigenvalues of S are identical to those of X⊤X. The eigenvectors cm of X⊤X can be used to recover the eigenvectors bm of S via bm=λm1Xcm 19 20.
4.5 Key steps of PCA in practice
PCA involves several sequential steps:
- Mean subtraction: Center the data by subtracting the mean μ from each data point to ensure a mean of 0.
- Standardization: Divide each data point by the standard deviation σd for each dimension d to make the data unit-free and give it unit variance along each axis.
- Eigendecomposition of the covariance matrix: Compute the covariance matrix and its eigenvalues and eigenvectors. The eigenvectors associated with the largest eigenvalues form the basis of the principal subspace U.
- Projection: Project data points onto the principal subspace. For a new data point x∗, standardize it using the training data's mean and standard deviation, then compute the projection z∗=B⊤x∗. To map back to the original data space, undo standardization.
- MNIST Digits Reconstruction: Applying PCA to MNIST digits shows that increasing the number of principal components (PCs) leads to sharper reconstructions. With 500 PCs, the reconstruction is nearly perfect, while with only one PC, the reconstruction is blurry but captures basic shape 22.
The average squared reconstruction error is the sum of eigenvalues in the orthogonal complement of the principal subspace, N1∑i=M+1λi, indicating that the importance of principal components drops rapidly 23.
5. Latent Variable Perspective
5.1 Probabilistic PCA (PPCA)
PPCA frames PCA as a probabilistic latent-variable model, offering greater flexibility and insights compared to non-probabilistic derivations. It introduces a continuous latent variable z∈RM with a standard-normal prior p(z)=N(0,I).
The observed data x is modeled as a linear transformation of z plus Gaussian noise: x=Bz+μ+ϵ, where ϵ∼N(0,σ2I), B∈RD×M is the linear mapping, and μ∈RD is the mean offset 24.
The generative process involves sampling z∼N(0,I) and then x∼N(x∣Bz+μ,σ2I). The joint distribution is p(x,z∣B,μ,σ2)=p(x∣z,B,μ,σ2)p(z) 24 25.
- Generating New Data with Latent Variables: In PPCA, latent variables z can generate new data x~=Bz. By sampling z from the latent space, new images resembling the training data can be created. The realism of the generated image depends on the proximity of z to the training data's latent representation 25.
5.2 Likelihood and joint distribution in PPCA
The marginal likelihood p(x∣B,μ,σ2) is obtained by integrating out the latent variable z. This results in a Gaussian distribution for x with mean μ and covariance matrix BB⊤+σ2I.
This likelihood is used for maximum likelihood estimation of model parameters. The joint distribution p(x,z∣B,μ,σ2) is a multivariate Gaussian with mean [μ;0] and a block covariance matrix 26.
| Distribution | Parameters |
|---|---|
| Marginal p(z) | N(0,I) |
| Marginal p(x) | $\mathcal{N}(x |
| Joint p(x,z) | $\mathcal{N}(\begin{bmatrix} x \ z \end{bmatrix} |
📝 The marginal likelihood p(x∣B,μ,σ2) is a Gaussian distribution with mean μ and covariance matrix BB⊤+σ2I.
5.3 Posterior distribution in PPCA
The posterior distribution p(z∣x) is also Gaussian, determined by the joint distribution. The posterior mean m and covariance C are given by:
m=B⊤(BB⊤+σ2I)−1(x−μ) C=I−B⊤(BB⊤+σ2I)−1B
The posterior covariance C is independent of the observed data x and indicates the certainty of the latent embedding. Exploring the posterior involves sampling z∗∼p(z∣x∗) and then sampling x~∗∼p(x∣z∗,B,μ,σ2) to generate plausible data points 27.
5.4 Further reading and related models
PCA can be viewed as a linear auto-encoder, where an encoder maps data to a lower-dimensional code and a decoder reconstructs it. Nonlinear auto-encoders, including deep auto-encoders, extend this by using neural networks for nonlinear mappings 28.
PCA is also related to information theory, where the code can be seen as a compressed version of the data, and maximizing mutual information leads to the PCA solution.
Maximum likelihood estimates for PPCA parameters are: μML=N1∑n=1Nxn BML=T(Λ−σ2I)1/2R σML2=D−M1∑j=M+1λj
where T contains eigenvectors of the covariance matrix, Λ is a diagonal matrix of corresponding eigenvalues, and R is an arbitrary orthogonal matrix. In the noise-free limit (σ→0), PPCA converges to PCA 29.
Several extensions and related models exist:
- Factor Analysis (FA): Generalizes PPCA by allowing different noise variances (σd2) for each observation dimension. It requires iterative estimation methods like EM.
- Independent Component Analysis (ICA): Modifies the prior on latent variables to be non-Gaussian, enabling blind-source separation. PCA finds the best subspace, while ICA aims to find independent sources within that subspace
- Kernel PCA: Extends PCA to nonlinear dimensionality reduction by implicitly computing inner products in infinite-dimensional feature spaces using the kernel trick.
- Gaussian Process Latent Variable Model (GP-LVM): Replaces the linear mapping in PPCA with a Gaussian process, marginalizing out model parameters and making point estimates of latent variables 31.
- Bayesian PCA: Places prior distributions on model parameters and integrates them out to avoid point estimates and enable automatic dimensionality selection 30.
© 2026 Maeve. All rights reserved. This content is protected by copyright.