Ratio of uniforms

The ratio of uniforms is a method initially proposed by Kinderman and Monahan in 1977 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


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, 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, 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

$$

$$

Rejection sampling in $$A_{f,r}$$
The above statement does not specify how one should perform the uniform sampling in $$A_{f,r}$$. However, the interest of this method is that under mild conditions on $$f$$ (namely that $$f(x_1, x_2, \ldots, x_d)^{\frac{1}{1+rd}}$$ and $$x_i f(x_1, x_2, \ldots, x_d)^\frac{r}{1+rd}$$ for all $$i$$ are bounded), $$A_{f,r}$$ is bounded. One can define the rectangular bounding box $$\tilde{A}_{f,r}$$ such that$$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]$$This allows to sample uniformly the set $$A_{f,r}$$ by rejection sampling inside $$\tilde{A}_{f,r}$$. The parameter $$r$$ can be adjusted to change the shape of $$A_{f,r}$$ and maximize the acceptance ratio of this sampling.

Parametric description of the boundary of $$A_{f,r}$$
The definition of $$A_{f,r}$$ 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:$$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$$or for the common case where $$X$$ is a 1-dimensional variable, $$(u, v) = \left(f(x)^\frac{1}{1+r}, x\,f(x)^\frac{r}{1+r}\right)$$.

Generalized ratio of uniforms
Here parameterized only with $$r$$, the ratio of uniforms can be described with a more general class of transformations.

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


 * $$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\}$$

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

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

We can start constructing the set $$A_{f,1}$$:


 * $$A_{f,1} = \left\{(u,v)\in\mathbb{R}^2:0\leq u\leq \sqrt{p\left(\frac{v}{u}\right)} \right\}$$

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

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

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



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

It is possible to optimize the acceptance ratio by adjusting the value of $$r$$, as seen on the graphs.

Software

 * The rust and Runuran contributed packages in R.