Slice Sampling for Probabilistic Programming

Razvan Ranca, Zoubin GhahramaniarXiv 2015

Introduction

Probabilistic programming languages (PPLs) aim to decouple model specification from inference, allowing researchers to focus on domain-specific logic rather than the intricacies of posterior calculation. However, existing PPLs often suffer from steep learning curves due to specialized syntax and inference engines that require manual tuning. This paper introduces StocPy, a Turing-complete PPL implemented as a native Python library, and proposes a novel transdimensional slice sampling engine designed to handle complex, varying-dimension models automatically.

StocPy and Transdimensional Slice Sampling

StocPy leverages Python's native control flow and the scipy.stats library to provide a familiar environment for model definition. A key challenge in PPLs is "transdimensionality"—where program branching (e.g., if statements) causes the number of active random variables to change. Standard samplers like Metropolis-Hastings (MH) struggle here, often requiring carefully tuned step sizes.

To address this, the authors generalize slice sampling—an MCMC technique that adaptively finds the boundaries of a distribution—to work across dimensions. By incorporating a correction factor inspired by Reversible Jump MCMC (RJMCMC), the engine can jump between program traces of different dimensions while maintaining mathematical correctness. This approach mitigates the "trace problem," where the primary bottleneck is the number of likelihood calculations required for convergence.

Comparison of true trace likelihood versus likelihood when ignoring trans-dimensionality.

Experimental Evaluation

The system was evaluated against standard MH using synthetic models (Gaussian mean inference), PPL benchmarks (HMMs, Dirichlet Process Mixtures), and real-world data (Iris dataset for Logistic Regression and Bayesian Neural Networks). Performance was measured by tracking the Kolmogorov-Smirnov (KS) difference from the true posterior against the number of trace likelihood calculations, ensuring a fair comparison of algorithmic efficiency.

Results and Discussion

Experimental results demonstrate that slice sampling offers superior convergence, particularly in "hard" models with uninformative priors where MH often fails to find the posterior "needle in the haystack."

Performance comparison between Metropolis and Slice sampling on a hard model.

On the Iris dataset, slice sampling converged significantly faster than MH. For instance, in the Iris-versicolor classification task, MH lagged behind even with ten times the runtime. However, a trade-off exists: slice sampling is computationally "heavier" per iteration, requiring at least three likelihood evaluations per sample. In very small, discrete models like simple HMMs, the lower overhead of naive MH can result in faster wall-clock time despite lower per-sample efficiency.

Conclusion

StocPy demonstrates that Python can serve as a first-class citizen for probabilistic programming without sacrificing rigorous inference. Transdimensional slice sampling provides a robust, "tuning-free" alternative to Metropolis-Hastings, particularly for complex models where the dimensionality of the parameter space is not fixed. Future work will focus on optimizing the Python implementation and exploring the scalability of this approach to high-dimensional Bayesian Neural Networks.

Summary updated

BibTeX
@misc{ranca2015slice,
  author = {Razvan Ranca and Zoubin Ghahramani},
  title = {{Slice Sampling for Probabilistic Programming}},
  year = {2015},
  eprint = {1501.04684},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1501.04684},
}
Figure