Package org.evoludo.math
Class RNGDistribution.Geometric
Object
RNGDistribution
Geometric
- Enclosing class:
RNGDistribution
Geometrically distributed random numbers with support
{1,2,3,...}
.- 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 geometric probability distribution.private double
Mean of geometric distribution.private double
Success probability of single trial.Fields inherited from class RNGDistribution
rng, seed, seedSet, testSamples
-
Constructor Summary
ConstructorsConstructorDescriptionGeometric
(double p) Creates geometric distribution with success probabilityp
(mean1/p
) and a new instance ofMersenneTwister
.Geometric
(MersenneTwister rng, double p) Creates geometric distribution with success probabilityp
(mean1/p
) and the random number generatorrng
. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.double
Get the success probability of a single trial.int
next()
Generate a geometrically distributed random number with success probabilityp
.static int
next
(MersenneTwister rng, double p) Creates geometric distribution with success probabilityp
(mean1/p
) and the random number generatorrng
.void
setProbability
(double p) Set the probability of successp
for the geometric distribution.static void
test
(MersenneTwister rng, Logger logger, MersenneTwister.Chronometer clock) Test Geometric 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 geometric probability distribution. -
p
private double pSuccess probability of single trial. -
mean
private double meanMean of geometric distribution.
-
-
Constructor Details
-
Geometric
public Geometric(double p) Creates geometric distribution with success probabilityp
(mean1/p
) and a new instance ofMersenneTwister
.- Parameters:
p
- success probability of single trial
-
Geometric
Creates geometric distribution with success probabilityp
(mean1/p
) and the random number generatorrng
.- Parameters:
rng
- random number generatorp
- success probability of single trial
-
-
Method Details
-
setProbability
Set the probability of successp
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
- ifp≤0
orp≥1
- If
-
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 probabilityp
.- Returns:
- the number of trials until first success
-
clone
Description copied from class:RNGDistribution
Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.IMPORTANT:
- Specified by:
clone
in classRNGDistribution
- Returns:
- clone of RNGDistribution
-
next
Creates geometric distribution with success probabilityp
(mean1/p
) and the random number generatorrng
.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)
andnext()
.- Parameters:
rng
- random number generatorp
- probability of success of single trial- Returns:
- number of trials until first success
-
test
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 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
-