An algorithm for L1 nearest neighbor search via monotonic embedding

Xinan Wang, Sanjoy DasguptaNeurIPS 2016

In the world of machine learning, finding the "nearest neighbor" to a data point is a fundamental task. While Euclidean distance ($\ell_2$) is the default choice for most applications, the Manhattan distance ($\ell_1$) is often far more effective for data representing probability distributions, such as word counts in documents or color histograms in images.

The problem? Most of our fastest tools—like Locality-Sensitive Hashing (LSH) and random projection trees—are built specifically for $\ell_2$ space. In this paper, Xinan Wang and Sanjoy Dasgupta present a clever "monotonic embedding" that allows us to use these high-performance $\ell_2$ tools to solve $\ell_1$ problems without losing accuracy.

The Challenge of $\ell_1$ Projections

Nearest neighbor (NN) search is computationally expensive. A naive search through $n$ points takes $O(n)$ time, which is too slow for massive datasets. To speed this up, researchers use randomized data structures like LSH or trees.

However, these structures rely heavily on random projections, which behave beautifully in $\ell_2$ space but are problematic in $\ell_1$ space. For instance, $\ell_1$ random projections require Cauchy distributions, which have high variance and can be unstable in practice. Furthermore, it is mathematically impossible to embed $\ell_1$ directly into $\ell_2$ without significant distortion.

The authors tackle this by noting that while we can't embed $\ell_1$ into $\ell_2$, we can embed $\sqrt{\ell_1}$ into $\ell_2$. Because the square root is a monotonic function, the nearest neighbor in $\sqrt{\ell_1}$ is exactly the same as the nearest neighbor in $\ell_1$.

Euclidean Random Projection (ERP)

The authors introduce Euclidean Random Projection (ERP), a method that maps the data into a space where standard Gaussian projections can be applied. The process involves:

  1. The 1D Embedding: For a single dimension, they sort the data points and construct an embedding where the distance between points is the square root of their $\ell_1$ distance. This results in a vector in $(n-1)$-dimensional space.
  2. Higher Dimensions: They stack these 1D embeddings for every dimension in the original $d$-dimensional data, creating a massive, high-dimensional embedding in $O(nd)$ space.
  3. The Projection Trick: Materializing an $O(nd)$ vector is too memory-intensive. The authors prove that you can compute the Gaussian random projection of this massive embedding implicitly directly from the original coordinates.
  4. Query Handling: When a new query point arrives, it technically changes the entire embedding structure. The authors provide a mathematical proof showing how to "insert" the query into the existing projections using a specific conditional Gaussian distribution, keeping the process efficient with only $O(\log n)$ overhead.
Algorithm 1 details the implicit random projection for both the data and incoming queries.

Empirical Performance

The authors evaluated their ERP method against Cauchy-based LSH (CRP) and Metric Trees on four datasets where $\ell_1$ is the natural distance metric: Corel UCI (color histograms), Corel Hist, Cade (document topic distributions), and ImageNet (probabilistic class distributions).

Experimental results comparing Linear scan, Metric tree, CRP-LSH, and ERP-LSH across four datasets.

The ERP-LSH method proved highly competitive. Across all datasets, ERP-LSH achieved similar or better "query costs" (the number of points accessed) compared to Cauchy LSH. Notably, in the Cade dataset, ERP-LSH accessed significantly fewer points (218 vs 292) while maintaining a similar approximation rate. Furthermore, unlike Cauchy-based methods that suffer from high variance, the ERP method uses Gaussian projections, which are generally more stable and better understood in algorithmic contexts.

Key Insights and Limitations

A major takeaway from this work is that monotonicity is enough. You don't need to preserve the exact $\ell_1$ distance to find the nearest neighbor; preserving the ordering of distances via $\sqrt{\ell_1} \to \ell_2$ is sufficient. Additionally, while the embedding has a high nominal dimension, its "effective rank" is much lower ($O(d \log n)$), suggesting the data is highly compressible.

However, the method does have limitations:

  • Space Complexity: While ERP avoids materializing the $O(nd)$ embedding, it still requires $O(knd)$ space to store the projections for $k$ hash functions, which is more than the $O(kd)$ required by Cauchy LSH.
  • Sorting Dependency: The preprocessing step requires sorting points along every dimension, taking $O(dn \log n)$ time.

Future work could involve developing algorithms that specifically exploit the low-rank structure of this embedding to further reduce time and space requirements.

Summary updated

BibTeX
@inproceedings{wang2016algorithm,
  author = {Xinan Wang and Sanjoy Dasgupta},
  title = {{An algorithm for L1 nearest neighbor search via monotonic embedding}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2016},
  url = {https://openreview.net/forum?id=ByW38v-uWB},
}
Figure