Fast inverse transform sampling in one and two dimensions

Sheehan Olver, Alex Townsend · DOI

Abstract

We develop a computationally efficient and robust algorithm for generating pseudo-random samples from a broad class of smooth probability distributions in one and two dimensions. The algorithm is based on inverse transform sampling with a polynomial approximation scheme using Chebyshev polynomials, Chebyshev grids, and low rank function approximation. Numerical experiments demonstrate that our algorithm outperforms existing approaches.

Introduction

Generating pseudo-random samples from a specific probability distribution is a foundational task in statistics, physics, and computing. The theoretical "gold standard" for this task is inverse transform sampling (ITS). If a cumulative distribution function (CDF) $F(x)$ is available, one can generate a sample by taking a uniform random number $U \in [0,1]$ and calculating $F^{-1}(U)$.

However, conventional wisdom in computational statistics suggests that ITS is often impractical in higher dimensions or for complex functions. Approximating the inverse CDF globally is computationally expensive, numerically unstable, and difficult to scale. Consequently, researchers often rely on slower or more complex alternatives like rejection sampling (RS) or slice sampling (SS). This paper challenges that status quo by demonstrating that with modern numerical tools, inverse transform sampling is not only practical but often superior to standard library routines.

Methodology

The proposed algorithm leverages two key numerical techniques to make ITS efficient and robust:

  1. Chebyshev Polynomials (1D): Instead of working with a raw PDF, the algorithm approximates it using Chebyshev polynomials. For smooth functions, these approximations exhibit "superalgebraic" convergence, providing near machine-precision accuracy with very few terms. The CDF is then obtained through simple integration of the polynomial representation.
  2. Low-Rank Approximation (2D): To extend the method to two dimensions without encountering the "curse of dimensionality," the 2D PDF $f(x, y)$ is decomposed into a sum of products of 1D functions: $f(x, y) \approx \sum_{j=1}^k \sigma_j r_j(x) c_j(y)$. This is achieved via a fast Gaussian elimination-like process implemented in the Chebfun2 software package.

Rather than constructing a global inverse CDF, which can be numerically singular, the algorithm uses a robust bisection method to solve $F(x) = U$ pointwise for each sample. Because the polynomial representation is extremely fast to evaluate, this pointwise inversion is highly efficient.

Experimental Evaluation

The algorithm was evaluated on several challenging synthetic distributions, including multimodal densities and spectral densities from random matrix theory. In 2D, complex shapes such as the "butterfly" density were used to test the low-rank approximation approach.

Sampling results for 1D multimodal and 2D butterfly distributions.

As shown in the figure above, the generated samples perfectly match the target multimodal PDF in 1D and accurately capture the complex contours of the 2D butterfly distribution.

Key Results

The proposed ITS method was compared against MATLAB’s slicesample (SS) and standard Rejection Sampling (RS). In 1D benchmarks, ITS was consistently 10–20 times faster than slice sampling.

A critical advantage of the ITS approach is its performance on "peaky" or highly concentrated distributions. In such cases, rejection sampling becomes highly inefficient as the acceptance rate drops. In contrast, the authors' method maintains a nearly constant computational cost regardless of the distribution's concentration.

Performance comparison between the proposed method (dashed red) and rejection sampling (solid blue) as distribution concentration increases.

As illustrated in the performance plots, as the concentration parameter $\omega$ increases, the time and function evaluations required by rejection sampling grow linearly, while the proposed ITS method remains stable and significantly faster.

Discussion and Limitations

The success of this method relies on the assumption of smoothness, which allows for efficient Chebyshev approximation and Fast Cosine Transforms ($O(n \log n)$ setup). While extensions for piecewise smooth functions are possible, they require additional preprocessing.

Furthermore, while the 2D case is elegantly handled via low-rank matrices, scaling to 3D and higher dimensions would require low-rank tensor approximations. This represents a significant increase in complexity and is a primary focus for future research. Finally, the method involves an initial construction cost for the polynomial approximation; for a very small number of samples, the overhead of this setup might outweigh the per-sample speed gains. However, for large-scale sampling from smooth distributions, this approach represents a new state-of-the-art.

Summary updated

BibTeX
@misc{olver2013fast,
  author = {Sheehan Olver and Alex Townsend},
  title = {{Fast inverse transform sampling in one and two dimensions}},
  year = {2013},
  eprint = {1307.1223},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1307.1223},
}
Figure