Introduction
Probabilistic programming enables the specification of complex models as code. However, performing exact inference—calculating the marginal probability of outcomes—remains a significant challenge, particularly for programs involving stochastic recursion or low-probability events. Traditional sampling-based methods, such as Markov Chain Monte Carlo (MCMC) and Rejection Sampling, often struggle with these scenarios, leading to high variance or infinite loops in recursive contexts. This paper presents a dynamic programming (DP) approach that serves as a "universal marginalizer" for discrete probabilistic programs.
Methodology: Factored Sum-Product Networks
The core of the proposed method is the compilation of probabilistic programs into Factored Sum-Product Networks (FSPNs). Unlike standard Sum-Product Networks, FSPNs can contain cycles to represent recursive function calls.
The inference process involves two main stages:
- Compilation: A functional interpreter intercepts program calls to build the FSPN. Sum nodes represent probabilistic choices, product nodes represent independent sub-computations, and reference nodes handle recursion by pointing back to existing network components.
- Solving: The network is partitioned into Strongly Connected Components (SCCs) and solved in topological order. For cyclic components, the algorithm employs fixed-point iteration or Newton’s method to find numerical solutions for the recursive dependencies.
Experimental Evaluation
The DP algorithm was evaluated against traditional sampling methods across several challenging models.
Convergence and Precision
In the "Rope-Pulling Game" model, which involves low-probability conditions, the DP algorithm achieved exact results significantly faster than sampling-based alternatives.
As shown in Figure 2, while Rejection Sampling and MCMC exhibit high error that decreases slowly over time, the DP approach provides a precise solution once the computation is complete, demonstrating superior efficiency for rare-event inference.
Recursive Reasoning and Multi-Agent Logic
The method was also tested on recursive language models from cognitive science. In these models, a listener reasons about a speaker who in turn reasons about the listener. The DP approach demonstrated linear scaling with the depth of recursive reasoning, whereas sampling methods typically scale exponentially in such nested contexts.
Additionally, the algorithm successfully solved the "Blue-Eyed Islanders" puzzle, a classic logic problem involving deeply nested conditioning and multi-agent reasoning over time. This task is often considered intractable for generic samplers due to the complexity of the state space and the nature of the conditioning.
Conclusion and Future Work
The introduced dynamic programming algorithm provides a robust framework for exact inference in discrete probabilistic programs, effectively handling stochastic recursion and rare events. By transforming programs into solvable systems of equations, it avoids the pitfalls of sampling in complex recursive structures. Future work will focus on extending this framework to continuous variables and optimizing the solver for even larger state spaces.
Summary updated