Manuscript Offprint

arXiv:2610.10792

Bayes Rule for Conditioning Probabilistic Programs

Feras A. Saad

FERAS A. SAAD, Carnegie Mellon University, USA

Probabilistic programs provide a rigorous programming-language foundation for expressing rich probabilistic models and offer language-level support for solving challenging statistical inference problems. A key theoretical challenge that probabilistic programs inherit from probability theory is conditioning a probability distribution on an observation that has probability zero. Many languages address this challenge by using computational rules for conditioning that may work well for some problems but are statistically unsound for others.

This article introduces a principled mathematical approach for conditioning probabilistic programs. We first show that existing techniques based on “soft conditioning” and “neighborhood limits” exhibit semantic issues from the perspective of measure theory and produce inference results that disagree with sound statistical reasoning. By leveraging tools from geometric measure theory, we construct a novel disintegration-based semantics for probabilistic program traces that enables sound conditioning. The theory delivers an explicit Bayes rule representation of the conditional distribution, which is directly compatible with widely used probabilistic inference algorithms that require access to unnormalized posterior densities. Our Bayes rule handles probabilistic models with loops, branches, discrete, continuous, and mixed-type distributions, observations on manifolds, differentiable structure, and additional modeling motifs that arise in practice.

1 Introduction

Probabilistic programs are standard computer programs augmented with a construct to sample random variables from probability distributions. These languages can be used to model and analyze complex probabilistic processes, and have been thoroughly studied by the programming languages community [Barthe et al. 2020]. Within this field is an important class of languages for statistical probabilistic programming, which enjoy broad adoption among the machine learning, statistics, and data science communities [van de Meent et al. 2021]. Statistical probabilistic programs include an additional construct to observe random variables taking on particular values, which conditions the probability distribution induced by the sample statements to agree with a set of constraints. These systems provide sophisticated probabilistic inference engines to solve statistical problems, such as generating samples from the conditional distribution or estimating conditional expectations.

The goal of this paper is to build a rigorous mathematical foundation for conditioning probabilistic programs that aligns with principled statistical theory. To illustrate the fundamental challenge, consider a hidden random variable X and an observable random variable Z. For discrete random variables, the conditional distribution of X∣Z=zX \mid Z = z is given by the usual Bayes rule:

P[X=x∣Z=z]=P[X=x,Z=z]P[Z=z],(1)\mathbb{P}[X=x\mid Z=z]=\frac{\mathbb{P}[X=x,Z=z]}{\mathbb{P}[Z=z]}, \tag{1}

which is well-defined whenever P[Z=z]>0\mathbb{P}[Z = z] > 0. For discrete probability, this theory is complete: any semantics for discrete probabilistic programs can safely ignore probability-zero observations, because conditioning on zz for which P[Z=z]=0\mathbb{P}[Z = z] = 0 is statistically undefined without controversy.

Real-world applications, however, demand the use of continuous random variables such as the normal, uniform, or gamma, which take on uncountably many outcomes. In this case, every observation z satisfies P[Z=z]=0\mathbb{P}[Z = z] = 0, which rules out the use of the standard Bayes rule. This challenge with conditioning on probability-zero events has a long history in probability theory.

Modern probabilistic programming languages use variants of the Bayes rules to condition on probability-zero events, which can be problematic. The first issue is semantic: while the computational behavior of the program is fully precise, the inference problem being solved may have no reasonable statistical interpretation. The second issue is practical: because inference algorithms such as importance sampling, variational inference, and Markov chain Monte Carlo all make use of unnormalized target distributions, using ad-hoc Bayes rules can give unsound statistical results.

Feras A. Saad

References (40)