Class RNGDistribution.Geometric

Enclosing class:
RNGDistribution

public static class RNGDistribution.Geometric extends RNGDistribution
Geometrically distributed random numbers with support {1,2,3,...}.
See Also:
  • Field Details

    • cdf

      private double[] cdf
      Cumulative distribution function of geometric probability distribution.
    • p

      private double p
      Success probability of single trial.
    • mean

      private double mean
      Mean of geometric distribution.
  • Constructor Details

    • Geometric

      public Geometric(double p)
      Creates geometric distribution with success probability p (mean 1/p) and a new instance of MersenneTwister.
      Parameters:
      p - success probability of single trial
    • Geometric

      public Geometric(MersenneTwister rng, double p)
      Creates geometric distribution with success probability p (mean 1/p) and the random number generator rng.
      Parameters:
      rng - random number generator
      p - success probability of single trial
  • Method Details

    • setProbability

      public void setProbability(double p) throws IllegalArgumentException
      Set the probability of success p for the geometric distribution.

      Note:

      • If p<10-4 the geometric distribution is approximated by an exponential distribution.
      • cumulative probabilities are limited to 50*mean trials.
      Parameters:
      p - probability of success of single trial
      Throws:
      IllegalArgumentException - if p≤0 or p≥1
    • getProbability

      public double getProbability()
      Get the success probability of a single trial.
      Returns:
      the success probability of a single trial
    • next

      public int next()
      Generate a geometrically distributed random number with success probability p.
      Returns:
      the number of trials until first success
    • clone

      public RNGDistribution.Geometric 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 int next(MersenneTwister rng, double p)
      Creates geometric distribution with success probability p (mean 1/p) and the random number generator rng.

      Note: cumulative distribution function is generated on the fly. This is fine if only a few geometrically distributed random numbers are required or if performance is of a minor concern. Otherwise use Geometric(double) and next().

      Parameters:
      rng - random number generator
      p - probability of success of single trial
      Returns:
      number of trials until first success
    • test

      public static void test(MersenneTwister rng, Logger logger, MersenneTwister.Chronometer clock)
      Test Geometric 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