Class Hypergeom

java.lang.Object
org.apache.commons.statistics.inference.Hypergeom

class Hypergeom extends Object
Provide a wrapper around the HypergeometricDistribution that caches all probability mass values.

This class extracts the logic from the HypergeometricDistribution implementation used for the cumulative probability functions. It allows fast computation of the CDF and SF for the entire supported domain.

Since:
1.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
    1/2.
    private final int
    The lower bound of the support (inclusive).
    private final int
    Cached midpoint, m, of the CDF/SF.
    private final int
    Lower mode.
    private final int
    Upper mode.
    private final double
    Cached CDF of the midpoint.
    private final double[]
    Cached probability values.
    private final int
    The upper bound of the support (inclusive).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Hypergeom(int populationSize, int numberOfSuccesses, int sampleSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) double
    cdf(int x)
    Compute the cumulative distribution function (CDF) at the specified value.
    (package private) int
    Get the lower mode of the distribution.
    (package private) int
    Get the lower bound of the support.
    (package private) int
    Get the upper bound of the support.
    (package private) int
    Get the upper mode of the distribution.
    private double
    innerCumulativeProbability(int x0, int x1)
    For this distribution, X, this method returns P(x0 <= X <= x1).
    (package private) double
    pmf(int x)
    Compute the probability mass function (PMF) at the specified value.
    (package private) double
    sf(int x)
    Compute the survival function (SF) at the specified value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HALF

      private static final double HALF
      1/2.
      See Also:
    • lowerBound

      private final int lowerBound
      The lower bound of the support (inclusive).
    • upperBound

      private final int upperBound
      The upper bound of the support (inclusive).
    • prob

      private final double[] prob
      Cached probability values. This holds values from x=0 even though the supported lower bound may be above x=0. This allows x to be used as an index without offsetting using the lower bound.
    • m

      private final int m
      Cached midpoint, m, of the CDF/SF. This is not the true median. It is the value where the CDF is closest to 0.5; as such the CDF(m) may be below 0.5 if the next value CDF(m+1) is further from 0.5. Used for the cumulative probability functions.
    • midCDF

      private final double midCDF
      Cached CDF of the midpoint. Used for the cumulative probability functions.
    • m1

      private final int m1
      Lower mode.
    • m2

      private final int m2
      Upper mode.
  • Constructor Details

    • Hypergeom

      Hypergeom(int populationSize, int numberOfSuccesses, int sampleSize)
      Parameters:
      populationSize - Population size.
      numberOfSuccesses - Number of successes in the population.
      sampleSize - Sample size.
  • Method Details

    • getSupportLowerBound

      int getSupportLowerBound()
      Get the lower bound of the support.
      Returns:
      lower bound
    • getSupportUpperBound

      int getSupportUpperBound()
      Get the upper bound of the support.
      Returns:
      upper bound
    • getLowerMode

      int getLowerMode()
      Get the lower mode of the distribution.
      Returns:
      lower mode
    • getUpperMode

      int getUpperMode()
      Get the upper mode of the distribution.
      Returns:
      upper mode
    • pmf

      double pmf(int x)
      Compute the probability mass function (PMF) at the specified value.
      Parameters:
      x - Value.
      Returns:
      P(X = x)
      Throws:
      IndexOutOfBoundsException - if the value x is not in the supported domain.
    • cdf

      double cdf(int x)
      Compute the cumulative distribution function (CDF) at the specified value.
      Parameters:
      x - Value.
      Returns:
      P(X invalid input: '<'= x)
    • sf

      double sf(int x)
      Compute the survival function (SF) at the specified value. This is the complementary cumulative distribution function.
      Parameters:
      x - Value.
      Returns:
      P(X > x)
    • innerCumulativeProbability

      private double innerCumulativeProbability(int x0, int x1)
      For this distribution, X, this method returns P(x0 <= X <= x1). This probability is computed by summing the point probabilities for the values x0, x0 + dx, x0 + 2 * dx, ..., x1; the direction dx is determined using a comparison of the input bounds. This should be called by using x0 as the domain limit and x1 as the internal value. This will result in a sum of increasingly larger magnitudes.
      Parameters:
      x0 - Inclusive domain bound.
      x1 - Inclusive internal bound.
      Returns:
      P(x0 <= X <= x1).