Near-Linear Time Algorithm for the Chamfer Distance

Ainesh Bakshi, Piotr Indyk, Rajesh Jayaram, Sandeep Silwal, Erik Waingarten

TL;DR: Researchers have developed the first near-linear time algorithm to estimate the Chamfer distance, a fundamental metric for comparing point clouds. By replacing a quadratic $O(n^2)$ brute-force approach with an $O(n \log n)$ method utilizing importance sampling and locality-sensitive hashing, the team achieved up to a 50x speedup on billion-scale datasets while maintaining high accuracy.

The Bottleneck of Chamfer Distance

In fields like computer vision, robotics, and graphics, measuring the similarity between two sets of points (point clouds) is a frequent requirement. The Chamfer distance is a standard metric for this task. For two point sets $A$ and $B$, it calculates the sum of the distances from every point in $A$ to its nearest neighbor in $B$.

The primary challenge is scale. A naive, brute-force calculation requires comparing every point in $A$ to every point in $B$, resulting in a quadratic $O(n^2)$ runtime. For a dataset with a million points, this translates to a trillion operations. While Chamfer distance is often used as a faster proxy for the more computationally expensive Earth Mover’s Distance (EMD), its quadratic cost remains a massive bottleneck for modern, high-dimensional, billion-scale datasets.

Methodology: The Chamfer-Estimate Algorithm

To overcome this bottleneck, the authors introduce Chamfer-Estimate, an algorithm that provides a $(1+\epsilon)$-approximation of the distance in near-linear time. The core innovation is a strategic shift from uniform sampling to importance sampling.

  1. The Sampling Dilemma: If points from set $A$ are picked uniformly at random to estimate the total distance, the sample might miss "outliers" that are very far from set $B$. Because these outliers contribute disproportionately to the total distance, missing them leads to significant estimation errors.
  2. CrudeNN Subroutine: To identify these critical points, the authors developed "CrudeNN." This subroutine uses Locality-Sensitive Hashing (LSH) at multiple scales to quickly find a "rough" nearest neighbor for every point. While it doesn't find the exact nearest neighbor, it provides a reliable upper bound, indicating which points in $A$ are likely far from $B$.
  3. Importance Sampling: Using these crude estimates, the algorithm constructs a probability distribution. Points likely to be far away—and thus have a larger impact on the total distance—are sampled more frequently.
  4. Final Estimation: By averaging the results of these strategically chosen samples, the algorithm produces a highly accurate estimate of the total Chamfer distance in a fraction of the time required for a full scan.

Key Theoretical Insights

  • Estimation vs. Reporting: A fascinating theoretical insight of the paper is that estimating the distance value is fundamentally easier than reporting the actual mapping (identifying exactly which point in $A$ maps to which point in $B$). The authors prove that while estimation can be achieved in near-linear time, any algorithm attempting to report the full mapping is likely bound to near-quadratic time due to the "Hitting Set Conjecture."
  • LSH at Every Scale: Standard LSH is typically tuned for a specific distance threshold. The authors’ "hashing at every scale" approach allows them to handle datasets where distances vary wildly, ensuring a point's "importance" is captured whether its nearest neighbor is 1 unit or 1,000 units away.
  • Robustness to Skew: Unlike uniform sampling, which fails when a few points account for most of the distance, this importance sampling approach is mathematically guaranteed to perform well even on highly skewed, outlier-heavy data.

Experimental Results

The authors evaluated their approach across a diverse range of benchmarks, including 3D object point clouds (ShapeNet), word embeddings, synthetic Gaussian points designed to stress-test sampling robustness, and massive high-dimensional datasets (DEEP1B & Microsoft-Turing).

Sample complexity vs. relative error curves and computation time comparisons across various datasets.
  • Efficiency and Accuracy: The algorithm achieved the same relative error as uniform sampling while using 5x to 10x fewer samples. In practical tests, the approximate distance was accurate enough to recover the true nearest neighbor point cloud over 98% of the time.
  • Speed: On billion-scale datasets, the algorithm was up to 50x faster than optimized brute-force methods. For downstream tasks, it proved to be up to 1000x faster than naive methods.
  • Practical Implementation: Unlike many purely theoretical algorithms, Chamfer-Estimate is highly implementable and performs exceptionally well on standard hardware without requiring exotic setups.

Limitations and Future Directions

  • The Mapping Trade-off: As noted, this algorithm only provides the value of the distance. Applications requiring the exact alignment (knowing which point in $B$ is closest to each point in $A$) cannot bypass the quadratic bottleneck using this method.
  • Metric Support: The current paper covers Euclidean ($\ell_2$) and Manhattan ($\ell_1$) distances. Extending this framework to more complex or non-metric distance measures remains an open area for future research.
  • Parameter Tuning: Performance depends on hyperparameters like the number of LSH "grid levels" and window sizes. While a small number of levels works well in practice, automated tuning for arbitrary datasets could further improve usability.

Summary updated

BibTeX
@inproceedings{bakshi2023near,
  author = {Ainesh Bakshi and Piotr Indyk and Rajesh Jayaram and Sandeep Silwal and Erik Waingarten},
  title = {{Near-Linear Time Algorithm for the Chamfer Distance}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=Mv96iC6TMX},
}
Figure