Skip to the interactive lab
← The dimensionality notebook

03 / Minimal neighbourhoods

Two nearest neighbours

Two distances. A surprisingly useful ratio.

Preparing the geometry lab…

Behind the estimate

A little geometry. A clearer picture.

Back to the experiment ↑

How it works

For each point, compare its first two neighbours. Their distance ratios reveal a dimension through a simple fitted line.

μ=r2r1−log(1−F(μ))=dlogμ

r₁ and r₂ are the first two neighbour distances; F is the cumulative distribution of their ratio.

  1. Keep only two neighbours.Compute μ = r₂ / r₁ for every valid sample.
  2. Order the ratios.Use their empirical cumulative distribution to form the log–log coordinates.
  3. Fit through the origin.The fitted slope is the dimension estimate. The plotted points show how well that relation holds.

The plot is a view of the data. Distances, angles and covariance are computed in all generated coordinates. Noise, sampling and scale can change an estimate; the underlying noiseless manifold is only a reference.