Package org.evoludo.math
Class RNGDistribution.Binomial
Object
RNGDistribution
Binomial
- Enclosing class:
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class RNGDistribution
RNGDistribution.Binomial, RNGDistribution.Exponential, RNGDistribution.Geometric, RNGDistribution.Gillespie, RNGDistribution.Normal, RNGDistribution.TestCommand, RNGDistribution.Uniform -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate double[]Cumulative distribution function of binomial probability distribution.private doubleMean number of successesn p.private doubleSuccess probability of single trial.Fields inherited from class RNGDistribution
rng, seed, seedSet, testSamples -
Constructor Summary
ConstructorsConstructorDescriptionBinomial(double p, int n) Creates binomial distribution withntrials and success probabilityp(meann p) and a new instance ofMersenneTwister..Binomial(MersenneTwister rng, double p, int n) Creates binomial distribution withntrials and success probabilityp(meann p) and the random number generatorrng. -
Method Summary
Modifier and TypeMethodDescriptionclone()Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.doubleGet the probability of successpof a single trial for the binomial distribution.intGet the number of trialsnfor the binomial distribution.intnext()Generate the number of successful trials drawn from the binomial distribution.static intnext(MersenneTwister rng, double p, int n) Creates binomial distribution forntrials with success probabilityp(meann p) and the random number generatorrng.voidsetProbabilityTrials(double p, int n) Set the probability of successpand the number of trialsn.static voidtest(MersenneTwister rng, Logger logger, MersenneTwister.Chronometer clock) Test Binomial distribution.Methods inherited from class RNGDistribution
clearRNGSeed, clone, getRNG, getRNGSeed, isRNGSeedSet, nextBoolean, nextByte, nextBytes, nextDouble, nextGaussian, nextInt, nextInt, random01, random01d, random0n, random0N, setRNG, setRNGSeed, setRNGSeed
-
Field Details
-
cdf
private double[] cdfCumulative distribution function of binomial probability distribution. -
p
private double pSuccess probability of single trial. -
mean
private double meanMean number of successesn p.
-
-
Constructor Details
-
Binomial
public Binomial(double p, int n) Creates binomial distribution withntrials and success probabilityp(meann p) and a new instance ofMersenneTwister..- Parameters:
p- success probability of single trialn- number of trials
-
Binomial
Creates binomial distribution withntrials and success probabilityp(meann p) and the random number generatorrng.- Parameters:
rng- random number generatorp- success probability of single trialn- number of trials- Throws:
IllegalArgumentException
-
-
Method Details
-
setProbabilityTrials
Set the probability of successpand the number of trialsn. This calculates the cumulative probabilities for the binomial distribution.- Parameters:
p- probability of success of single trialn- number of trials- Throws:
IllegalArgumentException- ifp≤0,p≥1orn<0
-
getProbability
public double getProbability()Get the probability of successpof a single trial for the binomial distribution.- Returns:
- the success probability of a single trial
-
getTrials
public int getTrials()Get the number of trialsnfor 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
Description copied from class:RNGDistributionClone this RNGDistribution to ensure both objects return identical sequences of random numbers.IMPORTANT:
- Specified by:
clonein classRNGDistribution- Returns:
- clone of RNGDistribution
-
next
Creates binomial distribution forntrials with success probabilityp(meann p) and the random number generatorrng.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)} andnext().- Parameters:
rng- random number generatorp- probability of success of single trialn- number of trials- Returns:
- number of successful trials
-
test
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 from0. This is more stringent than the traditional 95% confidence interval.- Parameters:
rng- the random number generatorlogger- the logger for reporting resultsclock- the stop watch
-