Delayed Sampling and Automatic Rao-Blackwellization of Probabilistic Programs

Lawrence M. Murray, Daniel Lundén, Jan Kudlicka, David Broman, Thomas B. Schön

Abstract

We introduce a dynamic mechanism for the solution of analytically-tractable substructure in probabilistic programs, using conjugate priors and affine transformations to reduce variance in Monte Carlo inference. By delaying the sampling of random variables and maintaining a dynamic graph of their relationships, the system performs automatic Rao–Blackwellization, significantly reducing the variance of Sequential Monte Carlo (SMC) inference without requiring manual mathematical derivations from the user.

Introduction

Probabilistic programming languages (PPLs) allow researchers to define complex models using standard code constructs like loops, recursion, and branches. However, performing inference—estimating the hidden states of these models from data—is computationally expensive. The standard tool for this is Sequential Monte Carlo (SMC), specifically the "bootstrap particle filter." While easy to implement, it is often inefficient because it samples variables "blindly" from their priors.

Expert statisticians often improve this by "marginalizing out" certain variables analytically (a technique called Rao–Blackwellization) or by using "locally optimal proposals" that look ahead at the data. The challenge is that in a PPL, the model structure can change dynamically as the program runs. Manually deriving these optimizations for every possible execution path is nearly impossible. This paper seeks to automate these expert-level optimizations at runtime.

Methodology: Delayed Sampling

The authors propose a mechanism that changes how PPLs handle random variables. Instead of sampling a value immediately when a variable is defined (the assume statement), the system creates a node in a dynamic directed graph (specifically a forest of trees) where nodes are random variables and edges represent analytic relationships, such as conjugate priors or affine transformations.

This figure demonstrates how the system maintains and transforms a dynamic graph of random variables. Operations like 'Graft' and 'Marginalize' allow the system to propagate information and delay sampling until absolutely necessary.

Sampling is "delayed" until the very last moment—specifically, when the program needs a concrete number to proceed (e.g., for an if condition). The algorithm maintains a "marginalized path" (M-path) from the root of a tree to a terminal node. By carefully grafting and pruning these paths, the system ensures that information from observations is propagated backward through the graph before any sampling occurs. Because variables are kept in a marginalized state for as long as possible, the SMC algorithm effectively operates in a lower-dimensional space, which inherently reduces estimator variance.

Evaluation and Results

The approach was evaluated using a linear-nonlinear state-space model and real-world epidemiological data from a Dengue outbreak. The primary metric for success was the variance of the marginal log-likelihood estimate ($\log \hat{Z}$). Lower variance indicates more stable inference that requires fewer "particles" (simulated runs) to reach an accurate result.

Distributions of the marginal log-likelihood estimate across two different models. The dark gray bars (delayed sampling enabled) show much tighter clusters and higher accuracy with far fewer particles (N) compared to the light gray bars (disabled).

In the state-space model, delayed sampling significantly outperformed the standard bootstrap particle filter. Using only 64 particles with delayed sampling provided a more accurate and stable estimate than using 2048 particles without it. In the Dengue model, the reduction in variance was even more pronounced, enabling parameter estimation that would otherwise have been computationally prohibitive.

Conclusion and Future Work

Delayed Sampling provides a powerful, automated way to improve PPL inference efficiency by performing Rao-Blackwellization at runtime. While the current implementation requires the graph of analytic relationships to be a forest, it successfully recovers known analytical solutions in complex, branching programs. Future work aims to extend this mechanism to handle more complex joint dependencies and to apply it to other inference methods, such as generating collapsed Gibbs samplers for MCMC.

Summary updated

BibTeX
@inproceedings{murray2018delayed,
  author = {Lawrence M. Murray and Daniel Lundén and Jan Kudlicka and David Broman and Thomas B. Schön},
  title = {{Delayed Sampling and Automatic Rao-Blackwellization of Probabilistic Programs}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2018},
  url = {https://openreview.net/forum?id=ZusZ7YxbI2v},
}
Figure