java.lang.Object
org.bzdev.math.rv.RandomVariable<Integer>
org.bzdev.math.rv.IntegerRandomVariable
org.bzdev.math.rv.PoissonIntegerRV
- All Implemented Interfaces:
Cloneable
,RandomVariableOps<Integer>
Integer-valued random variable with a Poisson distribution.
If X is a random variable with a Poisson distribution that has a
parameter λ, the the probability that X = k is given by
(λke-λ)/k!The sequence of integers generated by instances of this class are values of k with the distribution given above.
The algorithms used are
- Table lookup: used for λ≤745 and when a table
is available. A table, if not currently cached, is created
when λ ≤ 745 and the second argument of the
two-argument constructor has the value
true
. The table may be removed by the garbage collector, although the methodPoissonTable.add(double)
can be used to create a persistent table. This algorithm is basically inverse transform sampling with pre-computed values and a binary search to find the inverse. The limit on λ is set by numerical-accuracy constraints. - Inverse transform sampling: used for λ≤18. The inverse is found by computing the CDF for increasing values of k until the value for the CDF is larger than a uniformly distributed random number (computed once).
- The PTRD algorithm (Wolfgang Hörmann, "The Transformed Rejection Method for Generating Poisson Random Variables," page 6, Virtschaftsuniversität Wien, April 1992, http://epub.wu.ac.at/352/1/document.pdf): used for 18 < λ < 225.
- Approximation via a normal distribution: used for λ ≥ 225.
-
Constructor Summary
ConstructorsConstructorDescriptionPoissonIntegerRV
(double lambda) Constructor.PoissonIntegerRV
(double lambda, boolean mode) Constructor with a mode to allow tables to be allocated. -
Method Summary
Methods inherited from class org.bzdev.math.rv.IntegerRandomVariable
clearRangeTest, getMaximum, getMaximumClosed, getMinimum, getMinimumClosed, parallelStream, parallelStream, rangeTestFailed, rangeTestNeeded, setMaximum, setMinimum, setRequiredMaximum, setRequiredMinimum, spliterator, spliterator, stream, stream, tightenMaximum, tightenMaximumS, tightenMinimum, tightenMinimumS
Methods inherited from class org.bzdev.math.rv.RandomVariable
clone, getCharacteristics
-
Constructor Details
-
PoissonIntegerRV
public PoissonIntegerRV(double lambda) Constructor.- Parameters:
lambda
- the rate of the Poisson distribution (equal to its mean and to its variance).
-
PoissonIntegerRV
public PoissonIntegerRV(double lambda, boolean mode) Constructor with a mode to allow tables to be allocated. If tables are requested and the value of lambda is too large, the request will be ignored.- Parameters:
lambda
- the rate of the Poisson distribution (equal to its mean and to its variance)mode
- true if tables should be allocated to improve execution speed; false otherwise
-
-
Method Details
-
getMean
public double getMean()Get the mean value for the random-variable.- Returns:
- the mean value
-
getSDev
public double getSDev()Get the standard deviation for the random variable.- Returns:
- the standard deviation
-
next
Get the next value.- Specified by:
next
in interfaceRandomVariableOps<Integer>
- Specified by:
next
in classRandomVariable<Integer>
- Returns:
- an integer giving a value from a Poisson distribution
-