Class ZigguratGaussian
- java.lang.Object
-
- org.cicirello.math.rand.ZigguratGaussian
-
public final class ZigguratGaussian extends Object
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 is the polar method (nextGaussian method of the
Random
andThreadLocalRandom
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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
nextGaussian()
Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.static double
nextGaussian(double sigma)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or your choosing.static double
nextGaussian(double sigma, Random r)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or your choosing.static double
nextGaussian(double sigma, SplittableRandom r)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or your choosing.static double
nextGaussian(Random r)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.static double
nextGaussian(SplittableRandom r)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.
-
-
-
Method Detail
-
nextGaussian
public static double nextGaussian(double sigma)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or your choosing.ThreadLocalRandom
is 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
public static double nextGaussian(double sigma, Random r)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or 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(double sigma, SplittableRandom r)
Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or 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.ThreadLocalRandom
is 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
public static double nextGaussian(Random r)
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.
-
nextGaussian
public static double nextGaussian(SplittableRandom r)
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.
-
-