An Easy Rejection Sampling Baseline via Gradient Refined Proposals

Edward Raff, Mark McLean, James Holt

Abstract

Rejection sampling is a common tool for low dimensional problems ($d \leq 2$), often touted as an "easy" way to obtain valid samples from a distribution $f(\cdot)$ of interest. In practice it is non-trivial to apply, often requiring considerable mathematical effort to devise a good proposal distribution $g(\cdot)$ and select a supremum $C$. More advanced samplers require additional mathematical derivations, limitations on $f(\cdot)$, or even cross-validation, making them difficult to apply. We devise a new approximate baseline approach to rejection sampling that works with less information, requiring only a differentiable $f(\cdot)$ be specified, making it easier to use. We propose a new approach to rejection sampling by refining a parameterized proposal distribution with a loss derived from the acceptance threshold. In this manner we obtain comparable or better acceptance rates on current benchmarks by up to $7.3\times$, while requiring no extra assumptions or any derivations to use: only a differentiable $f(\cdot)$ is required. While approximate, the results are correct with high probability, and in all tests pass a distributional check. This makes our approach easy to use, reproduce, and efficacious.

Introduction

Rejection sampling is a fundamental technique for drawing samples from a complex target distribution $f(x)$. To implement it, one needs a simpler proposal distribution $g(x)$ and a constant $C$ such that $C \cdot g(x) \geq f(x)$ for all $x$. The efficiency of the sampler depends entirely on how well $C \cdot g(x)$ "hugs" the target $f(x)$; if the gap is large, the computational cost of rejected samples becomes prohibitive.

While rejection sampling is algorithmically simple, it is mathematically demanding. Users typically must manually derive $g(x)$ and $C$, which is difficult for bespoke or high-dimensional distributions. Existing "adaptive" samplers often require the target to be log-concave, have bounded support, or require complex mathematical derivations. Easy Rejection Sampling (ERS) aims to be a true baseline: just provide a differentiable function $f(x)$, and the system handles the rest.

Methods: Gradient Refined Proposals

The ERS pipeline consists of three automated steps:

  1. Initialization: The system automatically detects distribution characteristics like bounded support or multiple modes, using gradient-based optimization (FISTA) to find the "peaks" of the distribution to seed the proposal.
  2. Gaussian Mixture Model (GMM) Proposals: ERS utilizes a GMM as the proposal $g(x)$. GMMs are flexible enough to wrap around complex shapes while remaining simple to sample from efficiently.
  3. Gradient Refinement: Most prior work attempts to make $g(x)$ look like $f(x)$ by minimizing Mean Squared Error (MSE). However, MSE does not necessarily maximize the acceptance rate. Instead, ERS uses automatic differentiation to directly optimize the parameters of the GMM to minimize the ratio $f(x)/g(x)$.
Optimizing the ratio $f(x)/g(x)$ (green) leads to a much tighter bound and lower constant $C$ than minimizing MSE (orange).

By optimizing the ratio directly, ERS finds proposals that are significantly more efficient. The system uses a Softmax-weighted loss function on the log-ratios of both accepted and rejected samples, ensuring improvement across the entire domain.

Key Results

The authors evaluated ERS against several classic "hard" distributions, including the "Peakiness Problem" and "Dimension Scaling."

Robustness to Peakiness

In the "Peakiness" task, a parameter $a$ controls how "sharp" the distribution's peak is. As $a$ increases, most samplers fail because their proposals cannot adapt to the extreme narrowness of the target.

Acceptance rate of ERS remains stable as the target distribution becomes "peakier," whereas other methods fail.

As shown in the figure, ERS maintained a high acceptance rate (~70%) even as the distribution became extremely sharp, while competing methods (like NNARS and PRS) saw their efficiency crater to near 0%.

Scaling and Speed

  • Dimension Scaling: Like all rejection samplers, ERS struggles as dimensions increase. It remains most effective for $d \leq 3$, becoming statistically indistinguishable from simpler methods by $d=7$.
  • Massive Speedups: ERS achieved up to 7.3x higher acceptance rates than prior state-of-the-art adaptive samplers.
  • Hardware Acceleration: Implemented in JAX, the algorithm is vectorized and roughly 4x faster on a GPU compared to standard baselines, even before accounting for improved acceptance rates.

Conclusion

ERS provides a "turn-key" baseline for rejection sampling that requires significantly less human effort than traditional methods. While it is technically an "approximate" baseline because the scaling constant $C$ is estimated empirically, it passed all distributional checks in testing. This makes it a highly efficacious tool for low-dimensional sampling problems where ease of use and efficiency are paramount.

Summary updated

BibTeX
@inproceedings{raff2023easy,
  author = {Edward Raff and Mark McLean and James Holt},
  title = {{An Easy Rejection Sampling Baseline via Gradient Refined Proposals}},
  booktitle = {ECAI},
  year = {2023},
  doi = {10.3233/faia230483},
}
Figure