java.lang.Object
org.bzdev.math.PoissonTable
Table implementation for generating Poisson-distributed values.
This is appropriate for small values of the parameter lambda
(which is equal to the mean value of a Poisson distribution),
where a large number of Poisson-distributed numbers with the
same parameter will be generated. If the values of lambda are
too large, numerical accuracy issues result in an incorrect
computation.
There is a bound on the integers returned. If the actual value is too large, the implementation tries again. This distributes errors evenly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
The maximum value of λ for an instance ofPoissonTable
. -
Method Summary
Modifier and TypeMethodDescriptionstatic PoissonTable
add
(double lambda) Add aPoissonTable
so that it cannot be garbage collected.static PoissonTable
createTable
(double lambda) Create an instance ofPoissonTable
.boolean
Compares this object against the argument.static int
estimateN
(double lambda) Estimate the limit on the integers that can be generated.double
Get the mean value of the Poisson distribution represented by this class.double
getN()
Get the limit for the highest integer that thenext()
method will produce.static PoissonTable
getTable
(double lambda) Get an instance ofPoissonTable
.int
hashCode()
Get the hash code for this object.int
next()
Get the next Poisson-distributed random numberstatic PoissonTable
remove
(double lambda) Arrange so that an addedPoissonTable
can be garbage collected.
-
Field Details
-
MAX_LAMBDA
public static final double MAX_LAMBDAThe maximum value of λ for an instance ofPoissonTable
.- See Also:
-
-
Method Details
-
equals
Compares this object against the argument. Two instances of PoissonTable are considered to be equal if the value of lambda used to configure them are the same. -
hashCode
public int hashCode()Get the hash code for this object. -
getLambda
public double getLambda()Get the mean value of the Poisson distribution represented by this class.- Returns:
- the mean value of this class' Poisson distribution
-
getN
public double getN()Get the limit for the highest integer that thenext()
method will produce. The values will be less than this limit.- Returns:
- the limit
-
estimateN
public static int estimateN(double lambda) Estimate the limit on the integers that can be generated.- Parameters:
lambda
- the mean value of a Poisson distribution- Returns:
- the limit
-
getTable
Get an instance ofPoissonTable
.- Parameters:
lambda
- the parameter λ (the mean value for the distribution)- Returns:
- the table; null if
lambda is larger than
MAX_LAMBDA
, the table was not created, or an existing table was removed by garbage collection - Throws:
IllegalArgumentException
- iflambda
is negative
-
createTable
Create an instance ofPoissonTable
. An existing table may be returned instead if one exists.- Parameters:
lambda
- the parameter λ (the mean value for the distribution)- Returns:
- the table
- Throws:
IllegalArgumentException
- iflambda
is negative
-
add
Add aPoissonTable
so that it cannot be garbage collected.- Parameters:
lambda
- the λ parameter for the distribution- Returns:
- the table
-
remove
Arrange so that an addedPoissonTable
can be garbage collected.- Parameters:
lambda
- the λ parameter for the distribution- Returns:
- the table
-
next
public int next()Get the next Poisson-distributed random number- Returns:
- the number
-