Sunday, January 11, 2009

The Box-Muller Algorithm

Many thanks to Professior Gordon Wyeth at the University of Queensland and his MCL code. I am grateful to him for bringing the Box-Muller algorithm to my attention. It is a way of generating normally distributed random variables with mean zero and standard deviation one, given a set of uniformly generated random variables in the range 0 to 1. This algorithm is important when adding Gaussian noise to a process in the MCL algorithm. Unfortunately, Java's Math class has no method to generate random numbers from a normal distribution. However, Java does have a uniform random number generator function, which can be used to generate a normal distribution by applying the Box-Muller algorithm.

You can download my code to test this algorithm. Here is a frequency histogram of the data that I generated from my program:



This frequency distribution has a mean of 0.0036 and a standard deviation of 1.0008. Of course, your own results will be different, but the mean and standard deviation should come close to 0 and 1, respectively.

The best explanation of why the Box-Muller algorithm works as it does is in this document.

No comments: