Showing posts with label Box-Muller algorithm. Show all posts
Showing posts with label Box-Muller algorithm. Show all posts

Monday, January 12, 2009

Added new BoxMuller.java Class

I have added a new class called BoxMuller.java. Its sole static method randn(float mu, float sigma) returns a random floating-point number drawn from a normal distribution of mean mu and standard deviation sigma. Essentially, it produces the same result as Matlab's randn function.

The BoxMuller.randn method is used in the MCL.java class to add noise to a newly chosen particle in the chooseNewPoseSet method. I have corrected this method so that it now refers to the randn method.

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.