- java.lang.Object
-
- org.cicirello.math.rand.PolarGaussian
-
public final class PolarGaussian extends Object
This class provides methods for generating pseudorandom numbers from a Gaussian distribution using the classic Polar Method. Other methods exist that are faster than Polar, and with superior statistical properties over the Polar method. One such algorithm is the Ziggurat method, implemented in the
ZigguratGaussianclass. The Polar method implementation provided in the PolarGaussian class was originally implemented as part of an experimental study comparing the effects of different Gaussian algorithms on the performance of a genetic algorithm. It is included here in this repository, however, if you are looking for a fast algorithm for generating Gaussian distributed random numbers, we suggest you consider theZigguratGaussianclass instead.It should be noted that the Java API includes a polar method implementation in both the
RandomandThreadLocalRandomclasses. However, the experimental study mentioned above also included the use ofSplittableRandomwhich does not provide any methods for generating Gaussian distributed random numbers. TheSplittableRandomclass is also declared final, so extending to add such a method was not an option. Our solution was a static method in this class with a parameter for the underlying pseudorandom number generator (PRNG). We chose to do the same forRandomandThreadLocalRandomso that our approach was consistent across all 3 PRNGs used in the study.You can find some experimental data comparing the performance of a sequential genetic algorithm (GA) using this implementation of the Polar method for Gaussian mutation vs using the faster Ziggurat method, as well as experimental data for the same comparison but with a Parallel GA, 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.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doublenextGaussian()Generates 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, or your choosing.static doublenextGaussian(double sigma, Random r)Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or your choosing.static doublenextGaussian(double sigma, SplittableRandom r)Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, or your choosing.static doublenextGaussian(Random r)Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.static doublenextGaussian(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.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
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.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
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.
-
-