In high-dimensional space
Building and checking models
Principle or heuristic
Advanced
No one can hear you scream.
What it is
A play on the Alien tagline, “In space no one can hear you scream.” Intuitions from one, two or three dimensions fail badly in high dimensions. The most striking case is that in a high-dimensional distribution, almost none of the probability mass is near the mode. Draws from a 100-dimensional standard normal are almost never near the origin, even though the origin has the highest density. They sit in a thin shell, the typical set, at radius about \(\sqrt{d}\).
Why it matters
The typical set explains a lot about Bayesian computation. Optimizers find the mode, which is unrepresentative. Random-walk samplers struggle because almost all of the space is empty. Hamiltonian Monte Carlo, as used in Stan, works because it is designed to move along the typical set. It also explains why posterior modes (MAP estimates) can be misleading summaries in high-dimensional models such as hierarchical models with many groups.
How it works
For \(x \sim \mathrm{N}(0, I_d)\), the squared distance from the mode is \(\lVert x \rVert^2 \sim \chi^2_d\), with mean \(d\) and standard deviation \(\sqrt{2d}\). So
\[ \lVert x \rVert \approx \sqrt{d} \pm \tfrac{1}{\sqrt{2}}. \]
As \(d\) grows, the radius grows and the relative width of the shell shrinks. The density is highest at the origin, but the volume there is tiny. The mass sits where moderate density meets enormous volume.
Simulated example
Draw 5,000 points from a \(d\)-dimensional standard normal and look at their distances from the mode.
Show simulation code
The R version uses base R, and the Python version uses NumPy and Matplotlib. Where the simulation draws random numbers, each language draws its own, so exact numbers differ slightly but show the same pattern. The numbered markers in the R code are explained under it.
import {rng, range, mean, sd, fmt, pct} from "../js/stats.js"
viewof d = Inputs.range([1, 500], {value: 100, step: 1, label: "Dimension d"})
viewof seed = Inputs.range([1, 500], {value: 132, step: 1, label: "Random seed"})
shell = {
const r = rng(seed);
return range(5000).map(() => { let s = 0; for (let j = 0; j < d; j++) { const z = r.normal(); s += z * z; } return {dist: Math.sqrt(s)}; });
}
Plot.plot({
ariaLabel: "In high-dimensional space: simulation chart",
ariaDescription: "Horizontal axis: Distance from the mode. Vertical axis: Draws. The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 280,
x: {label: "Distance from the mode", grid: true, domain: [0, Math.max(4, Math.sqrt(d) + 4)]},
y: {label: "Draws"},
marks: [
Plot.rectY(shell, Plot.binX({y: "count"}, {x: "dist", fill: "#2166ac", thresholds: 60})),
Plot.ruleX([0], {stroke: "#d6604d", strokeWidth: 3}),
Plot.text([0], {x: 0, y: 0, text: () => "mode", dx: 6, dy: -10, textAnchor: "start", fill: "#d6604d"}),
Plot.ruleX([Math.sqrt(d)], {stroke: "currentColor", strokeDasharray: "4 3"}),
Plot.ruleY([0])
]
})# In high-dimensional space, no one can hear you scream.
1d <- 100 # dimension
2set.seed(132)
3dist <- sqrt(rowSums(matrix(rnorm(5000 * d), ncol = d)^2)) # from the mode
cat("Distance from the mode: ", round(mean(dist), 2), " +/- ",
round(sd(dist), 2), " (sqrt(d) = ", round(sqrt(d), 2), ")\n",
sep = ""
)
cat("Share of draws within distance 1 of the mode: ",
round(100 * mean(dist < 1), 2), "%\n",
sep = ""
)
4hist(dist,
breaks = 40, col = "#2166ac", border = "white", main = "",
xlim = c(0, max(dist)), xlab = "Distance from the mode",
ylab = "Draws"
)
abline(v = 0, col = "#d6604d", lwd = 3)- 1
- The page’s control: the number of dimensions.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- The distance from the mode of 5,000 draws from a standard normal in d dimensions. It concentrates near the square root of d.
- 4
- The histogram of distances. The mode, in red at zero, is where the density is highest and where no draw ever goes.
# In high-dimensional space, no one can hear you scream.
import numpy as np
import matplotlib.pyplot as plt
d = 100 # dimension
rng = np.random.default_rng(132)
dist = np.sqrt((rng.normal(size=(5000, d)) ** 2).sum(axis=1)) # from mode
print(f"Distance from the mode: {dist.mean():.2f} +/- {dist.std(ddof=1):.2f}"
f" (sqrt(d) = {np.sqrt(d):.2f})")
print(f"Share of draws within distance 1 of the mode: "
f"{100 * np.mean(dist < 1):.2f}%")
plt.hist(dist, bins=40, color="#2166ac")
plt.axvline(0, color="#d6604d", linewidth=3)
plt.xlim(0, dist.max())
plt.xlabel("Distance from the mode")
plt.ylabel("Draws")
plt.show()Key takeaways
- In high dimensions, almost all probability mass is far from the mode, in the typical set.
- Mode-based summaries and optimizers can badly misrepresent high-dimensional posteriors.
- Good samplers, such as Hamiltonian Monte Carlo, are built to explore the typical set.
Source
- Andrew Gelman, The typical set and its relevance to Bayesian computation (2020).
- Michael Betancourt, “A conceptual introduction to Hamiltonian Monte Carlo” (2017).