This class provides methods for generating pseudorandom numbers from a Gaussian distribution using the Ziggurat Algorithm. The Ziggurat algorithm is significantly faster than the more commonly encountered Polar method, and has some other desirable statistical properties. The ZigguratGaussian class is a Java port of the GNU Scientific Library's C implementation (Voss, 2005) of the Ziggurat method. In porting to Java, we have made a few subtle, and minor, optimizations that are not worth specifying in the API documentation as they do not impact usage of the class. If interested, see the source code comments, which highlights any differences between this Java implementation and the C implementation on which it is based.
This Java implementation originated as part of an effort to speed
up the runtime of a parallel genetic algorithm (PGA). The PGA in
question evolved its control parameters (i.e., crossover and mutation rates,
etc) using Gaussian mutation. The only Gaussian implementation within the
Java API, at that time, was the polar method (nextGaussian method of the Random and
ThreadLocalRandom classes, however the polar method is quite slow
relative to other newer available alternatives, such as the Ziggurat method.
You can find some experimental data comparing the performance of a sequential genetic algorithm (GA) using this implementation of the Ziggurat method for Gaussian mutation vs using the more common polar method, as well as experimental data for the same comparison but with a PGA, in the following paper:
- V. A. Cicirello. Impact of Random Number Generation on Parallel Genetic Algorithms. Proceedings of the Thirty-First International Florida Artificial Intelligence Research Society Conference, pages 2-7. AAAI Press, May 2018.
See the following articles for detailed description of the Ziggurat algorithm:
- G. Marsaglia and W. W. Tsang. The ziggurat method for generating random variables. Journal of Statistical Software. 5(1):1–7, 2000.
- P. H. W. Leong, G. Zhang, D. Lee, W. Luk, and J. Villasenor. A Comment on the Implementation of the Ziggurat Method. Journal of Statistical Software. 12(7):1–4, 2005.
- J. Voss. The Ziggurat Method for Generating Gaussian Random Numbers. GSL: GNU Scientific Library. 2005.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleGenerates a random number from a Gaussian distribution with mean 0 and standard deviation 1.static doublenextGaussian(double sigma) Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.static doublenextGaussian(double sigma, RandomGenerator r) Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.static doubleGenerates a random number from a Gaussian distribution with mean 0 and standard deviation 1.
-
Method Details
-
nextGaussian
public static double nextGaussian(double sigma) Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.ThreadLocalRandomis used as the pseudorandom number generator for the source of randomness.- Parameters:
sigma- The standard deviation of the Gaussian.- Returns:
- A random number from a Gaussian distribution with mean 0 and standard deviation sigma.
-
nextGaussian
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.- Parameters:
sigma- The standard deviation of the Gaussian.r- The pseudorandom number generator to use for the source of randomness.- Returns:
- A random number from a Gaussian distribution with mean 0 and standard deviation sigma.
-
nextGaussian
public static double nextGaussian()Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.ThreadLocalRandomis used as the pseudorandom number generator for the source of randomness.- Returns:
- A random number from a Gaussian distribution with mean 0 and standard deviation 1.
-
nextGaussian
Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.- Parameters:
r- The pseudorandom number generator to use for the source of randomness.- Returns:
- A random number from a Gaussian distribution with mean 0 and standard deviation 1.
-