Draw a sample from a normal distribution with mean 0 and variance 1

In the previous post, it’s easy to transform it to a sample from a normal distribution with mean  \mu and variance  \sigma^{2} by calculating  \sigma x \, + \, \mu if we can draw a sample x from a normal distribution with mean 0 and variance 1.

Then I started googling how to draw a sample from a normal distribution with mean 0 and variance 1.

Box-Muller transformation seems to be one of the most popular way to do it.

According to the post I found, it does seem to be difficult. However we need to now how to draw a sample from an exponential distribution. Inverse transform sampling seems to be a way to do it.

According to the Inverse transform sampling page on wikipedia, the following method can be used.

The problem that the inverse transform sampling method solves is as follows:

  • Let X be a random variable whose distribution can be described by the cumulative distribution function F.
  • We want to generate values of X which are distributed according to this distribution.

The inverse transform sampling method works as follows:

  1. Generate a random number u from the standard uniform distribution in the interval [0,1].
  2. Compute the value x such that F(x) = u.
  3. Take x to be the random number drawn from the distribution described by F.

The most important thing is to know how to calculate the value x such that  F(x) \, = \, u. You need to know the inverse function  F^{-1}(x) of cumulative distribution function  F, which quantile function.

Actually if we know the quantile function of normal distribution, we don’t need Box-Muller transformation.

However the quantile function of normal distribution does not have any closed-form representation using basic algebraic functions.

On the other hand, a cumulative distribution function of an exponential distribution is  F(x)=1-e^{-\lambda x}. The quantile function  x = F^{-1}(y) = -\frac{1}{\lambda}\ln(1-y) can be calculated by solving  y=F(x) easily.