7. Dimensionality reduction

Table of contents

  1. Dimensionality Reduction with Principal Component Analysis
  2. Maximum Variance Perspective
  3. Projection Perspective
  4. Eigenvector Computation and Low-Rank Approximations
  5. 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\tilde{x}_n of data points xnx_n that are similar to the original data but possess a significantly lower intrinsic dimensionality. This involves finding an MM-dimensional subspace U⊆RDU \subseteq \mathbb{R}^D (M<DM < D) and a projection matrix B=[b1,…,bM]∈RD×MB = [b_1, \dots, b_M] \in \mathbb{R}^{D \times M}, where the columns of BB are orthonormal.

The projected data x~n=Bzn\tilde{x}_n = B z_n lives in UU, and zn=B⊤xn∈RMz_n = B^\top x_n \in \mathbb{R}^M is the compressed representation (code) 2.

  • Dataset: An i.i.d. dataset X={x1,…,xN}X = \{x_1, \dots, x_N\}, where xn∈RDx_n \in \mathbb{R}^D and has a mean of 0.
  • Data Covariance Matrix: S=1N∑n=1Nxnxn⊤S = \frac{1}{N} \sum_{n=1}^N x_n x_n^\top.
  • Projection Matrix: B=[b1,…,bM]B = [b_1, \dots, b_M], with orthonormal columns bi⊤bj=δijb_i^\top b_j = \delta_{ij}.
  • Projected Data: x~=BB⊤x∈RD\tilde{x} = BB^\top x \in \mathbb{R}^D 2.

📝 Consider a 2D vector x=[5,3]⊤x = [5, 3]^\top. If we use a basis e1=[1,0]⊤e_1 = [1, 0]^\top and e2=[0,1]⊤e_2 = [0, 1]^\top, then x=5e1+3e2x = 5e_1 + 3e_2. If we are interested in vectors of the form x~=[0,z]⊤\tilde{x} = [0, z]^\top, these can be represented by the single coordinate zz with respect to e2e_2. This forms a 1D subspace spanned by e2e_2 3.

1.4 Data Representation and Compression

PCA can be viewed as an auto-encoder with linear mappings. The matrix BB acts as a decoder, mapping the low-dimensional code z∈RMz \in \mathbb{R}^M back to the original data space RD\mathbb{R}^D.

Conversely, B⊤B^\top acts as an encoder, transforming the original data xx into the compressed code zz 3.

  • Encoder: z=B⊤xz = B^\top x.
  • Decoder: x~=Bz\tilde{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\mathbb{R}^{784} 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 BB whose columns span an MM-dimensional subspace that captures the maximum variance of the data when projected. This is achieved by maximizing the variance of the first coordinate z1z_1 of the compressed representation znz_n 5.

  • Variance of Projected Data: V1=1N∑n=1Nz1n2V_1 = \frac{1}{N} \sum_{n=1}^N z_{1n}^2, where z1n=b1⊤xnz_{1n} = b_1^\top x_n.
  • Objective Function: Maximize V1=b1⊤Sb1V_1 = b_1^\top S b_1 subject to ∥b1∥2=1\|b_1\|^2 = 1 5.

2.2 Direction of Maximal Variance

The problem of maximizing b1⊤Sb1b_1^\top S b_1 subject to ∥b1∥2=1\|b_1\|^2 = 1 is a constrained optimization problem. Using a Lagrangian, the solution is found to be the eigenvector of the covariance matrix SS corresponding to the largest eigenvalue.

This eigenvector is the first principal component 6.

  • Lagrangian: L(b1,λ1)=b1⊤Sb1+λ1(1−b1⊤b1)L(b_1, \lambda_1) = b_1^\top S b_1 + \lambda_1(1 - b_1^\top b_1).
  • Eigenvalue Equation: Sb1=λ1b1S b_1 = \lambda_1 b_1.
  • Variance: V1=λ1V_1 = \lambda_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 MM-dimensional subspace that captures maximal variance, we sequentially find the principal components. The mm-th principal component is found by considering the data projected onto the subspace orthogonal to the first m−1m-1 principal components.

This process reveals that the principal components are the eigenvectors of the covariance matrix SS associated with the MM largest eigenvalues 7 8.

  • Transformed Data: X^=X−Bm−1X\hat{X} = X - B_{m-1}X, where Bm−1=∑i=1m−1bibi⊤B_{m-1} = \sum_{i=1}^{m-1} b_i b_i^\top.
  • Variance of m-th Component: Vm=bm⊤S^bmV_m = b_m^\top \hat{S} b_m, where S^\hat{S} is the covariance matrix of X^\hat{X} 7.
  • Result: The mm-th principal component bmb_m is the eigenvector of SS corresponding to the mm-th largest eigenvalue λm\lambda_m 8.
PropertyDescription
Principal ComponentsEigenvectors of the data covariance matrix S.
EigenvaluesAssociated with the principal components; represent the variance captured by each component.
Maximum Variance Captured (M components)VM=∑m=1MλmV_M = \sum_{m=1}^M \lambda_m
Variance LostJM=∑j=M+1Dλj=VD−VMJ_M = \sum_{j=M+1}^D \lambda_j = V_D - V_M

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 MM-dimensional subspace U⊆RDU \subseteq \mathbb{R}^D with an orthonormal basis b1,…,bMb_1, \dots, b_M (the principal subspace) and corresponding coordinates zn∈RMz_n \in \mathbb{R}^M such that the projected data x~n=∑m=1Mzmnbm\tilde{x}_n = \sum_{m=1}^M z_{mn} b_m is as similar as possible to the original data xnx_n. Similarity is measured by minimizing the average squared Euclidean distance (reconstruction error) 10 11.

  • Principal Subspace: U=span[b1,…,bM]U = \text{span}[b_1, \dots, b_M].
  • Reconstruction Error: JM=1N∑n=1N∥xn−x~n∥2J_M = \frac{1}{N} \sum_{n=1}^N \|x_n - \tilde{x}_n\|^2 11.

3.2 Finding Optimal Coordinates

For a given orthonormal basis (b1,…,bM)(b_1, \dots, b_M), the optimal coordinates zmnz_{mn} that minimize the reconstruction error are found by orthogonal projection. This means zmnz_{mn} are the coordinates of the orthogonal projection of xnx_n onto the principal subspace 11 12.

  • Optimal Coordinates: zin=xn⊤bi=bi⊤xnz_{in} = x_n^\top b_i = b_i^\top x_n.
  • Interpretation: The optimal coordinates are the coefficients of the orthogonal projection of xnx_n onto the subspace spanned by bib_i 12.

📝 In Figure 10.8, a vector x∈R2x \in \mathbb{R}^2 is projected onto a 1D subspace spanned by bb. The optimal projection x~\tilde{x} is found by scaling bb with the coordinate z1=x⊤bz_1 = x^\top b. This x~\tilde{x} is the orthogonal projection of xx onto the line spanned by bb 12.

3.3 Finding the Basis of the Principal Subspace 15

Minimizing the reconstruction error JMJ_M leads to finding the basis vectors b1,…,bMb_1, \dots, b_M of the principal subspace. The displacement vector xn−x~nx_n - \tilde{x}_n lies in the orthogonal complement of the principal subspace 13 14.

  • Displacement Vector: xn−x~n=∑j=M+1D(bj⊤xn)bjx_n - \tilde{x}_n = \sum_{j=M+1}^D (b_j^\top x_n) b_j.
  • Projection Matrix: The projection onto the principal subspace is BB⊤=∑m=1Mbmbm⊤BB^\top = \sum_{m=1}^M b_m b_m^\top 14.
ObjectiveEquivalent Formulation
Minimize average squared reconstruction error JMJ_MMaximize variance captured by the principal subspace VMV_M
Minimize projection of covariance matrix onto orthogonal complementMaximize projection of covariance matrix onto principal subspace

The minimization of the average squared reconstruction error JM=∑j=M+1DλjJ_M = \sum_{j=M+1}^D \lambda_j requires selecting the D−MD-M smallest eigenvalues. Consequently, the basis of the principal subspace consists of the eigenvectors b1,…,bMb_1, \dots, b_M corresponding to the MM largest eigenvalues of the data covariance matrix SS 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=1N∑n=1Nxnxn⊤S = \frac{1}{N} \sum_{n=1}^{N} x_n x_n^\top. Two primary approaches exist for computing these eigenvectors and eigenvalues:

  • Eigendecomposition: Directly compute the eigenvalues and eigenvectors of the covariance matrix SS.
  • Singular Value Decomposition (SVD): Utilize the SVD of the data matrix X=[x1,…,xN]∈RD×NX = [x_1, \dots, x_N] \in \mathbb{R}^{D \times N}. The eigenvalues of SS are the squared singular values of XX, and the columns of UU from the SVD of X=UΣV⊤X = U \Sigma V^\top are the eigenvectors of SS. Specifically, λd=σd2/N\lambda_d = \sigma_d^2 / N 17.

4.2 PCA using low-rank matrix approximations

PCA selects the MM eigenvectors corresponding to the largest eigenvalues of SS to form the projection matrix BB. This matrix projects data onto a lower-dimensional MM-dimensional subspace, maximizing variance and minimizing reconstruction error.

The Eckart-Young theorem provides the best rank-MM approximation of XX as XM=UMΣMVM⊤X_M = U_M \Sigma_M V_M^\top, where UMU_M contains the MM principal eigenvectors and ΣM\Sigma_M contains the MM largest singular values 18.

📝 The Eckart-Young theorem states that the best rank-MM approximation of XX is XM=UMΣMVM⊤X_M = U_M \Sigma_M V_M^\top, where UMU_M contains the MM principal eigenvectors and ΣM\Sigma_M contains the MM 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 SS, starting with a random vector x0x_0 not in its null space, the iteration xk+1=Sxk∥Sxk∥x_{k+1} = \frac{S x_k}{\|S x_k\|} converges to the eigenvector corresponding to the largest eigenvalue of SS 19.

4.4 PCA in high dimensions

When the data dimensionality DD is much larger than the number of data points NN (N≪DN \ll D), computing the D×DD \times D covariance matrix SS is computationally prohibitive. In this scenario, PCA can be performed more efficiently by considering the N×NN \times N matrix X⊤XX^\top X.

The non-zero eigenvalues of SS are identical to those of X⊤XX^\top X. The eigenvectors cmc_m of X⊤XX^\top X can be used to recover the eigenvectors bmb_m of SS via bm=1λmXcmb_m = \frac{1}{\lambda_m} X c_m 19 20.

4.5 Key steps of PCA in practice

PCA involves several sequential steps:

  1. Mean subtraction: Center the data by subtracting the mean μ\mu from each data point to ensure a mean of 0.
  2. Standardization: Divide each data point by the standard deviation σd\sigma_d for each dimension dd to make the data unit-free and give it unit variance along each axis.
  3. 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 UU.
  4. Projection: Project data points onto the principal subspace. For a new data point x∗x^\ast, standardize it using the training data's mean and standard deviation, then compute the projection z∗=B⊤x∗z^\ast = B^\top x^\ast. 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, 1N∑i=M+1λi\frac{1}{N} \sum_{i=M+1}^{\lambda_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∈RMz \in \mathbb{R}^M with a standard-normal prior p(z)=N(0,I)p(z) = \mathcal{N}(0, I).

The observed data xx is modeled as a linear transformation of zz plus Gaussian noise: x=Bz+μ+ϵx = Bz + \mu + \epsilon, where ϵ∼N(0,σ2I)\epsilon \sim \mathcal{N}(0, \sigma^2 I), B∈RD×MB \in \mathbb{R}^{D \times M} is the linear mapping, and μ∈RD\mu \in \mathbb{R}^D is the mean offset 24.

The generative process involves sampling z∼N(0,I)z \sim \mathcal{N}(0, I) and then x∼N(x∣Bz+μ,σ2I)x \sim \mathcal{N}(x | Bz + \mu, \sigma^2 I). The joint distribution is p(x,z∣B,μ,σ2)=p(x∣z,B,μ,σ2)p(z)p(x, z | B, \mu, \sigma^2) = p(x | z, B, \mu, \sigma^2) p(z) 24 25.

  • Generating New Data with Latent Variables: In PPCA, latent variables zz can generate new data x~=Bzx̃ = Bz. By sampling zz from the latent space, new images resembling the training data can be created. The realism of the generated image depends on the proximity of zz to the training data's latent representation 25.

5.2 Likelihood and joint distribution in PPCA

The marginal likelihood p(x∣B,μ,σ2)p(x | B, \mu, \sigma^2) is obtained by integrating out the latent variable zz. This results in a Gaussian distribution for xx with mean μ\mu and covariance matrix BB⊤+σ2IBB^\top + \sigma^2 I.

This likelihood is used for maximum likelihood estimation of model parameters. The joint distribution p(x,z∣B,μ,σ2)p(x, z | B, \mu, \sigma^2) is a multivariate Gaussian with mean [μ;0][\mu; 0] and a block covariance matrix 26.

DistributionParameters
Marginal p(z)p(z)N(0,I)\mathcal{N}(0, I)
Marginal p(x)p(x)$\mathcal{N}(x
Joint p(x,z)p(x, z)$\mathcal{N}(\begin{bmatrix} x \ z \end{bmatrix}

📝 The marginal likelihood p(x∣B,μ,σ2)p(x | B, \mu, \sigma^2) is a Gaussian distribution with mean μ\mu and covariance matrix BB⊤+σ2IBB^\top + \sigma^2 I.

5.3 Posterior distribution in PPCA

The posterior distribution p(z∣x)p(z | x) is also Gaussian, determined by the joint distribution. The posterior mean mm and covariance CC are given by:

m=B⊤(BB⊤+σ2I)−1(x−μ)m = B^\top(BB^\top + \sigma^2 I)^{-1}(x - \mu) C=I−B⊤(BB⊤+σ2I)−1BC = I - B^\top(BB^\top + \sigma^2 I)^{-1}B

The posterior covariance CC is independent of the observed data xx and indicates the certainty of the latent embedding. Exploring the posterior involves sampling z∗∼p(z∣x∗)z^\ast \sim p(z | x^\ast) and then sampling x~∗∼p(x∣z∗,B,μ,σ2)x̃^\ast \sim p(x | z^\ast, B, \mu, \sigma^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=1N∑n=1Nxn\mu_{ML} = \frac{1}{N} \sum_{n=1}^{N} x_n BML=T(Λ−σ2I)1/2RB_{ML} = T (\Lambda - \sigma^2 I)^{1/2} R σML2=1D−M∑j=M+1λj\sigma^2_{ML} = \frac{1}{D-M} \sum_{j=M+1}^{\lambda_j}

where TT contains eigenvectors of the covariance matrix, Λ\Lambda is a diagonal matrix of corresponding eigenvalues, and RR is an arbitrary orthogonal matrix. In the noise-free limit (σ→0\sigma \to 0), PPCA converges to PCA 29.

Several extensions and related models exist:

  • Factor Analysis (FA): Generalizes PPCA by allowing different noise variances (σd2\sigma_d^2) 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.

See also