Manifolds: a low-dimensional surface inside a high-dimensional space

A grayscale photo is a point made of 10,000 numbers. But realistic photos are not spread evenly through that huge space. They are thought to gather near a narrow, curved surface. That surface is a manifold. Unroll a thread coiled into a spiral yourself, and see why you should not measure in straight lines on a curved surface.

Short answer. A manifold is a surface that looks flat up close but is curved as a whole. The surface of the Earth is one. Your neighborhood looks flat, but the whole thing is a ball. In AI it shows up as the manifold hypothesis: "real data seems to have many numbers, but it gathers near a low-dimensional surface like this". It is not a proven fact but an assumption that works well. On a curved surface, straight-line distance can be misleading, so you either measure along the surface (geodesic distance) or unroll the surface and give the points new coordinates. A latent space can be seen as those unrolled coordinates.

0

The data is 120 points on a plane. They sit in thread order on a spiral coiled three times (gap between turns 1), shaken a little with a fixed seed. Everything is made up. It is the rolled-up sheet in 3D (the Swiss roll) with one dimension taken away: a 1D thread inside 2D. The color is the position t measured along the thread (start 0 is blue, end 1 is orange). Unrolling keeps the length of every piece of thread and only shrinks the angles where it bends. So the length along the thread is the same at every amount. The picture zooms so the points fill the box, with the same scale across and up.

Try this. ① At unroll amount 0 the colors in the band are mixed. Only 53% of point pairs sit in thread order (a coin flip would give 50%). That is because every turn passes over the same x positions again. ② At 0.5 it is still 53%: the coiled part still overlaps. At 0.75 it is 93%, and at 1 it is 100%, with the colors lined up from blue to orange. ③ All the while the length along the thread stays 38.3, and only the straight-line distance between the two ends changes, from 3 to 38.3.

Definitions

The text below explains with pictures and experiments. These are the textbook definitions. A point is a point of ℝD, written with D numbers, and ‖·‖ is the Euclidean (straight-line) distance.

manifold
Let M be a subset of ℝD. M is a k-dimensional manifold if every point p of M has an open set U in M that contains p, an open set V in ℝk, and a homeomorphism φ:U→V (a one-to-one correspondence where the map and its inverse are both continuous). k is called the intrinsic dimension and D the ambient dimension.
manifold hypothesis
The assumption that real high-dimensional data, such as images, sound and text, lie close to a manifold (one piece or several) whose intrinsic dimension is much lower than the ambient dimension D. It is not a proven theorem. The evidence is that methods built on it work well.
geodesic distance
For two points a and b on a manifold M, join them with continuous curves γ:[0,1]→M (γ(0) = a, γ(1) = b) that never leave M. The geodesic distance is the infimum of the lengths of these curves. The length of a curve is the supremum of the lengths of the broken lines that join points marked along it in order.

L(γ)=sup0=t0<t1<…<tm=1∑k=1m‖γ(tk)−γ(tk−1)‖

dM(𝐚,𝐛)=infγL(γ)

latent space
A low-dimensional coordinate space (k < D) that represents the data. An encoder f:ℝD→ℝk sends a data point x to latent coordinates z = f(x), and a decoder g:ℝk→ℝD sends z to a point in the data space. Under the manifold hypothesis you can see it as coordinates made by flattening the manifold the data lie on.
manifold learning
Nonlinear dimensionality reduction methods that find low-dimensional coordinates while keeping the structure of the manifold the data lie on (geodesic distances or nearest-neighbor relations). For example, Isomap estimates geodesic distances by shortest paths in a graph of nearest neighbors and keeps them, and t-SNE and UMAP keep nearest neighbors.

1. What a manifold is: a surface that looks flat up close

Think of the surface of the Earth. A map of your neighborhood can be drawn on a flat sheet of paper and be almost right. But the whole Earth is a ball, and you cannot fit all of it on one sheet without squashing it. Flat up close, curved as a whole. That is a manifold. The surface of the Earth is a 2D manifold inside 3D space, because two numbers, latitude and longitude, are enough to fix a place.

"Dimension" means two things here. One is how many numbers you use to write a point down (the dimension of the outside space). The other is how many directions you can move in on the surface (the dimension of the surface). The lab's points are written with two numbers, x and y, but on the thread they can only move forward or back. The outside is 2D, the surface is 1D.

2. The manifold hypothesis: data gathers near a narrow surface

A 100 × 100 grayscale face photo has one brightness number per pixel, so it is one point made of 10,000 numbers: a point in a 10,000-dimensional space. But if you pick any point in that space (set every pixel's brightness at random), you almost always get a picture of static noise. Points that look like faces sit only in a very narrow part of this huge space.

On top of that, photos of one person's face can be seen as fixed, more or less, by a few dozen factors such as head angle, expression and lighting. Turn the head a little and the photo changes a little. So you can think of face photos as lying near a curved surface of a few dozen dimensions inside the 10,000 dimensions. This idea is the manifold hypothesis. Real data such as images, sound and text is thought to behave this way, by and large.

Careful. The manifold hypothesis is not a proven fact but an assumption that works well. The evidence is that methods built on it work well. It does not mean that every dataset truly lies on one smooth surface. The surface may come in several pieces, or have a different dimension in different places.

3. Latent space: the coordinates of the unrolled surface

A manifold is the curved surface the data lies on, and a latent space is the coordinates you get by unrolling that surface. For the Earth, the surface of the Earth is the manifold and a latitude-longitude map is the latent space. Put a dot on the map and it fixes one place on the Earth. Any place on the Earth can be moved to one dot on the map.

Unroll the lab all the way and each point's place can be written with one number (how far to the right of the first point). That number is the position along the thread, the 1D latent coordinate of this thread. That is why the colors in the band line up in order. An autoencoder learns an encoder and a decoder like these together, as neural networks. But just as a world map stretches the polar regions, unrolled coordinates can be stretched or squeezed in places.

4. Straight-line distance and distance along the surface

Say two ants sit on a rolled-up sheet of paper. One is on an inner turn and the other on the next turn out, on the same side. Measured straight through space, they are only one gap apart. But the ants cannot leave the paper, so they have to walk a full turn along it to meet. Distance measured along the surface is called geodesic distance. It is like the flight distance between two cities, which is measured along the surface of the Earth, not straight through the ground.

50 106

The same 120 points as lab ①, left coiled as they were. The points are numbered from 0 at the start of the thread to 119 at the end. Distance along the thread is the straight-line distances between neighboring points, added up in order between the two points (section 5).

Try this. ① The starting pair, #50 and #106, sit on the same side of neighboring turns. The straight-line distance is 1, but along the thread it is 18.01, 18 times longer. ② Move point ② to #51 (right next to point ①) and the two distances match, 0.35 and 0.35. Up close the surface is flat. ③ #0 and #119 (the two ends of the thread) are 2.99 apart in a straight line and 38.26 along the thread.

This is why PCA goes wrong on a curved surface. PCA picks the straight direction in which the points spread out the most and drops a shadow onto it. The band at the bottom of lab ① is such a shadow. When you squash in a straight line, points on other turns that are close in a straight line land on the same spot, and the colors mix. A spiral overlaps its turns whatever straight direction you squash it along. To unroll a curved surface properly, you need a method that keeps distances along the surface or keeps close neighbors. Isomap computes geodesic distances and keeps them, t-SNE and UMAP keep close neighbors as they flatten, and an autoencoder learns a function that does the unrolling.

5. How the formula is built: adding short straight lines in order

The length of a curved path is hard to measure directly. So you cut the path into short pieces, measure each piece in a straight line, and add them up. A short piece is almost straight inside. This is "flat up close" put to work. Place four points x₀, x₁, x₂, x₃ evenly on a half circle of radius 1 and follow along.

  1. Straight-line distance: d(x₀, x₃) = ‖x₃ − x₀‖. It is 2. It is the diameter of the half circle, so it passes through the empty space off the thread.
  2. The first piece: ‖x₁ − x₀‖. It is 1. Joining two next-door points with a straight line does not stray far from the thread. Why: up close the surface is flat, so over short distances you can trust straight-line distance.
  3. One more piece: ‖x₁ − x₀‖ + ‖x₂ − x₁‖. The total is 2. Only join next-door points, never skip. Why: a straight line that skips far ahead passes through empty space again.
  4. Add them all: D(x₀, x₃) ≈ Σₖ ‖xₖ − xₖ₋₁‖. The total is 3, which is 1.5 times the straight-line 2. It is a little shorter than the true half circle, π ≈ 3.14. Cut it into 6 pieces and you get 3.11, into 12 pieces 3.13. Why: each piece is a shortcut a little shorter than the thread, so the total always falls a little short, but the gap shrinks as the pieces get shorter.

The "distance along the thread" in lab ② is this sum. Real data, though, does not come with the thread order written down. Isomap links each point to a few close neighbors to build a graph, then finds the shortest path in that graph to get this sum. After that it places the points in a low dimension so these distances are kept as well as possible.

6. Easy mistakes

When to use which

MethodGoodBadUse it when
PCAFast and always the same answer. Moves new points the same way. The kept-variance ratio tells you how much you lostOnly squashes in straight lines. On a curved surface, different turns overlap (the band in lab ①)The surface is nearly flat. A first look. Cutting down dimensions before another method
IsomapUnrolls while keeping geodesic distances. Straightens a rolled-up surfaceIf the neighborhood is too wide or the noise is large, shortcuts jump between turns and break it. It finds shortest paths for every pair of points, so it is slow on big dataOne surface curves smoothly and you want to keep distances along the surface themselves
t-SNE · UMAPClose neighbors are kept well, so clusters show up clearlyFor looking. Large distances and cluster sizes cannot be trusted. Each setting and seed gives a different pictureLooking at curved data as a 2D picture
AutoencoderLearns an encoder and a decoder together, so it turns new data into coordinates and rebuilds data from coordinatesNeeds training and a lot of data. The axes have no fixed meaningUsing the coordinates of a curved surface as model input or to make new data

Common questions

Is the manifold hypothesis proven?

No. It is an assumption that real data gathers near a low-dimensional curved surface. The evidence is that methods built on it work well. There is no promise that it always holds for every dataset.

How do I tell whether my data lies on a flat or a curved surface?

There is no clear-cut test. Color the points by something you already know, such as a label or an order, and squash them with PCA. If the colors line up in order, PCA is enough. If they mix like the band in lab ①, suspect a curved surface and compare with a t-SNE or UMAP picture.

Are a manifold and a latent space the same thing?

No. A manifold is the curved surface the data lies on, inside the original space. A latent space is the set of coordinates you get by unrolling that surface. It is the relation between the surface of the Earth and a latitude-longitude map.

Words

What this page saysWhat books call it
a surface that is flat up close and curved as a wholemanifold
the idea that data gathers near a narrow surfacemanifold hypothesis
dimension of the surfaceintrinsic dimension
how many numbers write a point downambient dimension
straight-line distanceEuclidean distance
distance along the surfacegeodesic distance
coordinates of the unrolled surfacelatent space, latent representation
methods that unroll a curved surfacemanifold learning, nonlinear dimensionality reduction
squashing in straight lineslinear projection
rolled-up sheet of paperSwiss roll
adding short straight lines in orderpolygonal approximation of arc length
a shortcut that jumps between turnsshort-circuit

Sources

← t-SNE and UMAPDecision trees, random forests and boosting →