Abstract
We present Bayesian Binary Search (BBS), a novel probabilistic variant of the classical binary search/bisection algorithm. BBS leverages machine learning/statistical techniques to estimate the probability density of the search space and modifies the bisection step to split based on probability density rather than the traditional midpoint, allowing for the learned distribution of the search space to guide the search algorithm. Search space density estimation can flexibly be performed using supervised probabilistic machine learning techniques (e.g., Gaussian process regression, Bayesian neural networks, quantile regression) or unsupervised learning algorithms (e.g., Gaussian mixture models, kernel density estimation (KDE), maximum likelihood estimation (MLE)). We demonstrate significant efficiency gains of using BBS on both simulated data across a variety of distributions and in a real-world binary search use case of probing channel balances in the Bitcoin Lightning Network, for which we have deployed the BBS algorithm in a production setting.
Introduction
The binary search algorithm is a fundamental tool in computer science, prized for its $O(\log n)$ efficiency. Traditionally, the algorithm operates by bisecting the search space at the geometric midpoint. However, this approach assumes a uniform prior, treating every position as equally likely. In many practical applications, such as searching for a user's age in a database or probing payment channel balances in the Bitcoin Lightning Network, prior knowledge or historical data often suggests that certain regions of the search space are more probable than others. Bayesian Binary Search (BBS) addresses this by incorporating probability density estimation into the search process.
Methodology: Probabilistic Bisection
The core innovation of BBS is the transition from geometric bisection to probabilistic bisection. Instead of calculating the midpoint as $mid = (low + high) / 2$, BBS identifies a split point $x^*$ such that the cumulative distribution function (CDF) at $x^*$ is 0.5. This effectively splits the search space into two regions of equal probability rather than equal size.
The BBS workflow involves:
- Probability Density Function (PDF) Estimation: Utilizing machine learning models (e.g., Gaussian Process Regression, Bayesian Neural Networks) to generate an initial distribution of the target's location.
- Median Identification: Calculating the point $x^*$ that bisects the estimated PDF.
- Query and Bayesian Update: Comparing the target against $x^*$. Upon determining the target's relative position, the algorithm truncates the impossible region of the distribution and renormalizes the remaining PDF.
- Iteration: Repeating the process until the target is localized within a specified tolerance ($\epsilon$).
Experimental Evaluation
The authors evaluated BBS using both simulated distributions and real-world data from the Bitcoin Lightning Network (LN).
Simulated Distributions
BBS was tested against targets sampled from Normal, Bimodal, and Exponential distributions. These tests aimed to quantify performance gains when dealing with varying degrees of data skewness.
Real-World Application: Bitcoin Lightning Network
The algorithm was applied to the task of probing LN channel balances. This is a high-cost search environment where each query involves sending "fake" payments to determine liquidity. A Random Forest model, trained on node and edge features, provided the prior distributions for these searches.
Results and Discussion
The experimental results demonstrate that BBS consistently outperforms standard binary search when accurate prior information is available.
As shown in Figure 1, the mean number of steps required by BBS is consistently lower than that of standard Binary Search across various epsilon values for a Normal distribution. The performance gap is particularly pronounced at lower epsilon values, where the probabilistic guidance allows for faster convergence.
The data in Figure 2 quantifies these improvements, showing a percent decrease in search steps ranging from approximately 4.5% to over 11% for the Normal distribution. In simulations using exponential distributions, the reduction in search steps was even more significant, reaching 13% to 20%. In the real-world Bitcoin LN application, BBS achieved a 3% to 6% reduction in required probes, which translates to improved network liquidity and reduced overhead in production environments.
Robustness and Limitations
BBS is a generalization of standard binary search; if a uniform distribution is assumed, BBS reverts to the classical midpoint bisection. However, the algorithm's performance is sensitive to the quality of the prior. If the ML model's prediction is highly inaccurate (high KL divergence from the true distribution), BBS may perform worse than the standard algorithm. Additionally, the computational cost of PDF estimation and median calculation must be weighed against the savings in search steps, making BBS most suitable for environments where queries are "expensive."
Conclusion
Bayesian Binary Search represents a significant advancement in search algorithms by integrating statistical learning with classical bisection. By "splitting the odds" rather than the middle, BBS offers a more efficient path to target localization in data-rich environments. Future work will focus on adaptive PDF estimation to handle non-stationary distributions and establishing tighter theoretical performance bounds.
Paper Citation: Singh, V., et al. (2024). Bayesian Binary Search. arXiv:2410.01771v1 [cs.LG].
Summary updated