Beyond Bayesian Model Averaging over Paths in Probabilistic Programs with Stochastic Support

Tim Reichelt, Luke Ong, Tom Rainforth

Introduction

Universal Probabilistic Programming Systems (PPS), such as Pyro and Turing, provide a powerful framework for modeling complex systems by allowing the number and type of latent variables to vary based on stochastic outcomes—a property known as stochastic support. While this flexibility is a hallmark of universal PPS, it introduces a subtle but significant behavior: programs with branching logic implicitly perform Bayesian Model Averaging (BMA) over their execution paths. This paper, presented at AISTATS 2024, investigates the limitations of this implicit BMA and proposes a more robust alternative based on stacking.

The Problem: Fragility of BMA in Branching Programs

In a PPS, any program with branching logic can be decomposed into a weighted sum of "Straight-Line Programs" (SLPs), each representing a unique execution path. Current inference engines typically weight these paths by their marginal likelihoods, which is the defining characteristic of BMA.

However, BMA is known to be fragile under model misspecification. When the true data-generating process is not perfectly captured by any single path, BMA weights tend to "collapse" onto the single path with the highest evidence. This leads to overconfident predictions and high sensitivity to minor data perturbations. If the "best" path changes between datasets, the model's predictive performance becomes unstable.

Methodology: Stacking for PPS

To address these issues, the authors propose moving beyond BMA by optimizing path weights for predictive performance rather than theoretical evidence. The proposed method, "Stacking for PPS," involves the following steps:

  1. Mixture Modeling: SLPs are treated as components of a mixture model.
  2. Weight Optimization: Instead of marginal likelihood, weights are optimized to maximize the Log Posterior Predictive Density (LPPD) on held-out data.
  3. Efficient Cross-Validation: To avoid the need for a separate validation set, the method utilizes Pareto Smoothed Importance Sampling Leave-One-Out (PSIS-LOO) cross-validation. This allows for an estimate of predictive performance using only the training data.
  4. Regularization: A PAC-Bayes inspired regularization term is introduced to prevent overfitting, particularly in models with a large number of paths.

This approach is implemented as a computationally efficient post-processing step. Standard inference is performed once, samples are grouped by their execution paths, and a small convex optimization problem is solved to determine the optimal weights.

Experimental Evaluation

The researchers evaluated the stacking approach across a variety of synthetic and real-world tasks, including toy scenarios designed to isolate BMA failure modes, subset regression, function induction using PCFGs, and several real-world datasets like California Housing and Radon contamination.

Figure 1: Comparison of BMA and Stacking weights across three toy scenarios: Distinct SLPs, SLPs with Overlap, and Dominant SLP. The top row illustrates how BMA weights (blue) often collapse to the extremes (0 or 1), while Stacked weights (red) remain more central and robust. The bottom row shows that Stacking consistently achieves better (more negative) LPPD differences compared to BMA.

Key findings from these experiments include:

  • Improved Predictive Performance: In nearly all test cases, stacking outperformed BMA in terms of LPPD. In the subset regression task, stacking significantly exceeded the performance of both standard BMA and analytic BMA solutions.
  • Enhanced Weight Stability: In complex models like the Radon hierarchical model, BMA weights were highly unstable across different data splits. Stacking weights provided much more consistent modeling choices.
  • Computational Efficiency: The stacking optimization is remarkably fast, often taking less than a second, even when the initial inference takes several minutes.

Discussion and Conclusion

The realization that branching logic in PPS implies BMA is a critical insight for the field. By replacing implicit BMA with a stacking-based post-processing step, practitioners can achieve more robust and accurate predictions without significant computational overhead.

Future work remains in automating path identification through static analysis and scaling the method to programs with recursive logic or an exceptionally large number of execution paths. Nonetheless, stacking represents a significant step forward in making universal probabilistic programming more reliable for real-world applications.

Summary updated

BibTeX
@inproceedings{reichelt2024beyond,
  author = {Tim Reichelt and Luke Ong and Tom Rainforth},
  title = {{Beyond Bayesian Model Averaging over Paths in Probabilistic Programs with Stochastic Support}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2024},
}
Figure