The Azimuth Project
Transforming uniform random variables to other distributions (Rev #2)

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. Generate NN independent standard normal random numbers, forming an NN-vector XX.
  2. Set V=LX+μV = LX + \mu, where LL is the left Cholesky factor of the multivariate normal covariance matrix Σ\Sigma (ΣLL T\Sigma\equiv LL^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.

References

  • TODO