Misplaced Pages

Ratio of uniforms

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

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

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

Theorem — Let X {\displaystyle X} be a multidimensional random variable with probability density function p ( x 1 , x 2 , , x d ) {\displaystyle p(x_{1},x_{2},\ldots ,x_{d})} on R d {\displaystyle \mathbb {R} ^{d}} . The function p {\displaystyle p} is only required to be known up to a constant, so we can assume that we only know f {\displaystyle f} where p ( x 1 , x 2 , , x d ) = c f ( x 1 , x 2 , , x d ) {\displaystyle p(x_{1},x_{2},\ldots ,x_{d})=cf(x_{1},x_{2},\ldots ,x_{d})} , with c {\displaystyle c} a constant unknown or difficult to compute. Let r > 0 {\displaystyle r>0} , a parameter that can be adjusted as we choose to improve the properties of the method. We can define the set A f , r {\displaystyle A_{f,r}} : A f , r = { ( u , v 1 , v 2 , , v d ) R d + 1 : 0 u f ( v 1 u r , v 2 u r , , v d u r ) 1 1 + r d } {\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\}} The Lebesgue measure of the set A f , r {\displaystyle A_{f,r}} is finite and equal to 1 c ( 1 + r d ) {\displaystyle {\frac {1}{c\,(1+rd)}}} .

Furthermore, let ( U , V 1 , V 2 , , V d ) {\displaystyle (U,V_{1},V_{2},\ldots ,V_{d})} be a random variable uniformly distributed on the set A f , r {\displaystyle A_{f,r}} . Then, ( V 1 U r , V 2 U r , , V d U r ) {\displaystyle \left({\frac {V_{1}}{U^{r}}},{\frac {V_{2}}{U^{r}}},\ldots ,{\frac {V_{d}}{U^{r}}}\right)} is a random variable on R d {\displaystyle \mathbb {R} ^{d}} distributed like X {\displaystyle X} .

Proof

We will first assume that the first statement is correct, i.e. | A f , r | = 1 c ( 1 + r d ) {\displaystyle |A_{f,r}|={\frac {1}{c\,(1+rd)}}} .

Let φ {\displaystyle \varphi } be a measurable function on R d {\displaystyle \mathbb {R} ^{d}} . Let's consider the expectation of φ ( V 1 U r , , V d U r ) {\displaystyle \varphi \left({\frac {V_{1}}{U^{r}}},\ldots ,{\frac {V_{d}}{U^{r}}}\right)} on the set A f , r {\displaystyle A_{f,r}} :

E [ φ ( V 1 U r , , V d U r ) ] = 1 | A f , r | φ ( v 1 u r , , v d u r ) 1 ( u , v 1 , , v d ) A f , r d u d v 1 d v d {\displaystyle E\left={\frac {1}{|A_{f,r}|}}\int _{-\infty }^{\infty }\int _{-\infty }^{\infty }\cdots \int _{-\infty }^{\infty }\varphi \left({\frac {v_{1}}{u^{r}}},\ldots ,{\frac {v_{d}}{u^{r}}}\right)\mathbf {1} _{(u,v_{1},\ldots ,v_{d})\in A_{f,r}}\mathrm {d} u\,\mathrm {d} v_{1}\ldots \mathrm {d} v_{d}}

With the change of variables x i = v i u r {\displaystyle x_{i}={\frac {v_{i}}{u^{r}}}} , we have

E [ φ ( V 1 U r , , V d U r ) ] = 1 | A f , r | φ ( x 1 , , x d ) 1 0 u f ( x 1 , , x d ) 1 1 + r d u r d d u d x 1 d x d = 1 | A f , r | φ ( x 1 , , x d ) 1 1 + r d f ( x 1 , , x d ) d x 1 d x d = φ ( x 1 , , x d ) p ( x 1 , , x d ) d x 1 d x d {\displaystyle {\begin{aligned}E\left&={\frac {1}{|A_{f,r}|}}\int _{-\infty }^{\infty }\int _{-\infty }^{\infty }\cdots \int _{-\infty }^{\infty }\varphi (x_{1},\ldots ,x_{d})\mathbf {1} _{0\leq u\leq f(x_{1},\ldots ,x_{d})^{\frac {1}{1+rd}}}u^{rd}\mathrm {d} u\,\mathrm {d} x_{1}\cdots \mathrm {d} x_{d}\\&={\frac {1}{|A_{f,r}|}}\int _{-\infty }^{\infty }\cdots \int _{-\infty }^{\infty }\varphi \left(x_{1},\ldots ,x_{d}\right){\frac {1}{1+rd}}f\left(x_{1},\ldots ,x_{d}\right)\mathrm {d} x_{1}\cdots \mathrm {d} x_{d}\\&=\int _{-\infty }^{\infty }\ldots \int _{-\infty }^{\infty }\varphi \left(x_{1},\ldots ,x_{d}\right)p\left(x_{1},\ldots ,x_{d}\right)\mathrm {d} x_{1}\cdots \mathrm {d} x_{d}\end{aligned}}}

where we can see that ( V 1 U r , , V d U r ) {\displaystyle \left({\frac {V_{1}}{U^{r}}},\ldots ,{\frac {V_{d}}{U^{r}}}\right)} has indeed the density p {\displaystyle p} .

Coming back to the first statement, a similar argument shows that | A f , r | = 1 c ( 1 + r d ) {\displaystyle |A_{f,r}|={\frac {1}{c\,(1+rd)}}} .

Complements

Rejection sampling in A f , r {\displaystyle A_{f,r}}

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

Parametric description of the boundary of A f , r {\displaystyle A_{f,r}}

The definition of A f , r {\displaystyle 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 ( x 1 , x 2 , , x d ) 1 1 + r d and i [ | 1 , n | ] , v i = x i u r {\displaystyle u=f\left(x_{1},x_{2},\ldots ,x_{d}\right)^{\frac {1}{1+rd}}\quad {\text{and}}\quad \forall i\in ,v_{i}=x_{i}u^{r}} or for the common case where X {\displaystyle X} is a 1-dimensional variable, ( u , v ) = ( f ( x ) 1 1 + r , x f ( x ) r 1 + r ) {\displaystyle (u,v)=\left(f(x)^{\frac {1}{1+r}},x\,f(x)^{\frac {r}{1+r}}\right)} .

Generalized ratio of uniforms

Above parameterized only with r {\displaystyle r} , the ratio of uniforms can be described with a more general class of transformations in terms of a transformation g. In the 1-dimensional case, if g : R + R + {\displaystyle g:\mathbb {R} ^{+}\rightarrow \mathbb {R} ^{+}} is a strictly increasing and differentiable function such that g ( 0 ) = 0 {\displaystyle g(0)=0} , then we can define A f , g {\displaystyle A_{f,g}} such that

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

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

Examples

Exponential distribution before and after change of variables by the ratio of uniforms method. Top: graph of the exponential distribution on R + {\displaystyle \mathbb {R} ^{+}} . Bottom: the set A f , 1 {\displaystyle A_{f,1}} is represented in the space ( u , v ) {\displaystyle (u,v)} , inscribed in the bounding box A ~ f , 1 {\displaystyle {\tilde {A}}_{f,1}} . 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, p ( x ) = λ e λ x {\displaystyle p(x)=\lambda \mathrm {e} ^{-\lambda x}} with the ratio of uniforms method. We will take here r = 1 {\displaystyle r=1} .

We can start constructing the set A f , 1 {\displaystyle A_{f,1}} :

A f , 1 = { ( u , v ) R 2 : 0 u p ( v u ) } {\displaystyle 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 u p ( v u ) {\displaystyle 0\leq u\leq {\sqrt {p\left({\frac {v}{u}}\right)}}} is equivalent, after computation, to 0 v u λ ln u 2 λ {\displaystyle 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 A ~ f , 1 {\displaystyle {\tilde {A}}_{f,1}} where A f , 1 {\displaystyle A_{f,1}} is included. Indeed, with g ( u ) = u λ ln u 2 λ {\displaystyle g(u)=-{\frac {u}{\lambda }}\ln {\frac {u^{2}}{\lambda }}} , we have g ( λ ) = 0 {\displaystyle g\left({\sqrt {\lambda }}\right)=0} and g ( λ e ) = 0 {\displaystyle g'\left({\frac {\sqrt {\lambda }}{\mathrm {e} }}\right)=0} , from where A ~ f , 1 = [ 0 , λ ] × [ 0 , 2 e λ ] {\displaystyle {\tilde {A}}_{f,1}=\left\times \left} .

From here, we can draw pairs of uniform random variables U U n i f ( 0 , λ ) {\displaystyle U\sim \mathrm {Unif} \left(0,{\sqrt {\lambda }}\right)} and V U n i f ( 0 , 2 e λ ) {\displaystyle V\sim \mathrm {Unif} \left(0,{\frac {2}{\mathrm {e} {\sqrt {\lambda }}}}\right)} until u λ e λ v u {\displaystyle u\leq {\sqrt {\lambda \,\mathrm {e} ^{-\lambda {\frac {v}{u}}}}}} , and when that happens, we return v u {\displaystyle {\frac {v}{u}}} , 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 R {\displaystyle \mathbb {R} } . Bottom: the set A f , r {\displaystyle A_{f,r}} is represented for two different values of r {\displaystyle r} . 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 x {\displaystyle x} in the set.

A mixture of normal distributions

Consider the mixture of two normal distributions D = 0.6 N ( μ = 1 , σ = 2 ) + 0.4 N ( μ = 3 , σ = 1 ) {\displaystyle {\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 {\displaystyle r} , one should first determine the boundaries of the rectangular bounding box A ~ f , r {\displaystyle {\tilde {A}}_{f,r}} enclosing the set A f , r {\displaystyle A_{f,r}} . This can be done numerically, by computing the minimum and maximum of u ( x ) = f ( x ) 1 1 + r {\displaystyle u(x)=f(x)^{\frac {1}{1+r}}} and v ( x ) = x f ( x ) r 1 + r {\displaystyle v(x)=x\,f(x)^{\frac {r}{1+r}}} on a grid of values of x {\displaystyle x} . Then, one can draw uniform samples ( u , v ) A ~ f , r {\displaystyle (u,v)\in {\tilde {A}}_{f,r}} , only keep those that fall inside the set A f , r {\displaystyle A_{f,r}} and return them as v u r {\displaystyle {\frac {v}{u^{r}}}} .

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

Software

  • The rust and Runuran 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. S2CID 12884505.
  2. Robert, Christian; Casella, George (2004). Monte Carlo Statistical Methods (2 ed.). Springer-Verlag. p. 47. ISBN 978-0-387-21239-5.
  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 .
  4. GOBET, EMMANUEL (2020). MONTE-CARLO METHODS AND STOCHASTIC PROCESSES : from linear to non-linear. : CRC PRESS. ISBN 978-0-367-65846-5. 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". Statistics and Computing. 1 (2): 129–133. doi:10.1007/BF01889987. ISSN 1573-1375. S2CID 119824513.
  6. Northrop, P. J. (2021), rust: Ratio-of-Uniforms Simulation with Transformation
  7. Leydold, J.; Hörmann, W. (2021), Runuran: R Interface to the 'UNU.RAN' Random Variate Generators
Categories:
Ratio of uniforms Add topic