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, 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:

See the following articles for detailed description of the Ziggurat algorithm:

  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    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, of your choosing.
    static double
    nextGaussian(double sigma, RandomGenerator r)
    Generates a random number from a Gaussian distribution with mean 0 and standard deviation, sigma, of your choosing.
    static double
    Generates a random number from a Gaussian distribution with mean 0 and standard deviation 1.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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. 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, RandomGenerator r)
      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. 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(RandomGenerator 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.