Dimensionality reduction is the process of reducing the number of random variables under consideration by obtaining a set of principal variables.
Dimensionality Reduction
What is Dimensionality Reduction?
Dimensionality reduction is the process of reducing the number of random variables under consideration by obtaining a set of principal variables.
It helps in:
Uniform Manifold Approximation and Projection (UMAP)
PCA
PCA
Core idea:
Based on variance maximization and eigen decomposition.
PCA
Core idea:
Based on variance maximization and eigen decomposition.
Purpose:
Find a set of orthogonal axes (principal components) that capture the maximum variance in the data.
PCA
Steps:
Center the data.
Compute the covariance matrix: \(\sum = \frac{1}{n} X^T X\)
Compute the eigenvectors and eigenvalues: \(\sum v_i = \lambda_i v_i\)
Project the data onto the new: \(Z = X W_k\)
where \(W_k\) are the top-k eigenvectors.
Example on MNIST
MNIST Dataset
Dataset of 28x28 pixel images of handwritten digits
MNIST Dataset
Every MNIST image can be thought of as a 28x28 array of numbers describing how dark each pixel is:
We can flatten each array into a 28 * 28 = 784 dimensional vector, where each component of the vector is a value between zero and one describing the intensity of the pixel
We can think of MNIST as a collection of 784-dimensional vectors
MNIST Dataset
But not all vectors in this 784-dimensional space are MNIST digits! Typical points in this space are very different
To get a sense of what a typical point looks like, we can randomly pick a few random 28x28 images – each pixel is randomly black, white or some shade of gray. These random points look like noise:
MNIST Dataset
28x28 images that look like MNIST digits are very rare - they make up a very small subspace of 784-dimensional space
With some slightly harder arguments, we can see that they occupy a lower (than 748) dimensional subspace
Many theories about lower-dimensional structure of MNIST (and similar data)
Manifold hypothesis (popular among ML researchers): MNIST is a low dimensional manifold curving through its high-dimensional embedding space
Another hypothesis (rooted in topological data analysis) is that data like MNIST consists of blobs with tentacle-like protrusions sticking out into the surrounding space
But no one actually knows for sure!
MNIST Cube
Imagine the MNIST data points as points suspended in a 784-dimensional cube
Each dimension of the cube corresponds to a particular pixel
The data points range from zero to one according to pixel intensity
On one side of the dimension, there are images where that pixel is white. On the other side of the dimension, there are images where it is black. In between, there are images where it is gray.
What does this cube look like if we look at a particular two-dimensional face? Let's look at Olah's visualizations.
MNIST Cube
What qualities would the ‘perfect’ visualization of MNIST have? What should our goal be?
It is also known as Principal Coordinates Analysis (PCoA).
MDS
It is also known as Principal Coordinates Analysis (PCoA).
Core idea:
Focuses on preserving distances using eigenvalue decomposition of a similarity matrix.
MDS
It is also known as Principal Coordinates Analysis (PCoA).
Core idea:
Focuses on preserving distances using eigenvalue decomposition of a similarity matrix.
Purpose:
Preserve pairwise distances between data points in the low-dimensional embedding.
MDS
Steps:
Compute the squared proximity matrix: \(D^2 = [d^2_{ij}]\)
Double-center the distance matrix to obtain a similarity matrix: \(B = - \frac{1}{2} C D^2 C\)
Where \(C=I-\frac{1}{n} J_n\) is the centering matrix and \(J_n = 11^T\) is the matrix of all ones.
Perform eigen decomposition: \(B = V \Sigma V^T\)
Use top eigenvectors as Low-dim coordinates: \(X = V_k \Sigma_k ^{1/2}\)
Projects using sparse random matrices while preserving distances.
SRP
Core idea:
Projects using sparse random matrices while preserving distances.
Purpose:
Reduce dimensionality while approximately preserving pairwise distances using sparse random matrices.
SRP
Steps:
Generate a sparse random matrix: \(\mathcal{R}_{ij} = \sqrt{s} \times \begin{cases}
+1, & \text{with probability } \frac{1}{2s} \\
-1, & \text{with probability } \frac{1}{2s} \\
0, & \text{with probability } 1 - \frac{1}{s} \\
\end{cases}\)
Where \(s\) is the sparsity parameter.
Projects \(Z = X\mathcal{R}\)
SRP on MNIST
srp=SparseRandomProjection(n_components=2, random_state=42)X_srp=srp.fit_transform(X)plot_clustering(X_srp, "", "Sparse Random Projection")
SRP on MNIST
srp_3d=SparseRandomProjection(n_components=3, random_state=42)X_srp_3d=srp_3d.fit(X)X_srp_3d=srp_3d.fit_transform(X)plot_3d_clustering(X_srp_3d, "", "Sparse Random Projection")
LLE
LLE
Core idea:
Uses local linear reconstruction weights.
LLE
Core idea:
Uses local linear reconstruction weights.
Purpose:
Preserve local neighborhood relationships by linear reconstruction.
LLE
Steps:
Identify k-nearest neighbors for each point:
Minimize \(\sum_i || x_i - \sum _{j \in N(i) w_{ij} x_j } ||^2\)
Compute weights that reconstruct each point from its neighbors.
Find low-dimensional embeddings that preserve these weights: \(\Phi(Y) = \sum_i ||y_i - \sum _{j \in N(i) w_{ij} y_j } ||^2\)
Olah, Christopher. 2014. “Visualizing Mnist: An Exploration of Dimensionality Reduction.”Visualizing MNIST: An Exploration of Dimensionality Reduction - Colah’s Blog. https://colah.github.io/posts/2014-10-Visualizing-MNIST/.