Class 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 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

      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.