Dimensionality Reduction Algorithms
Discover and understand AI algorithms at Programming Ocean Academy with clear explanations, equations, and illustrations for better learning.
AI Algorithms Explainer
Principal Component Analysis (PCA)
$$ Z = XW, \quad \text{where } W = \text{eigenvectors of } \Sigma = \frac{1}{n}X^TX $$
- $X$: Mean-centered data matrix (samples × features).
- $\Sigma$: Covariance matrix of $X$.
- $W$: Matrix of top $k$ eigenvectors (principal components).
- $Z$: Transformed data in reduced dimensions.
- Variance Preservation: PCA selects axes that capture the most variance in the data.
- Use Case: Data visualization, noise reduction, preprocessing for machine learning models.
Singular Value Decomposition (SVD)
$$ X = U \Sigma V^T $$
- $X$: Original data matrix (samples × features).
- $U$: Left singular vectors (orthonormal columns).
- $\Sigma$: Diagonal matrix of singular values (importance of each component).
- $V^T$: Right singular vectors (principal directions).
- Relation to PCA: PCA is performed via SVD on the mean-centered data matrix.
- Use Case: Dimensionality reduction, latent semantic analysis, image compression.
Linear Discriminant Analysis (LDA)
$$ W = \arg\max_W \frac{|W^T S_B W|}{|W^T S_W W|} $$
- $W$: Projection matrix for the lower-dimensional space.
- $S_B$: Between-class scatter matrix (distance between class means).
- $S_W$: Within-class scatter matrix (spread within each class).
- Optimization Goal: Maximize between-class variance while minimizing within-class variance.
- Supervised: LDA uses class labels, unlike PCA which is unsupervised.
- Use Case: Pattern recognition, face recognition, bioinformatics classification problems.
Independent Component Analysis (ICA)
$$ X = AS, \quad \text{or} \quad S = WX $$
- $X$: Observed data matrix (mixture of signals).
- $S$: Source signals (assumed to be statistically independent).
- $A$: Mixing matrix; $W = A^{-1}$ is the unmixing matrix.
- Independence: ICA maximizes statistical independence between the components.
- Contrast with PCA: PCA decorrelates variables, ICA finds truly independent components.
- Use Case: Blind source separation, EEG signal processing, financial signal decomposition.
Non-negative Matrix Factorization (NMF)
$$ X \approx WH $$
- $X$: Original non-negative data matrix (e.g., documents × terms, images).
- $W$: Basis matrix (non-negative), represents additive components.
- $H$: Coefficient matrix (non-negative), encodes how components are combined.
- Interpretability: Components in $W$ and $H$ are often interpretable as parts-based representations.
- Contrast with PCA: PCA allows negative values and uses orthogonality; NMF enforces non-negativity, yielding more interpretable results.
- Use Case: Document clustering, image decomposition, bioinformatics (e.g., gene expression data).
Sparse PCA / Robust PCA
$$ X \approx LD, \quad \text{with sparsity or robustness constraints} $$
- Sparse PCA: Enhances interpretability by enforcing sparsity in loading vectors (many elements zero).
- Robust PCA: Decomposes data as $X = L + S$ where $L$ is low-rank (structure), $S$ is sparse (outliers).
- $L$: Captures the principal low-rank structure of the data.
- $S$: Isolates anomalies or noise, useful for denoising and anomaly detection.
- Contrast with standard PCA: Standard PCA is sensitive to outliers and dense; variants adapt to real-world data issues.
- Use Case: Image background separation, fault detection in sensors, bioinformatics with sparse features.
Kernel PCA (KPCA)
$$ \Phi(X) \rightarrow \text{PCA in feature space} $$
- $X$: Original data matrix.
- $\Phi(X)$: Nonlinear mapping of data into a high-dimensional feature space using a kernel function.
- Kernel Trick: Avoids explicit mapping by using kernel functions (e.g., RBF, polynomial) to compute inner products.
- Captures Nonlinearity: Enables PCA to uncover nonlinear structures in data.
- Contrast with PCA: PCA only captures linear structure; KPCA generalizes it using kernel methods.
- Use Case: Nonlinear dimensionality reduction, face recognition, denoising, pattern recognition.
Isomap
$$ \text{Geodesic Distances} \rightarrow \text{MDS Embedding} $$
- Goal: Capture the intrinsic geometry of nonlinear manifolds.
- Step 1: Construct neighborhood graph based on k-nearest neighbors or $\epsilon$-radius.
- Step 2: Compute shortest (geodesic) paths on the graph using algorithms like Dijkstra's.
- Step 3: Apply Multidimensional Scaling (MDS) to the geodesic distance matrix to embed in lower dimensions.
- Preserves: Global geometry and manifold structure better than linear methods.
- Use Case: Unfolding manifolds like the Swiss roll, visualizing high-dimensional nonlinear data.
Locally Linear Embedding (LLE)
$$ X_i \approx \sum_j W_{ij} X_j, \quad Y_i = \sum_j W_{ij} Y_j $$
- $X_i$: High-dimensional data point.
- $W_{ij}$: Weights that best reconstruct $X_i$ from its neighbors.
- $Y_i$: Low-dimensional embedding preserving the same weights.
- Preserves: Local linear structure by keeping neighborhood relationships intact.
- Contrast with Isomap: Isomap preserves global distances; LLE focuses on local neighborhood geometry.
- Use Case: Visualizing manifolds, understanding local structures in high-dimensional data.
Hessian Locally Linear Embedding (Hessian LLE)
$$ \text{Minimize } \sum_i \| \mathcal{H}(Y_i) \|^2 $$
- $\mathcal{H}(Y_i)$: Hessian operator applied to the local embedding around point $i$.
- Goal: Preserve local isometry and curvature, improving over standard LLE on curved manifolds.
- Method: Incorporates second-order (Hessian) information of local neighborhoods for smoother embeddings.
- Preserves: Local geometric structure including curvature, better for complex manifolds.
- Contrast with LLE: LLE preserves linear relationships; Hessian LLE adds sensitivity to curvature.
- Use Case: Advanced manifold learning, scientific data visualization where curvature matters.
Laplacian Eigenmaps / Spectral Embedding
$$ \min_Y \sum_{i,j} \|Y_i - Y_j\|^2 W_{ij}, \quad \text{subject to } Y^T D Y = I $$
- $W_{ij}$: Weight matrix encoding similarity between neighbors.
- $D$: Diagonal degree matrix; $D_{ii} = \sum_j W_{ij}$.
- Graph Laplacian: $L = D - W$, used to capture local connectivity.
- Goal: Embed data to preserve local neighborhood similarity in a lower-dimensional space.
- Contrast with LLE: Both preserve locality, but Laplacian Eigenmaps optimize a global cost on local similarities.
- Use Case: Semi-supervised learning, clustering, graph-based representations of data.
t-Distributed Stochastic Neighbor Embedding (t-SNE)
$$ \text{Minimize } KL(P \| Q), \quad P_{ij} \sim \text{Gaussian}, \quad Q_{ij} \sim \text{t-distribution} $$
- $P_{ij}$: Probability of similarity in high-dimensional space using Gaussian kernel.
- $Q_{ij}$: Similarity in low-dimensional space using Student t-distribution (heavy tails).
- KL Divergence: Measures the difference between $P$ and $Q$ to preserve local structure.
- Emphasizes: Local relationships and clusters while spreading out dissimilar groups.
- Contrast with PCA: PCA is linear and global; t-SNE is nonlinear and focuses on local clustering.
- Use Case: Visualizing high-dimensional data in 2D or 3D (e.g., word embeddings, gene expression).
UMAP (Uniform Manifold Approximation and Projection)
$$ \text{Minimize } \mathcal{C}(P, Q), \quad P, Q \text{ are fuzzy simplicial sets} $$
- P: Fuzzy topological representation of high-dimensional data using local connectivity.
- Q: Low-dimensional equivalent fuzzy set preserving both local and global structures.
- Optimization: Minimizes cross-entropy between P and Q distributions.
- Preserves: Both local neighborhood continuity and global data structure better than t-SNE.
- Contrast with t-SNE: t-SNE is good for local clusters but distorts global layout; UMAP is faster and preserves more structure.
- Use Case: Large-scale embedding for visualization, clustering, and preprocessing before classification.
Maximum Variance Unfolding (MVU)
$$ \max_Y \text{Tr}(Y^T Y), \quad \text{subject to } \|Y_i - Y_j\|^2 = \|X_i - X_j\|^2 \text{ for neighbors} $$
- Y: Low-dimensional embedding of data points.
- Objective: Maximize pairwise distances (variance) in the embedding space.
- Constraint: Preserve original distances between nearest neighbors from high-dimensional space.
- Method: Solves a semidefinite programming problem to unfold the manifold.
- Preserves: Local geometry and attempts to spread data as much as possible globally.
- Use Case: Manifold learning, especially when interested in visualizing the intrinsic dimensionality.
Gaussian Process Latent Variable Models (GPLVM)
$$ X = f(Y) + \epsilon, \quad f \sim \mathcal{GP}(0, k(\cdot, \cdot)) $$
- X: Observed high-dimensional data.
- Y: Latent low-dimensional variables to be learned.
- f: Nonlinear mapping from latent to observed space, drawn from a Gaussian Process.
- Bayesian Nature: Places a prior over functions using Gaussian processes, allowing uncertainty quantification.
- Preserves: Probabilistic structure and nonlinear dependencies without requiring an explicit mapping.
- Use Case: Generative modeling, pose estimation, bioinformatics, and high-dimensional time series modeling.
Autoencoders (Deep / Variational / Sparse, etc.)
$$ X \xrightarrow{\text{Encoder}} Z \xrightarrow{\text{Decoder}} \hat{X}, \quad \text{minimize } \|X - \hat{X}\|^2 $$
- X: Original input data.
- Z: Latent (compressed) representation learned by the encoder.
- hat{X}: Reconstructed data output by the decoder.
- Deep Autoencoders: Use multiple nonlinear layers to capture complex structure.
- Variational Autoencoders (VAE): Introduce probabilistic latent variables and regularize using KL divergence.
- Sparse Autoencoders: Encourage sparsity in Z to improve feature learning and interpretability.
- Use Case: Denoising, anomaly detection, dimensionality reduction, and generative modeling.
Variational Autoencoders (VAEs)
$$ \mathcal{L} = \mathbb{E}_{q(z|x)}[\log p(x|z)] - KL[q(z|x) \| p(z)] $$
- x: Observed input data.
- z: Latent variable sampled from a learned distribution.
- q(z|x): Encoder outputs a distribution (typically Gaussian) over latent variables.
- p(x|z): Decoder reconstructs the input from the latent space.
- KL divergence: Regularizes the latent space by making q(z|x) close to a prior p(z).
- Uncertainty: Provides probabilistic interpretation and uncertainty estimates for generated samples.
- Use Case: Generative modeling, synthetic data creation, and tasks requiring latent distributions with structure.
Low Variance Filter
$$ \text{Drop feature } j \text{ if } \text{Var}(X_j) < \theta $$
- X_j: Feature column j in the dataset.
- Var(X_j): Variance of the feature across all samples.
- theta: User-defined threshold; features with variance below this are removed.
- Purpose: Eliminate features that carry little to no information.
- Impact: Reduces dimensionality and computational cost, especially for high-dimensional data.
- Use Case: Preprocessing step in pipelines for text data, image pixels, and bioinformatics.
High Correlation Filter
$$ \text{Drop } X_j \text{ if } |\text{Corr}(X_i, X_j)| > \theta $$
- X_i, X_j: Pair of feature columns.
- Corr(X_i, X_j): Correlation coefficient between features i and j.
- theta: Correlation threshold, commonly set between 0.7 and 0.95.
- Purpose: Removes redundancy and multicollinearity among features.
- Selection: One of the correlated features is typically retained based on domain knowledge or relevance.
- Use Case: Structured datasets in regression, classification, and when interpretability is important.
Missing Value Ratio Filter
$$ \text{Drop feature } j \text{ if } \frac{\text{Missing}_j}{\text{Total}_j} > \theta $$
- Missing_j: Number of missing entries in feature j.
- Total_j: Total number of entries in feature j.
- theta: User-defined threshold, often set around 0.2 to 0.5.
- Purpose: Remove features with too many missing values that may affect model reliability.
- Alternative: Imputation methods can be considered if the feature is important but partially missing.
- Use Case: Data preprocessing in tabular datasets from surveys, clinical trials, and sensor data.
Forward / Backward Feature Selection / Elimination
$$ \text{Search: } \arg\max_{S \subseteq F} \text{Score(Model(S))} $$
- F: Full set of features.
- S: Subset of selected features.
- Forward Selection: Starts with no features, adds one at a time that improves model performance the most.
- Backward Elimination: Starts with all features, removes one at a time that least affects performance.
- Evaluation: Uses model scoring metrics (e.g., accuracy, AIC, R²) to decide inclusion/exclusion.
- Use Case: Regression and classification problems where model interpretability or performance tuning is needed.
Factor Analysis
$$ X = LF + \epsilon $$
- X: Observed variables matrix.
- L: Loading matrix showing the relationship between observed variables and latent factors.
- F: Latent factors that explain the shared variance in X.
- epsilon: Unique (noise) variance not explained by the factors.
- Goal: Discover hidden structures by modeling only the common variance among variables.
- Contrast with PCA: PCA captures total variance, while factor analysis focuses on shared (common) variance.
- Use Case: Psychology, social sciences, market research, where interpreting latent traits is essential.