Stochastically Differentiable Probabilistic Programs

David Tolpin, Yuan Zhou, Hongseok YangarXiv 2020 · OpenReview

TL;DR

This paper introduces "stochastically differentiable probabilistic programs" (SDPPs) to enable efficient gradient-based inference in models with both continuous and discrete latent variables. Their novel approach uses stochastic gradient Markov Chain Monte Carlo (sgMCMC) to achieve robust inference, outperforming existing methods in terms of speed and effectiveness.

What Problem Does This Paper Address?

Probabilistic programming systems (PPSs) are powerful tools for defining and reasoning about statistical models. However, many real-world models involve a mix of continuous (e.g., parameters of a distribution) and discrete (e.g., assignments to clusters) latent variables. This mixture poses a significant challenge for standard inference algorithms, particularly gradient-based methods like Hamiltonian Monte Carlo (HMC). These methods typically require the model to be differentiable with respect to all latent variables.

Existing solutions to this problem are often cumbersome:

  • Manual Marginalization: Users must analytically remove the discrete variables, which is often intractable or requires significant effort.
  • Composing Inference: Separate inference engines are used for discrete and continuous variables (e.g., MCMC for discrete, HMC for continuous). This can lead to poor mixing and inefficiency, especially in complex models.

The paper aims to bridge this gap by providing a unified, automated, and efficient inference approach for models with mixed continuous and discrete latent variables.

Methods

The core contribution is the concept of stochastically differentiable probabilistic programs (SDPPs). An SDPP is a probabilistic program where the probability of its trace is differentiable with respect to the continuous variables in the trace, even though the program itself might contain discrete, non-differentiable random variables (referred to as "nuisance variables").

To perform inference on SDPPs, the authors derive an unbiased stochastic estimator for the gradient of the marginal log-likelihood. This estimator is crucial because it allows the use of gradient-based methods. The key idea is to leverage the fact that the gradient of the log-likelihood of the joint distribution (including nuisance variables) can be used to approximate the gradient of the marginal log-likelihood. This is achieved through a Monte Carlo approximation, where nuisance variables are sampled.

The paper then adapts stochastic gradient Hamiltonian Monte Carlo (sgHMC) to work with these stochastic gradient estimates. sgHMC is a variant of HMC that uses noisy gradient estimates, making it suitable for large datasets or models where exact gradients are expensive to compute. The proposed method uses a single sample of the nuisance variables to compute the gradient for each sgHMC step.

Datasets

The paper does not introduce new datasets. Instead, it uses three standard probabilistic models as case studies for evaluation:

  • Compensation Survey (a simple mixture model)
  • Gaussian Mixture Model (GMM)
  • Hidden Markov Model (HMM)

For each model, they create both a "stochastic" (mixed support) and a "marginalized" (deterministic) version. They also compare their results against a Stan implementation of the marginalized models.

Key Insights and Ideas

  • Unified Inference for Mixed Models: The most significant insight is that by treating models with discrete nuisance variables as "stochastically differentiable," we can unlock efficient gradient-based inference without manual marginalization.
  • Gradient Estimation is Key: The ability to derive an unbiased stochastic gradient estimator for the marginal log-likelihood is the technical lynchpin. This allows gradient-based methods to "see through" the discrete variables.
  • sgHMC as a Natural Fit: sgHMC, designed for noisy gradients, is a natural and effective choice for inference in SDPPs, as the gradient estimates are inherently stochastic.
  • Poorer Mixing of Composing Inference: The paper highlights a critical limitation of composing inference (separate MCMC for discrete, HMC for continuous). When HMC is conditioned on a fixed discrete variable, it can get stuck in one mode of a multimodal posterior, leading to poor mixing and slow exploration. SDPPs with sgHMC avoid this by re-sampling the discrete variable at each gradient step.

Key Results

The paper presents empirical results from case studies on three models, comparing their proposed sgHMC approach with:

  1. sgHMC with a single-sample gradient estimate (their main proposal).
  2. sgHMC with a 10-sample gradient estimate (to reduce gradient noise).
  3. A combination of MCMC (Metropolis-Hastings) for discrete variables and HMC for continuous variables (composing inference).
  4. HMC on the manually marginalized model.

Key findings include:

  • Effective Sample Size (ESS): sgHMC with a single-sample gradient achieved an ESS comparable to, and sometimes better than, HMC on the marginalized model. It significantly outperformed the MCMC+HMC composing inference method, which had substantially lower ESS.
  • Computation Time: sgHMC was considerably faster than HMC on the marginalized model (2.5-4.5 times faster) and also faster than the MCMC+HMC approach. This is attributed to the overhead of manual marginalization and the computational cost of certain operations (like LogSumExp) in the marginalized versions.
  • Effective Sample Size per Second: When combining ESS and computation time, sgHMC with a single-sample gradient estimate demonstrated the best performance, often achieving 2-4 times higher effective sample size per second compared to HMC on the marginalized model.

Limitations and Future Work

  • Limitations:
    • The paper focuses on models where the trace is differentiable with respect to continuous variables, and discrete variables are "nuisance" variables that can be sampled. Models where the structure of the trace itself depends dynamically on discrete variables might require different approaches.
  • While sgHMC with a single sample is efficient, it has higher gradient variance. Using multiple samples for the gradient estimate (as shown in their experiments) reduces variance but increases computation time, leading to a trade-off.
  • Future Work:
    • Investigating maximum a posteriori (MAP) estimation in SDPPs.
  • Exploring other stochastic gradient-based inference algorithms and their adaptation to SDPPs.
  • Integrating support for SDPPs into existing probabilistic programming frameworks.
  • Developing more sophisticated methods for handling models where the program structure is dynamic.

Summary updated

Abstract

Probabilistic programs with mixed support (both continuous and discrete latent random variables) commonly appear in many probabilistic programming systems (PPSs). However, the existence of the discrete random variables prohibits many basic gradient-based inference engines, which makes the inference procedure on such models particularly challenging. Existing PPSs either require the user to manually marginalize out the discrete variables or to perform a composing inference by running inference separately on discrete and continuous variables. The former is infeasible in most cases whereas the latter has some fundamental shortcomings. We present a novel approach to run inference efficiently and robustly in such programs using stochastic gradient Markov Chain Monte Carlo family of algorithms. We compare our stochastic gradient-based inference algorithm against conventional baselines in several important cases of probabilistic programs with mixed support, and demonstrate that it outperforms existing composing inference baselines and works almost as well as inference in marginalized versions of the programs, but with less programming effort and at a lower computation cost.
BibTeX
@misc{tolpin2020stochastically,
  author = {David Tolpin and Yuan Zhou and Hongseok Yang},
  title = {{Stochastically Differentiable Probabilistic Programs}},
  year = {2020},
  eprint = {2003.00704},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.00704},
}
Figure