Class PoissonTable

java.lang.Object
org.bzdev.math.PoissonTable

public final class PoissonTable extends Object
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 Details

  • Method Details

    • equals

      public boolean equals(Object o)
      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.
      Overrides:
      equals in class Object
      Parameters:
      o - the argument
      Returns:
      true if the objects are equal; false otherwise
    • hashCode

      public int hashCode()
      Get the hash code for this object.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • 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 the next() 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

      public static PoissonTable getTable(double lambda) throws IllegalArgumentException
      Get an instance of PoissonTable.
      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 - if lambda is negative
    • createTable

      public static PoissonTable createTable(double lambda) throws IllegalArgumentException
      Create an instance of PoissonTable. 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 - if lambda is negative
    • add

      public static PoissonTable add(double lambda)
      Add a PoissonTable so that it cannot be garbage collected.
      Parameters:
      lambda - the λ parameter for the distribution
      Returns:
      the table
    • remove

      public static PoissonTable remove(double lambda)
      Arrange so that an added PoissonTable 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