Abstract
Bayesian Network (BN) structure learning is computationally intensive due to the high volume of Conditional Independence (CI) tests required to map variable relationships. This paper introduces Fast-BNS, a highly optimized multi-core CPU implementation of the PC-stable algorithm. By employing a novel CI-level parallelism granularity, dynamic work pooling, and cache-friendly data structures, Fast-BNS achieves speedups of up to 50x for sequential execution and 24.5x for parallel execution compared to existing state-of-the-art libraries.
Introduction
Learning the structure of a Bayesian Network from data involves discovering conditional dependencies, typically represented as a Directed Acyclic Graph (DAG). Constraint-based methods like the PC-stable algorithm are standard for this task but rely on a massive number of CI tests. For high-dimensional datasets, these tests become a severe computational bottleneck. Previous attempts to parallelize this process on multi-core CPUs have struggled with efficiency due to suboptimal work granularity.
The Parallelization Bottleneck
Existing parallelization schemes for PC-stable generally fall into two categories, both of which have significant drawbacks:
- Edge-level parallelism (Coarse): Assigning different network edges to different threads leads to severe load imbalance. Some edges require many more CI tests than others, leaving threads idle while others are overloaded.
- Sample-level parallelism (Fine): Splitting the dataset across threads to compute a single CI test requires expensive atomic operations to prevent race conditions during contingency table updates, creating massive overhead.
Fast-BNS: CI-Level Parallelism
To overcome these limitations, Fast-BNS introduces CI-level parallelism. Instead of locking a thread to a specific edge or data sample, Fast-BNS uses a dynamic work pool (a stack) to monitor the processing progress of all edges. Threads dynamically pull groups of CI tests from the pool, process them, and update the edge's status. If an edge is proven independent, it is immediately dropped, ensuring threads remain balanced without requiring atomic operations.
Implementation Optimizations
Beyond its parallelization strategy, Fast-BNS incorporates three key software engineering optimizations:
- Grouping CI Tests: By grouping undirected edge tests (e.g., $V_i - V_j$ and $V_j - V_i$), the algorithm halves the total number of necessary CI tests.
- Cache-Friendly Data Storage: Fast-BNS transposes the dataset matrix so that rows represent features and columns represent samples. This converts random memory accesses into sequential ones, drastically reducing CPU cache misses.
- On-the-Fly Conditioning Sets: Rather than pre-computing and storing all possible conditioning sets—which is memory-intensive—Fast-BNS uses a lexicographical function to generate them in parallel as needed.
Experimental Results
Fast-BNS was evaluated using eight standard benchmark networks (e.g., Alarm, Munin, Link) with sample sizes up to 15,000.
- Sequential Speedup: The optimized sequential version is up to 50x faster than packages like
bnlearnandpcalg. - Parallel Speedup: Multi-threaded Fast-BNS is 4.8x to 24.5x faster than state-of-the-art parallel implementations like
parallel-PC. - Efficiency: On the complex Link dataset, where existing tools took over two days, Fast-BNS completed the task in approximately 1.2 hours. CPU profiling confirmed higher utilization and fewer cache misses, validating the design.
Conclusion
Fast-BNS demonstrates that granularity is the critical factor in parallelizing BN structure learning. By shifting to CI-level parallelism and optimizing memory access patterns, it eliminates thread starvation and atomic overhead. The open-source C++ implementation provides a high-performance foundation for future research in causal discovery.
Summary updated