Ratio of uniforms

From HandWiki

The ratio of uniforms is a method initially proposed by Kinderman and Monahan in 1977[1] for pseudo-random number sampling, that is, for drawing random samples from a statistical distribution. Like rejection sampling and inverse transform sampling, it is an exact simulation method. The basic idea of the method is to use a change of variables to create a bounded set, which can then be sampled uniformly to generate random variables following the original distribution. One feature of this method is that the distribution to sample is only required to be known up to an unknown multiplicative factor, a common situation in computational statistics and statistical physics.

Motivation

The pdf of a bimodal statistical distribution is plotted on a graph. The distribution is only defined between −1.5 and 1.5. A rectangular bounding box is drawn around the graph of the function between the abscisses −1.5 and 1.5, and the y coordinates 0 and the maximum of the function. The box is split into two zones by the curve: below the curve is the acceptance region, and above it is the rejection region.
Rejection sampling of a bounded statistical distribution with finite support.

A convenient technique to sample a statistical distribution is rejection sampling. When the probability density function of the distribution is bounded and has finite support, one can define a bounding box around it (a uniform proposal distribution), draw uniform samples in the box and return only the x coordinates of the points that fall below the function (see graph). As a direct consequence of the fundamental theorem of simulation,[2] the returned samples are distributed according to the original distribution.

When the support of the distribution is infinite, it is impossible to draw a rectangular bounding box containing the graph of the function. One can still use rejection sampling, but with a non-uniform proposal distribution. It can be delicate to choose an appropriate proposal distribution,[3] and one also has to know how to efficiently sample this proposal distribution.

The method of the ratio of uniforms offers a solution to this problem, by essentially using as proposal distribution the distribution created by the ratio of two uniform random variables.

Statement

The statement and the proof are adapted from the presentation by Gobet[4]

Theorem — Let [math]\displaystyle{ X }[/math] be a multidimensional random variable with probability density function [math]\displaystyle{ p(x_1, x_2, \ldots, x_d) }[/math] on [math]\displaystyle{ \mathbb{R}^d }[/math]. The function [math]\displaystyle{ p }[/math] is only required to be known up to a constant, so we can assume that we only know [math]\displaystyle{ f }[/math] where [math]\displaystyle{ p(x_1, x_2, \ldots, x_d) = c f(x_1, x_2, \ldots, x_d) }[/math], with [math]\displaystyle{ c }[/math] a constant unknown or difficult to compute. Let [math]\displaystyle{ r\gt 0 }[/math], a parameter that can be adjusted as we choose to improve the properties of the method. We can define the set [math]\displaystyle{ A_{f,r} }[/math]:[math]\displaystyle{ A_{f,r} = \left\{(u, v_1, v_2, \ldots, v_d) \in \mathbb{R}^{d+1}: 0 \leq u \leq f\left(\frac{v_1}{u^r},\frac{v_2}{u^r}, \ldots,\frac{v_d}{u^r} \right)^{\frac{1}{1+rd}}\right\} }[/math]The Lebesgue measure of the set [math]\displaystyle{ A_{f,r} }[/math] is finite and equal to [math]\displaystyle{ \frac{1}{c\,(1+rd)} }[/math].

Furthermore, let [math]\displaystyle{ (U, V_1, V_2, \ldots, V_d) }[/math] be a random variable uniformly distributed on the set [math]\displaystyle{ A_{f,r} }[/math]. Then, [math]\displaystyle{ \left(\frac{V_1}{U^r}, \frac{V_2}{U^r}, \ldots, \frac{V_d}{U^r}\right) }[/math] is a random variable on [math]\displaystyle{ \mathbb{R}^d }[/math] distributed like [math]\displaystyle{ X }[/math].

Complements

Rejection sampling in [math]\displaystyle{ A_{f,r} }[/math]

The above statement does not specify how one should perform the uniform sampling in [math]\displaystyle{ A_{f,r} }[/math]. However, the interest of this method is that under mild conditions on [math]\displaystyle{ f }[/math] (namely that [math]\displaystyle{ f(x_1, x_2, \ldots, x_d)^{\frac{1}{1+rd}} }[/math] and [math]\displaystyle{ x_i f(x_1, x_2, \ldots, x_d)^\frac{r}{1+rd} }[/math] for all [math]\displaystyle{ i }[/math] are bounded), [math]\displaystyle{ A_{f,r} }[/math] is bounded. One can define the rectangular bounding box [math]\displaystyle{ \tilde{A}_{f,r} }[/math] such that[math]\displaystyle{ A_{f,r} \subset \tilde{A}_{f,r} = \left[0, \sup_{x_1, \ldots, x_d}{f(x_1, \ldots, x_d)^{\frac{1}{1+rd}}}\right] \times \prod_i \left[\inf_{x_1, \ldots, x_d}{x_i f(x_1, \ldots, x_d)^{\frac{r}{1+rd}}}, \sup_{x_1, \ldots, x_d}{x_i f(x_1, \ldots, x_d)^{\frac{r}{1+rd}}}\right] }[/math]This allows to sample uniformly the set [math]\displaystyle{ A_{f,r} }[/math] by rejection sampling inside [math]\displaystyle{ \tilde{A}_{f,r} }[/math]. The parameter [math]\displaystyle{ r }[/math] can be adjusted to change the shape of [math]\displaystyle{ A_{f,r} }[/math] and maximize the acceptance ratio of this sampling.

Parametric description of the boundary of [math]\displaystyle{ A_{f,r} }[/math]

The definition of [math]\displaystyle{ A_{f,r} }[/math] is already convenient for the rejection sampling step. For illustration purposes, it can be interesting to draw the set, in which case it can be useful to know the parametric description of its boundary:[math]\displaystyle{ u = f\left(x_1, x_2, \ldots, x_d \right)^\frac{1}{1+rd} \quad\text{and}\quad \forall i \in [|1, n|], v_i = x_i u^r }[/math]or for the common case where [math]\displaystyle{ X }[/math] is a 1-dimensional variable, [math]\displaystyle{ (u, v) = \left(f(x)^\frac{1}{1+r}, x\,f(x)^\frac{r}{1+r}\right) }[/math].

Generalized ratio of uniforms

Here parameterized only with [math]\displaystyle{ r }[/math], the ratio of uniforms can be described with a more general class of transformations.[5]

In the 1-dimensional case, if [math]\displaystyle{ g: \mathbb{R}^+\rightarrow\mathbb{R}^+ }[/math] is a strictly increasing and differentiable function such that [math]\displaystyle{ g(0) = 0 }[/math], then we can define [math]\displaystyle{ A_{f,g} }[/math] such that

[math]\displaystyle{ A_{f,g} = \left\{(u, v)\in\mathbb{R}^2: 0\leq u \leq g^{-1}\left[f\left(\frac{v}{g'(u)}\right)\right]\right\} }[/math]

If [math]\displaystyle{ (U, V) }[/math] is a random variable uniformly distributed in [math]\displaystyle{ A_{f,g} }[/math], then [math]\displaystyle{ \frac{V}{g'(U)} }[/math] is distributed with the density [math]\displaystyle{ p }[/math].

Examples

Exponential distribution before and after change of variables by the ratio of uniforms method. Top: graph of the exponential distribution on [math]\displaystyle{ \mathbb{R}^+ }[/math]. Bottom: the set [math]\displaystyle{ A_{f,1} }[/math] is represented in the space [math]\displaystyle{ (u, v) }[/math], inscribed in the bounding box [math]\displaystyle{ \tilde{A}_{f,1} }[/math]. The colored domains, of equal probability, were added to help the visual association of the corresponding domains of the transformed sets.

The exponential distribution

Assume that we want to sample the exponential distribution, [math]\displaystyle{ p(x) = \lambda \mathrm{e}^{-\lambda x} }[/math] with the ratio of uniforms method. We will take here [math]\displaystyle{ r = 1 }[/math].

We can start constructing the set [math]\displaystyle{ A_{f,1} }[/math]:

[math]\displaystyle{ A_{f,1} = \left\{(u,v)\in\mathbb{R}^2:0\leq u\leq \sqrt{p\left(\frac{v}{u}\right)} \right\} }[/math]

The condition [math]\displaystyle{ 0\leq u\leq \sqrt{p\left(\frac{v}{u}\right)} }[/math] is equivalent, after computation, to [math]\displaystyle{ 0\leq v\leq -\frac{u}{\lambda}\ln\frac{u^2}{\lambda} }[/math], which allows us to plot the shape of the set (see graph).

This inequality also allows us to determine the rectangular bounding box [math]\displaystyle{ \tilde{A}_{f,1} }[/math] where [math]\displaystyle{ A_{f,1} }[/math] is included. Indeed, with [math]\displaystyle{ g(u) = -\frac{u}{\lambda}\ln\frac{u^2}{\lambda} }[/math], we have [math]\displaystyle{ g\left(\sqrt{\lambda}\right) = 0 }[/math] and [math]\displaystyle{ g'\left(\frac{2}{\mathrm{e}\sqrt{\lambda}}\right) = 0 }[/math], from where [math]\displaystyle{ \tilde{A}_{f,1} = \left[0, \sqrt{\lambda}\right]\times\left[0, g\left(\frac{2}{\mathrm{e}\sqrt{\lambda}}\right)\right] }[/math].

From here, we can draw pairs of uniform random variables [math]\displaystyle{ U \sim \mathrm{Unif}\left(0, \sqrt{\lambda}\right) }[/math] and [math]\displaystyle{ V \sim \mathrm{Unif}\left(0, g\left(\frac{2}{\mathrm{e}\sqrt{\lambda}}\right)\right) }[/math] until [math]\displaystyle{ u \leq \sqrt{\lambda\,\mathrm{e}^{-\lambda\frac{v}{u}}} }[/math], and when that happens, we return [math]\displaystyle{ \frac{v}{u} }[/math], which is exponentially distributed.

Normal mixture distribution before and after change of variables by the ratio of uniforms method. Top: graph of the mixture distribution on [math]\displaystyle{ \mathbb{R} }[/math]. Bottom: the set [math]\displaystyle{ A_{f,r} }[/math] is represented for two different values of [math]\displaystyle{ r }[/math]. The solid lines on the top represent the de-transformation of the bounding boxes on the bottom. The solid lines on the bottom represent the locations of different values of [math]\displaystyle{ x }[/math] in the set.

A mixture of normal distributions

Consider the mixture of two normal distributions [math]\displaystyle{ \mathcal{D} = 0.6\,N(\mu=-1, \sigma=2)+0.4\,N(\mu=3, \sigma=1) }[/math]. To apply the method of the ratio of uniforms, with a given [math]\displaystyle{ r }[/math], one should first determine the boundaries of the rectangular bounding box [math]\displaystyle{ \tilde{A}_{f,r} }[/math] enclosing the set [math]\displaystyle{ A_{f,r} }[/math]. This can be done numerically, by computing the minimum and maximum of [math]\displaystyle{ u(x) = f(x)^\frac{1}{1+r} }[/math] and [math]\displaystyle{ v(x) = x\,f(x)^\frac{r}{1+r} }[/math] on a grid of values of [math]\displaystyle{ x }[/math]. Then, one can draw uniform samples [math]\displaystyle{ (u, v)\in \tilde{A}_{f,r} }[/math], only keep those that fall inside the set [math]\displaystyle{ A_{f,r} }[/math] and return them as [math]\displaystyle{ \frac{v}{u^r} }[/math].

It is possible to optimize the acceptance ratio by adjusting the value of [math]\displaystyle{ r }[/math], as seen on the graphs.

Software

  • The rust[6] and Runuran[7] contributed packages in R.

See also

References

  1. Kinderman, A. J.; Monahan, J. F. (September 1977). "Computer Generation of Random Variables Using the Ratio of Uniform Deviates". ACM Transactions on Mathematical Software 3 (3): 257–260. doi:10.1145/355744.355750. 
  2. Robert, Christian; Casella, George (2004) (in en). Monte Carlo Statistical Methods (2 ed.). Springer-Verlag. p. 47. ISBN 978-0-387-21239-5. https://www.springer.com/gp/book/9780387212395. 
  3. Martino, Luca; Luengo, David; Míguez, Joaquín (16 July 2013). "On the Generalized Ratio of Uniforms as a Combination of Transformed Rejection and Extended Inverse of Density Sampling". p. 13. arXiv:1205.0482 [stat.CO].
  4. GOBET, EMMANUEL (2020). MONTE-CARLO METHODS AND STOCHASTIC PROCESSES : from linear to non-linear.. [S.l.]: CRC PRESS. ISBN 978-0-367-65846-5. OCLC 1178639517. https://www.worldcat.org/oclc/1178639517. 
  5. Wakefield, J. C.; Gelfand, A. E.; Smith, A. F. M. (1 December 1991). "Efficient generation of random variates via the ratio-of-uniforms method" (in en). Statistics and Computing 1 (2): 129–133. doi:10.1007/BF01889987. ISSN 1573-1375. https://link.springer.com/article/10.1007/BF01889987. 
  6. Northrop, P. J. (2021), rust: Ratio-of-Uniforms Simulation with Transformation, https://CRAN.R-project.org/package=rust 
  7. Leydold, J.; Hörmann, W. (2021), Runuran: R Interface to the 'UNU.RAN' Random Variate Generators, https://CRAN.R-project.org/package=Runuran