Abstract
Construction of a nearest neighbor graph is a critical yet computationally expensive step in many machine learning applications, particularly with high-dimensional data. This paper explores optimizing parallel execution of $k$-nearest neighbor ($k$NN) graph construction using tree-based data structures like $k$-d trees and ball trees. By leveraging the OpenMP and Galois frameworks, we present efficient and scalable parallel implementations. Our results demonstrate that while $k$-d trees excel in low-dimensional spaces, ball trees provide superior scalability in high-dimensional contexts. Notably, our Galois-based ball tree implementation achieves near-linear speedup across various datasets, significantly outperforming standard sequential libraries.
Introduction
The $k$-Nearest Neighbor ($k$NN) graph is a fundamental structure in machine learning, essential for tasks ranging from manifold learning to computer vision. However, as datasets grow in size and dimensionality, the computational cost of building these graphs becomes a significant bottleneck. The "curse of dimensionality" renders simple spatial partitions inefficient, often forcing algorithms to search nearly every branch of a tree.
While libraries like Scikit-learn offer tree-based search capabilities, they are frequently limited by sequential execution or poor scaling on large-scale data. This work addresses these challenges by developing a high-performance, parallel, and exact $k$NN graph construction tool capable of handling massive, high-dimensional datasets.
Methodology: Tree-Based Partitioning
The core of our approach lies in parallelizing the search phase of two primary data structures:
- $k$-d Trees: These partition space using axis-aligned hyperplanes. They are most effective when the number of points ($N$) is significantly larger than $2^d$, where $d$ is the number of dimensions.
- Ball Trees: These utilize nested hyperspheres to partition data, relying on the triangle inequality for pruning. This makes them generally more robust than $k$-d trees in high-dimensional spaces.
As illustrated in Figure 1, the dataset is recursively divided into a hierarchy of nodes. While the initial tree construction is performed sequentially, the search phase—the primary computational bottleneck—is parallelized.
Parallel Frameworks
We implemented these algorithms using two distinct paradigms:
- OpenMP: Utilizes parallel loops to search for neighbors for each point independently in a shared-memory environment.
- Galois Framework: Employs a "graph-centric" operator formulation. By treating the search as a series of tasks on a dynamic worklist, Galois enables more efficient scheduling and resource utilization compared to traditional loop-based parallelism.
Experimental Evaluation
We evaluated our implementations on six datasets with varying characteristics:
- MNIST: High-dimensional (784 features) handwritten digits.
- Covtype: Moderate dimensions (54 features) for forest cover prediction.
- Poker Hand: Large-scale (1 million points), low-dimensional (10 features).
- RNA & Housing: Small, low-dimensional datasets.
Key Results and Insights
Our empirical analysis yielded several critical findings:
- Dimensionality Thresholds: We confirmed the heuristic that $k$-d trees are superior only when $N \gg 2^d$. In high-dimensional scenarios like MNIST, ball trees are essential for performance.
- Galois Scalability: The Galois-based ball tree implementation demonstrated remarkable scalability, achieving almost linear speedup up to 16 threads. This indicates that doubling processing power nearly halves execution time, regardless of data dimensionality.
- Comparison with Scikit-learn: Our parallel implementations consistently outperformed Scikit-learn. On larger datasets like Poker and Covtype, Scikit-learn’s brute-force methods often failed due to memory constraints, whereas our parallel tree methods succeeded.
- Exactness: Unlike approximate $k$NN libraries, our tool ensures exact graph construction, maintaining full accuracy for downstream machine learning tasks.
Conclusion and Future Work
This work presents the first implementation of $k$-d and ball trees using the Galois framework, providing a scalable solution for exact $k$NN graph construction. While the search phase is now highly optimized, future work could focus on parallelizing the initial tree construction to remove it as a potential bottleneck for even larger datasets. Additionally, extending these methods to distributed-memory systems would allow for scaling across multiple machines.
Summary updated