Class RNGDistribution.Normal

Enclosing class:
RNGDistribution

public static class RNGDistribution.Normal extends RNGDistribution
Normally (or Gaussian) distributed random numbers with support (-Double.MAX_VALUE, Double.MAX_VALUE).
See Also:
  • Field Details

    • mean

      private double mean
      The mean of the Normal distribution.
    • stdev

      private double stdev
      The standard deviation of the Normal distribution.
  • Constructor Details

    • Normal

      public Normal()
      Creates a standard Normal distribution with mean==0 and standard deviation stdev==1 using and a new instance of MersenneTwister.
    • Normal

      public Normal(double mean, double stdev)
      Creates Normal distribution with mean and standard deviation stdev using and a new instance of MersenneTwister.
      Parameters:
      mean - of Normal distribution
      stdev - of Normal distribution
    • Normal

      public Normal(MersenneTwister rng, double mean, double stdev) throws IllegalArgumentException
      Creates Normal distribution with mean and standard deviation stdev using the random number generator rng.
      Parameters:
      rng - random number generator
      mean - of Normal distribution
      stdev - of Normal distribution
      Throws:
      IllegalArgumentException - if man≤0
      See Also:
  • Method Details

    • getMean

      public double getMean()
      Get the mean of the Normal distribution.
      Returns:
      the mean
    • getStdev

      public double getStdev()
      Get the standard deviation of the Normal distribution.
      Returns:
      the standard deviation
    • next

      public double next()
      Generate a normally distributed random number with mean and standard deviation stdev.
      Returns:
      the Normally distributed random number
    • clone

      public RNGDistribution.Normal clone()
      Description copied from class: RNGDistribution
      Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.

      IMPORTANT:

      1. overrides clone() in Object but conflicts with GWT's aversion to clone()ing...
      2. remove @SuppressWarnings("all") to ensure that no other issues crept in when modifying method.
      Specified by:
      clone in class RNGDistribution
      Returns:
      clone of RNGDistribution
    • next

      public static double next(MersenneTwister rng, double mean, double stdev)
      Normally distributed random number with mean and standard deviation stdev using random number generator rng.

      Note: no performance difference between the instance method next() and this static counterpart.

      Parameters:
      rng - random number generator
      mean - the mean of the Normal distribution
      stdev - the standard deviation of the Normal distribution
      Returns:
      Normally distributed random number
    • test

      public static void test(MersenneTwister rng, Logger logger, MersenneTwister.Chronometer clock)
      Test Normal distribution.

      The test samples the distribution and bins the random numbers. This sample distribution is compared to the theoretical expectation. The mean deviation is the mean difference between the actual number of events in each bin and their expected number. For a perfect match the mean deviation is 0. The test passes if the mean deviation lies within one standard error from 0. This is more stringent than the traditional 95% confidence interval.

      Parameters:
      rng - the random number generator
      logger - the logger for reporting results
      clock - the stop watch
      See Also:
    • cdf

      private static double cdf(double x, double mean, double stdev)
      Helper method to calculate the cumulative distribution function, cdf, of the Normal distribution.
      Parameters:
      x - the value for which to calculate the cdf
      mean - the mean value
      stdev - the standard deviation
      Returns:
      cdf at x
      See Also:
    • erf

      private static double erf(double x)
      Numerical approximation of error function erf(x) from Abramowitz & Stegun.

      Note: approximation requires x≥0. For x<0 use that erf(x) is odd function.

      Parameters:
      x - the function argument
      Returns:
      erf(x)