The Azimuth Project
Transforming uniform random variables to other distributions

Transforming uniform random variables to other distributions

Idea

It is common to have a low-level Random number generator which generates uniform variates on [0,1)[0,1) and generate variates from other distributions by “processing” those variables. One very flexible but memory-intensive approach is to use look-up tables to convert them. For some distributions a simpler mathematical transformation method can be used. We list some of the most common below. In what follows, lowercase letters denote pseudo-random numbers on [0,1)[0,1).

Normal distribution

  1. Generate uu and vv and set U=2u1U=2u-1, V=2v1V=2v-1.
  2. Set W=U 2+V 2W=U^2+V^2. If W>1W \gt 1 restart from 1.
  3. Set A=(2logW)/WA=\sqrt{(-2\log W)/W}.
  4. Values T 1=UAT_1=U A and T 2=VAT_2=V A are two independent variates from the Normal/Gaussian distribution.

Multivariate normal distribution

  1. Use the above method to generate NN independent standard normal random numbers (samples from N(0,1)N(0,1)), forming an NN-vector XX.
  2. Set V=LX+μV = L X + \mu, where LL is the left Cholesky factor of the multivariate normal covariance matrix Σ\Sigma (ΣLL T\Sigma\equiv L L^T), and μ\mu is the multivariate normal mean vector. The vector VV is a random sample from the distribution N(μ,Σ)N(\mu,\Sigma).

Student-tt distribution with nn degrees of freedom

  1. Generate uu and vv and set U=2u1U=2u-1, V=2v1V=2v-1.
  2. Set W=U 2+V 2W=U^2+V^2. If W>1W \gt 1 restart from 1.
  3. Value T=UnW 2/n1WT=U\sqrt{n \frac{W^{-2/n}-1}{W}} is from the Student-tt distribution with nn degrees of freedom.

Cauchy distribution

  1. Generate uu and vv and set U=2u1U=2u-1, V=2v1V=2v-1.
  2. Set W=U 2+V 2W=U^2+V^2. If W>1W \gt 1 restart from 1.
  3. Value T=UW 21WT=U\sqrt{\frac{W^{-2}-1}{W}} is from the Cauchy distribution.

Exponential distribution

  1. Generate uu, then expuλ\frac{\exp u}{\lambda} is form the Exp(λ)Exp(\lambda) distribution. [this is wrong. eg. how do you get a value greater than ]

Gamma(n,λ)(n,\lambda) distribution

  1. Generate nn variates V 1V_1 to V nV_n from Exp(λ)Exp(\lambda) using the above method.
  2. Then V 1++V NV_1+\dots +V_N is from the Gamma(n,λ)(n,\lambda) distribution.

Notes

References

  • TODO