Reparameterization Gradient for Non-differentiable Models

Wonyeol Lee, Hangyeol Yu, Hongseok Yang

Stochastic Variational Inference (SVI) is a cornerstone of modern Bayesian machine learning, allowing us to approximate complex posterior distributions. However, optimizing the Evidence Lower Bound (ELBO) efficiently relies heavily on low-variance gradient estimators. The "reparameterization trick" is the gold standard here, but it comes with a significant limitation: it requires the model's density function to be differentiable.

This requirement excludes many real-world models, particularly those in probabilistic programming that utilize discrete choices or conditional logic (like if-then-else blocks). When differentiability fails, researchers typically fall back on the Score Function (or REINFORCE) estimator. While universally applicable, REINFORCE suffers from extremely high variance, making optimization slow and unstable.

This paper introduces a novel, unbiased gradient estimator that bridges this gap, bringing the low-variance benefits of reparameterization to non-differentiable probabilistic models.

Splitting the Gradient: Interior and Boundary

The authors propose a new estimator that decomposes the latent space into differentiable regions and their non-differentiable boundaries. The total gradient is calculated as the sum of two distinct parts:

  1. RepGrad (Interior): Within regions where the density is smooth and differentiable, the algorithm applies the standard reparameterization trick.
  2. BouContr (Boundary): At the boundaries where differentiability breaks down (e.g., the "edges" created by if statements), the algorithm employs a form of manifold sampling. This calculates how moving the variational parameters changes the contribution of that boundary to the overall objective.

A common misconception is that because these boundaries are "measure-zero" sets (infinitely thin), they can be safely ignored. However, the authors prove mathematically that ignoring these boundaries leads to biased gradients. The "Boundary Contribution" term is an essential correction factor. In fact, the standard reparameterization trick is simply a special case of their generalized theorem where this boundary contribution happens to be zero.

Experimental Validation

The method is particularly well-suited for probabilistic programming, where if statements naturally define the boundaries the algorithm needs to sample. The authors evaluated their estimator on three sequential data benchmarks:

  • temperature: A room temperature controller model with discrete on/off states (41-dimensional latent variable, 80 if statements).
  • textmsg: A model tracking message frequency with usage change-points (3-dimensional latent variable, 37 if statements).
  • influenza: A US mortality data model dependent on dominant virus types (37-dimensional latent variable, 24 if statements).

Key Results

ELBO Convergence Comparison
  • Massive Variance Reduction: The proposed estimator ("OURS") demonstrated variances several orders of magnitude smaller (sometimes $< 10^{-10}$ times) than the Score Function ("SCORE") estimator.
  • Superior Convergence: Across all benchmarks, the new estimator converged more stably and reached higher ELBO values than SCORE.
  • Bias Correction: The biased version ("REPARAM", which uses only the interior gradient and ignores boundaries) frequently converged to sub-optimal values. This empirically proves that the boundary term is practically necessary for accuracy.
  • Manageable Overhead: Despite the added complexity of manifold sampling, the implementation added less than a 1.72x overhead in computation time per iteration compared to the biased approach.

Limitations and Future Directions

While a significant step forward, the current implementation is optimized for "simple" affine (linear) boundaries. Handling highly non-linear or complex boundaries remains an open challenge. Additionally, the study focused primarily on normal distributions; extending this framework to other common distributions like Gamma, Dirichlet, or Beta is a key direction for future research. Finally, as the number of if statements grows, finding even more efficient ways to scale the surface integral computations will be crucial for larger models.

Summary updated

BibTeX
@inproceedings{lee2018reparameterization,
  author = {Wonyeol Lee and Hangyeol Yu and Hongseok Yang},
  title = {{Reparameterization Gradient for Non-differentiable Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=HJ-flOb_bS},
}
Figure