org.apache.commons.math.distribution
Class HypergeometricDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractIntegerDistribution
          extended by org.apache.commons.math.distribution.HypergeometricDistributionImpl
All Implemented Interfaces:
java.io.Serializable, DiscreteDistribution, Distribution, HypergeometricDistribution, IntegerDistribution

public class HypergeometricDistributionImpl
extends AbstractIntegerDistribution
implements HypergeometricDistribution, java.io.Serializable

The default implementation of HypergeometricDistribution.

Version:
$Id: HypergeometricDistributionImpl.java 1182787 2011-10-13 11:20:48Z celestin $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
randomData
 
Constructor Summary
HypergeometricDistributionImpl(int populationSize, int numberOfSuccesses, int sampleSize)
          Construct a new hypergeometric distribution with the given the population size, the number of successes in the population, and the sample size.
 
Method Summary
protected  double calculateNumericalMean()
          Use this method to actually calculate the mean for the specific distribution.
protected  double calculateNumericalVariance()
          Use this method to actually calculate the variance for the specific distribution.
 double cumulativeProbability(int x)
          For this distribution, X, this method returns P(X <= x).
protected  int getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a PDF root.
protected  int getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a PDF root.
 int getNumberOfSuccesses()
          Access the number of successes.
 int getPopulationSize()
          Access the population size.
 int getSampleSize()
          Access the sample size.
 int getSupportLowerBound()
          Access the lower bound of the support.
 int getSupportUpperBound()
          Access the upper bound of the support.
 double probability(int x)
          For this distribution, X, this method returns P(X = x).
 double upperCumulativeProbability(int x)
          For this distribution, X, this method returns P(X >= x).
 
Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
cumulativeProbability, cumulativeProbability, cumulativeProbability, inverseCumulativeProbability, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive, probability, reseedRandomGenerator, sample, sample
 
Methods inherited from class org.apache.commons.math.distribution.AbstractDistribution
getNumericalMean, getNumericalVariance, isSupportConnected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.math.distribution.IntegerDistribution
cumulativeProbability, inverseCumulativeProbability, reseedRandomGenerator, sample, sample
 
Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probability
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive
 

Constructor Detail

HypergeometricDistributionImpl

public HypergeometricDistributionImpl(int populationSize,
                                      int numberOfSuccesses,
                                      int sampleSize)
Construct a new hypergeometric distribution with the given the population size, the number of successes in the population, and the sample size.

Parameters:
populationSize - Population size.
numberOfSuccesses - Number of successes in the population.
sampleSize - Sample size.
Throws:
NotPositiveException - if numberOfSuccesses < 0.
NotStrictlyPositiveException - if populationSize <= 0.
NotPositiveException - if populationSize < 0.
NumberIsTooLargeException - if numberOfSuccesses > populationSize.
NumberIsTooLargeException - if sampleSize > populationSize.
Method Detail

cumulativeProbability

public double cumulativeProbability(int x)
For this distribution, X, this method returns P(X <= x).

Specified by:
cumulativeProbability in interface IntegerDistribution
Specified by:
cumulativeProbability in class AbstractIntegerDistribution
Parameters:
x - Value at which the PDF is evaluated.
Returns:
PDF for this distribution.

getDomainLowerBound

protected int getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a PDF root.

Specified by:
getDomainLowerBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the domain value lower bound, i.e. P(X < 'lower bound') < p.

getDomainUpperBound

protected int getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a PDF root.

Specified by:
getDomainUpperBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value
Returns:
the domain value upper bound, i.e. P(X < 'upper bound') > p.

getNumberOfSuccesses

public int getNumberOfSuccesses()
Access the number of successes.

Specified by:
getNumberOfSuccesses in interface HypergeometricDistribution
Returns:
the number of successes.

getPopulationSize

public int getPopulationSize()
Access the population size.

Specified by:
getPopulationSize in interface HypergeometricDistribution
Returns:
the population size.

getSampleSize

public int getSampleSize()
Access the sample size.

Specified by:
getSampleSize in interface HypergeometricDistribution
Returns:
the sample size.

probability

public double probability(int x)
For this distribution, X, this method returns P(X = x).

Specified by:
probability in interface IntegerDistribution
Parameters:
x - Value at which the PMF is evaluated.
Returns:
PMF for this distribution.

upperCumulativeProbability

public double upperCumulativeProbability(int x)
For this distribution, X, this method returns P(X >= x).

Parameters:
x - Value at which the CDF is evaluated.
Returns:
the upper tail CDF for this distribution.
Since:
1.1

getSupportLowerBound

public int getSupportLowerBound()
Access the lower bound of the support. For population size N, number of successes m, and sample size n, the lower bound of the support is max(0, n + m - N)

Specified by:
getSupportLowerBound in class AbstractIntegerDistribution
Returns:
lower bound of the support

getSupportUpperBound

public int getSupportUpperBound()
Access the upper bound of the support. For number of successes m and sample size n, the upper bound of the support is min(m, n)

Specified by:
getSupportUpperBound in class AbstractIntegerDistribution
Returns:
upper bound of the support

calculateNumericalMean

protected double calculateNumericalMean()
Use this method to actually calculate the mean for the specific distribution. Use AbstractDistribution.getNumericalMean() (which implements caching) to actually get the mean. For population size N, number of successes m, and sample size n, the mean is n * m / N

Specified by:
calculateNumericalMean in class AbstractDistribution
Returns:
the mean or Double.NaN if it's not defined

calculateNumericalVariance

protected double calculateNumericalVariance()
Use this method to actually calculate the variance for the specific distribution. Use AbstractDistribution.getNumericalVariance() (which implements caching) to actually get the variance. For population size N, number of successes m, and sample size n, the variance is [ n * m * (N - n) * (N - m) ] / [ N^2 * (N - 1) ]

Specified by:
calculateNumericalVariance in class AbstractDistribution
Returns:
the variance or Double.NaN if it's not defined


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.