Abstract
Hamiltonian Monte Carlo (HMC) is a powerful tool for inference in probabilistic programming but often fails when models contain discontinuities, such as those introduced by if-else statements. This paper introduces the Simple Probabilistic Programming Language (SPPL) and a specialized compiler designed to automatically detect these "cliffs" in the probability landscape. By leveraging Discontinuous HMC (DHMC), the system can efficiently sample from models with non-smooth densities. We demonstrate that DHMC performs comparably to optimized state-of-the-art samplers on mixture models, providing a path toward automated inference for complex, discrete-continuous hybrid models.
Introduction
Hamiltonian Monte Carlo (HMC) has become the "gold standard" for probabilistic programming languages (PPLs) like Stan and PyMC3. By treating probability density as a physical landscape and using gradients to guide a "rolling" particle, HMC explores high-dimensional spaces efficiently. However, this mechanism relies on the assumption of a smooth landscape.
In practice, many models incorporate discrete logic—such as conditional thresholds—that create sharp discontinuities or "cliffs" where gradients are undefined or change abruptly. When standard HMC encounters these boundaries, its performance degrades significantly, leading to low acceptance rates and inaccurate posterior estimates. While variants like Discontinuous HMC (DHMC) exist to handle these jumps, existing PPL compilers typically cannot automatically identify the location of these boundaries from source code.
Methodology
The proposed solution consists of a domain-specific language and a compiler architecture that unearths geometric information for the sampler.
SPPL: Simple Probabilistic Programming Language
The authors developed SPPL, a Lisp-style language restricted to first-order operations. By limiting primitives to analytic functions (e.g., exp, +) and specific control flow structures, the language guarantees that the resulting probability density is "piecewise smooth." This ensures that the set of points where the density is discontinuous has a Lebesgue measure of zero, a critical requirement for valid MCMC inference.
Automated Predicate Tracking
The core innovation lies in the compilation scheme. Instead of merely calculating density, the compiler instruments the code to track "predicates"—the conditions within if statements. Each condition is assigned a unique identifier. At runtime, the system monitors these predicates; if a random variable's trajectory causes a condition to flip (e.g., from true to false), the system flags a "boundary crossing."
DHMC Integration
This boundary information is passed to a DHMC sampler. Unlike standard HMC, DHMC can "reflect" or "refract" off these boundaries, analogous to light interacting with a prism. This allows the sampler to maintain high efficiency even when navigating non-smooth spaces.
Experimental Evaluation
The approach was evaluated using a Gaussian Mixture Model (GMM) task, which is a classic example of a model with latent discrete variables (cluster assignments). In SPPL, these assignments are represented via if statements, creating the discontinuities the paper addresses. The task involved estimating cluster means and assignments for a synthetic dataset of 10 points.
Results
The researchers compared an unoptimized DHMC implementation against a highly optimized version of the No-U-Turn Sampler (NUTS) combined with Metropolis-within-Gibbs (MwG), as implemented in PyMC3.
As shown in the figure above, the DHMC approach achieved performance parity with the state-of-the-art NUTS-MwG baseline. The Mean Squared Error (MSE) for the posterior estimates of cluster means decreased consistently as the sample size increased, following a nearly identical trajectory to the optimized baseline. This demonstrates that by providing the sampler with boundary information, DHMC can handle mixture models effectively without the manual marginalization typically required in other PPLs.
Conclusion and Future Work
This work shifts the burden of handling discontinuities from the user to the compiler. By automatically "unearthing" boundary information, it enables the use of efficient samplers like DHMC on a wider class of models.
Future research directions include improving the runtime checker to analytically solve for exact boundary intersection points and expanding the SPPL language to include recursion and general function application while maintaining piecewise smoothness guarantees. Further optimization of the DHMC compiler is expected to yield significant performance gains over current hybrid sampling methods.
Summary updated