Class RNGDistribution.Binomial

Enclosing class:
RNGDistribution

public static class RNGDistribution.Binomial extends RNGDistribution
Binomially distributed random numbers with support {0,1,2,3,..., n}. This represents the number of successes in n trials each with a probability of success p.
See Also:
  • Field Details

    • cdf

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

      private double p
      Success probability of single trial.
    • mean

      private double mean
      Mean number of successes n p.
  • Constructor Details

    • Binomial

      public Binomial(double p, int n)
      Creates binomial distribution with n trials and success probability p (mean n p) and a new instance of MersenneTwister..
      Parameters:
      p - success probability of single trial
      n - number of trials
    • Binomial

      public Binomial(MersenneTwister rng, double p, int n) throws IllegalArgumentException
      Creates binomial distribution with n trials and success probability p (mean n p) and the random number generator rng.
      Parameters:
      rng - random number generator
      p - success probability of single trial
      n - number of trials
      Throws:
      IllegalArgumentException
  • Method Details

    • setProbabilityTrials

      public void setProbabilityTrials(double p, int n) throws IllegalArgumentException
      Set the probability of success p and the number of trials n. This calculates the cumulative probabilities for the binomial distribution.
      Parameters:
      p - probability of success of single trial
      n - number of trials
      Throws:
      IllegalArgumentException - if p≤0, p≥1 or n<0
    • getProbability

      public double getProbability()
      Get the probability of success p of a single trial for the binomial distribution.
      Returns:
      the success probability of a single trial
    • getTrials

      public int getTrials()
      Get the number of trials n for the binomial distribution.
      Returns:
      the number of trials
    • next

      public int next()
      Generate the number of successful trials drawn from the binomial distribution.
      Returns:
      the number of successful trials
    • clone

      public RNGDistribution.Binomial 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, int n)
      Creates binomial distribution for n trials with success probability p (mean n p) and the random number generator rng.

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

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

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