MDS and Isomap
Math 123: Mathematical Aspects of Data Analysis – Fall 2026
Where we are
Last time we built the Laplacian eigenmap, which places each vertex of a similarity graph at \(\bfy_i=(\phi_2(i),\ldots,\phi_{m+1}(i))\), the smoothest embedding that keeps neighbours close. It uses only local information.
Today we finish nonlinear dimension reduction with Isomap (Tenenbaum et al. 2000), which keeps global information: every pairwise distance, measured along the data. It is built on classical multidimensional scaling, which recovers points from their pairwise distances and turns out to be PCA in disguise.
Points from distances: classical MDS
The Laplacian eigenmap only ever asks neighbours to stay close. The other natural idea is to ask for all distances to be right: pick a notion of distance \(\delta_{ij}\) between data points, then find \(\bfy_1,\ldots,\bfy_n\in\Rbb^m\) with \[ \|\bfy_i-\bfy_j\|_2\approx\delta_{ij} \qquad\text{for all }i,j. \] This is multidimensional scaling (MDS). Before choosing a clever \(\delta_{ij}\), we answer a cleaner question: if the \(\delta_{ij}\) really are Euclidean distances between some points, can we recover the points? Distances do not change under translation, rotation, or reflection, so the best we can hope for is the points up to these rigid motions.
The centering matrix
Write \[ \bfJ=\bfI_n-\frac1n\mathbf{1}\mathbf{1}^\top\in\Rbb^{n\times n} \] for the centering matrix. For a vector \(\bfa\in\Rbb^n\), \(\bfJ\bfa=\bfa-\bar a\mathbf{1}\) subtracts the mean \(\bar a\) of the entries from every entry. In other words, \(\bfJ\) is the orthogonal projection onto the vectors with mean zero, so \(\bfJ^\top=\bfJ\), \(\bfJ^2=\bfJ\), and \(\bfJ\mathbf{1}=\mathbf{0}\). Applied to a data matrix \(\bfA\in\Rbb^{n\times d}\) with rows \(\bfx_i^\top\), it centers every column, so \(\bfJ\bfA\) is the centered data matrix \(\bfX\).
Distances determine the Gram matrix
For points \(\bfx_1,\ldots,\bfx_n\in\Rbb^d\), let \(\bfDelta\in\Rbb^{n\times n}\) be the matrix of squared distances, \(\Delta_{ij}=\|\bfx_i-\bfx_j\|_2^2\).
Proof. Let \(\bfA\) be the uncentered data matrix, so that \((\bfA\bfA^\top)_{ij}=\bfx_i^\top\bfx_j\), and let \(\bfg\in\Rbb^n\) have entries \(g_i=\|\bfx_i\|_2^2\). Expanding the square, \[ \Delta_{ij}=\|\bfx_i\|_2^2+\|\bfx_j\|_2^2-2\bfx_i^\top\bfx_j, \qquad\text{that is,}\qquad \bfDelta=\bfg\mathbf{1}^\top+\mathbf{1}\bfg^\top-2\bfA\bfA^\top. \] Since \(\bfJ\mathbf{1}=\mathbf{0}\), multiplying by \(\bfJ\) on both sides kills the two rank-one terms, and \[ -\frac12\bfJ\bfDelta\bfJ=\bfJ\bfA\bfA^\top\bfJ=(\bfJ\bfA)(\bfJ\bfA)^\top=\bfX\bfX^\top. \]
So the distances alone determine the Gram matrix \(\bfX\bfX^\top\) of the centered points, the matrix of all inner products \((\bfx_i-\bar\bfx)^\top(\bfx_j-\bar\bfx)\). For any list of dissimilarities \(\delta_{ij}\), symmetric with \(\delta_{ii}=0\), this suggests forming \[ \bfB=-\frac12\bfJ\bfDelta\bfJ, \qquad \Delta_{ij}=\delta_{ij}^2, \] and treating \(\bfB\) as the Gram matrix of the points we are looking for. The lemma says this is exactly right when the \(\delta_{ij}\) are Euclidean, and the converse holds too.
Proof. If such points exist, Lemma 1 gives \(\bfB=\bfY\bfY^\top\) for their centered data matrix \(\bfY\in\Rbb^{n\times p}\), which is PSD with rank at most \(p\).
Conversely, if \(\bfB\) is PSD with rank at most \(p\), write \(\bfB=\bfQ\Lambda\bfQ^\top\) by the spectral theorem, with only the first \(p\) eigenvalues possibly nonzero, and let \(\bfy_i^\top\) be the \(i\)-th row of \(\bfY=[\sqrt{\lambda_1}\bfq_1,\ldots,\sqrt{\lambda_p}\bfq_p]\), so \(\bfY\bfY^\top=\bfB\). Fix \(i,j\) and let \(\bfv=\bfe_i-\bfe_j\), so that \(\bfY^\top\bfv=\bfy_i-\bfy_j\). The entries of \(\bfv\) sum to zero, so \(\bfJ\bfv=\bfv\), and since \(\bfJ^\top=\bfJ\), \[ \|\bfy_i-\bfy_j\|_2^2 =\bfv^\top\bfY\bfY^\top\bfv =\bfv^\top\bfB\bfv =-\frac12(\bfJ\bfv)^\top\bfDelta(\bfJ\bfv) =-\frac12\bfv^\top\bfDelta\bfv =-\frac12(\Delta_{ii}+\Delta_{jj}-2\Delta_{ij}) =\delta_{ij}^2. \]
This is a classical result of Schoenberg (1935) and of Young and Householder (1938). It also gives a diagnostic: a negative eigenvalue of \(\bfB\) certifies that no configuration of points in any dimension has exactly the distances \(\delta_{ij}\).
The MDS embedding
When \(\bfB\) is not PSD, or has rank larger than \(m\), we settle for the configuration whose Gram matrix \(\bfY\bfY^\top\) is closest to \(\bfB\).
Proof. The candidates \(\bfP=\bfY\bfY^\top\) are exactly the PSD matrices of rank at most \(m\). Split \(\bfB=\bfB_+-\bfB_-\) into its positive and negative parts, \[ \bfB_+=\sum_{\lambda_i>0}\lambda_i\bfq_i\bfq_i^\top, \qquad \bfB_-=\sum_{\lambda_i<0}|\lambda_i|\bfq_i\bfq_i^\top, \] both PSD. Expand the square, using \(\langle\bfM,\bfN\rangle=\operatorname{tr}(\bfM^\top\bfN)\) for the inner product behind the Frobenius norm: \[ \|\bfB-\bfP\|_F^2=\|\bfB_+-\bfP\|_F^2+\|\bfB_-\|_F^2+2\operatorname{tr}(\bfB_-\bfP)-2\operatorname{tr}(\bfB_+\bfB_-). \] The last term is zero, since \(\bfB_+\bfB_-\) only involves products \(\bfq_i^\top\bfq_j=0\) with \(i\neq j\). The third term is non-negative: \(\operatorname{tr}(\bfB_-\bfP)=\sum_{\lambda_i<0}|\lambda_i|\,\bfq_i^\top\bfP\bfq_i\geq0\) since \(\bfP\) is PSD. So \(\|\bfB-\bfP\|_F^2\geq\|\bfB_+-\bfP\|_F^2+\|\bfB_-\|_F^2\).
Since \(\bfB_+\) is PSD, its eigendecomposition is an SVD, so by Eckart–Young the first term is smallest at \(\bfP=\sum_{i=1}^m\lambda_i\bfq_i\bfq_i^\top\). This \(\bfP\) equals \(\bfY\bfY^\top\) for the claimed \(\bfY\), and has \(\operatorname{tr}(\bfB_-\bfP)=0\), so it attains the lower bound.
The \(\bfY\) produced is automatically centered: \(\bfB\mathbf{1}=\mathbf{0}\) because \(\bfJ\mathbf{1}=\mathbf{0}\), so every \(\bfq_i\) with \(\lambda_i\neq0\) is orthogonal to \(\mathbf{1}\). As with the eigenmap, \(\bfY\bfQ\) is just as good for any orthogonal \(\bfQ\in\Rbb^{m\times m}\), so the answer is only determined up to rotation and reflection, which is all we could ask for.
MDS on Euclidean distances is PCA
Proof. By Lemma 1 and the SVD and eigendecomposition, \(\bfB=\bfX\bfX^\top=\bfU_r\Sigma_r^2\bfU_r^\top\). So \(\lambda_i=\sigma_i^2\) and \(\bfq_i=\pm\bfu_i\), and \(\sqrt{\lambda_i}\bfq_i=\pm\sigma_i\bfu_i=\pm\bfX\bfv_i\).
So PCA only ever needed the pairwise distances, never the coordinates themselves. That is what makes the next step possible: keep the PCA machinery, but feed it a better notion of distance.
Isomap
On the swiss roll, the Euclidean distance between points on adjacent layers is small, but the distance along the roll, the geodesic distance, is large. Unrolling the roll does not stretch it, so the geodesic distance between two points equals the ordinary distance between them in the flat rectangle. So if we knew the geodesic distances, Proposition 1 says they would be Euclidean distances in \(\Rbb^2\), and Theorem 1 would recover the flat rectangle exactly, up to a rigid motion.
We do not know the surface, but Lecture 13 already suggested a substitute: give each edge of a nearest-neighbour graph the length \(\|\bfx_i-\bfx_j\|_2\), and measure distance by shortest paths. Short edges are trustworthy, because nearby points are close along the surface too, and a path of short edges follows the surface instead of cutting through empty space.
Computing all the graph distances is a classical problem: Dijkstra’s algorithm, run once from every vertex, finds them for a \(k\)-nearest-neighbour graph in about \(O(n^2(k+\log n))\) operations.
Tenenbaum, de Silva, Langford, and collaborators (Tenenbaum et al. 2000) show that, as the samples get denser and the neighbourhoods smaller, graph distances converge to geodesic distances, so Isomap recovers the flat coordinates of any surface that can be unrolled without stretching onto a convex region of \(\Rbb^m\). Each hypothesis points at a way the method breaks.
- Shortcuts. If \(k\) is too large, or the noise too big, one edge can jump between adjacent layers of the roll. Every shortest path that can use it does, so a single bad edge can corrupt a large fraction of the distances at once.
- Holes. If the flat region is not convex, say a rectangle with a hole in it, geodesics must bend around the hole. Then the geodesic distances are not Euclidean distances in the plane, \(\bfB\) has negative eigenvalues, and the embedding is distorted near the hole.
- Surfaces that cannot be flattened. A sphere cannot be unrolled onto the plane without stretching, so no planar embedding preserves its geodesic distances, and MDS returns the best compromise.
- Disconnected graphs. If \(k\) is too small, some graph distances are infinite, and MDS cannot run at all.
- Cost. The matrix \(\bfB\) is dense and \(n\times n\), whereas the eigenmap only needs eigenvectors of a sparse Laplacian.
import numpy as np
from scipy.sparse.csgraph import shortest_path
from sklearn.neighbors import kneighbors_graph
def classical_mds(delta, m):
n = len(delta)
J = np.eye(n) - np.ones((n, n)) / n
B = -0.5 * J @ (delta**2) @ J
lam, Q = np.linalg.eigh(B) # increasing order
lam, Q = lam[::-1][:m], Q[:, ::-1][:, :m] # m largest
return Q * np.sqrt(lam) # Y = Q_m Lambda_m^{1/2}; assumes lam[m-1] > 0
def isomap(X, m, k=10):
G = kneighbors_graph(X, k, mode="distance") # edge lengths
delta = shortest_path(G, method="D", directed=False) # Dijkstra
return classical_mds(delta, m)scikit-learn’s Isomap does the same.
Local versus global
| Laplacian eigenmap | Isomap | |
|---|---|---|
| Keeps | neighbours close | all geodesic distances |
| Matrix | sparse Laplacian \(\bfL_{\mathrm{sym}}\) | dense \(\bfB=-\frac12\bfJ\bfDelta\bfJ\) |
| Eigenvectors | smallest, after the constant one | largest |
| Scale of the output | fixed by \(\bfY^\top\bfD\bfY=\bfI_m\), so not meaningful | distances are meant to be read off |
Both start from the same nearest-neighbour graph, and both end in an eigenvalue problem, but they ask opposite questions of it. To see both at work on real photographs, see Twenty Objects on a Turntable.
The most popular tools for visualizing high-dimensional data are t-SNE (Maaten and Hinton 2008) and UMAP (McInnes et al. 2018). Like the eigenmap, they start from a nearest-neighbour graph and pull neighbours together. Recall that the eigenmap never asks distant points to be far apart, and leaves that to the constraint \(\bfY^\top\bfD\bfY=\bfI_m\). t-SNE and UMAP drop the constraint and instead push every pair of points apart, then minimize the resulting attraction-minus-repulsion objective by gradient descent. The objective is not convex, so there is no eigenvector formula, and the answer depends on the starting point; UMAP starts from a Laplacian eigenmap.
- Wattenberg, Viégas, and Johnson, How to Use t-SNE Effectively (Distill, 2016). Interactive; read this one first. The main lesson: cluster sizes and the gaps between clusters in a t-SNE plot can mean nothing.
- Google PAIR, Understanding UMAP. A companion piece in the same style, comparing UMAP with t-SNE.
- Böhm, Berens, and Kobak, Attraction-Repulsion Spectrum in Neighbor Embeddings (JMLR, 2022). For the curious: it places Laplacian eigenmaps, UMAP, and t-SNE on a single spectrum, according to how strongly each one repels.