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:
$Revision: 1054524 $ $Date: 2011-01-03 05:59:18 +0100 (lun. 03 janv. 2011) $
See Also:
Serialized Form

Field Summary
private  int numberOfSuccesses
          The number of successes in the population.
private  int populationSize
          The population size.
private  int sampleSize
          The sample size.
private static long serialVersionUID
          Serializable version identifier
 
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
 double cumulativeProbability(int x)
          For this distribution, X, this method returns P(X ≤ x).
private  int[] getDomain(int n, int m, int k)
          Return the domain for the given hypergeometric distribution parameters.
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.
private  int getLowerDomain(int n, int m, int k)
          Return the lowest domain value for the given hypergeometric distribution parameters.
 int getNumberOfSuccesses()
          Access the number of successes.
protected  double getNumericalMean()
          Returns the mean.
 double getNumericalVariance()
          Returns the variance.
 int getPopulationSize()
          Access the population size.
 int getSampleSize()
          Access the sample size.
 int getSupportLowerBound()
          Returns the lower bound for the support for the distribution.
 int getSupportUpperBound()
          Returns the upper bound for the support of the distribution.
private  int getUpperDomain(int m, int k)
          Return the highest domain value for the given hypergeometric distribution parameters.
private  double innerCumulativeProbability(int x0, int x1, int dx, int n, int m, int k)
          For this distribution, X, this method returns P(x0 ≤ X ≤ x1).
 double probability(int x)
          For this distribution, X, this method returns P(X = x).
private  double probability(int n, int m, int k, int x)
          For the distribution, X, defined by the given hypergeometric distribution parameters, this method returns P(X = x).
 void setNumberOfSuccesses(int num)
          Deprecated. as of 2.1 (class will become immutable in 3.0)
private  void setNumberOfSuccessesInternal(int num)
          Modify the number of successes.
 void setPopulationSize(int size)
          Deprecated. as of 2.1 (class will become immutable in 3.0)
private  void setPopulationSizeInternal(int size)
          Modify the population size.
 void setSampleSize(int size)
          Deprecated. as of 2.1 (class will become immutable in 3.0)
private  void setSampleSizeInternal(int size)
          Modify the sample size.
 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 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
 
Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probability
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbability
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serializable version identifier

See Also:
Constant Field Values

numberOfSuccesses

private int numberOfSuccesses
The number of successes in the population.


populationSize

private int populationSize
The population size.


sampleSize

private int sampleSize
The sample size.

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 - the population size.
numberOfSuccesses - number of successes in the population.
sampleSize - the sample size.
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 - the value at which the PDF is evaluated.
Returns:
PDF for this distribution.

getDomain

private int[] getDomain(int n,
                        int m,
                        int k)
Return the domain for the given hypergeometric distribution parameters.

Parameters:
n - the population size.
m - number of successes in the population.
k - the sample size.
Returns:
a two element array containing the lower and upper bounds of the hypergeometric 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 - the desired probability for the critical value
Returns:
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 - the desired probability for the critical value
Returns:
domain value upper bound, i.e. P(X < upper bound) > p

getLowerDomain

private int getLowerDomain(int n,
                           int m,
                           int k)
Return the lowest domain value for the given hypergeometric distribution parameters.

Parameters:
n - the population size.
m - number of successes in the population.
k - the sample size.
Returns:
the lowest domain value of the hypergeometric distribution.

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.

getUpperDomain

private int getUpperDomain(int m,
                           int k)
Return the highest domain value for the given hypergeometric distribution parameters.

Parameters:
m - number of successes in the population.
k - the sample size.
Returns:
the highest domain value of the hypergeometric distribution.

probability

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

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

probability

private double probability(int n,
                           int m,
                           int k,
                           int x)
For the distribution, X, defined by the given hypergeometric distribution parameters, this method returns P(X = x).

Parameters:
n - the population size.
m - number of successes in the population.
k - the sample size.
x - the value at which the PMF is evaluated.
Returns:
PMF for the distribution.

setNumberOfSuccesses

@Deprecated
public void setNumberOfSuccesses(int num)
Deprecated. as of 2.1 (class will become immutable in 3.0)

Modify the number of successes.

Specified by:
setNumberOfSuccesses in interface HypergeometricDistribution
Parameters:
num - the new number of successes.
Throws:
java.lang.IllegalArgumentException - if num is negative.

setNumberOfSuccessesInternal

private void setNumberOfSuccessesInternal(int num)
Modify the number of successes.

Parameters:
num - the new number of successes.
Throws:
java.lang.IllegalArgumentException - if num is negative.

setPopulationSize

@Deprecated
public void setPopulationSize(int size)
Deprecated. as of 2.1 (class will become immutable in 3.0)

Modify the population size.

Specified by:
setPopulationSize in interface HypergeometricDistribution
Parameters:
size - the new population size.
Throws:
java.lang.IllegalArgumentException - if size is not positive.

setPopulationSizeInternal

private void setPopulationSizeInternal(int size)
Modify the population size.

Parameters:
size - the new population size.
Throws:
java.lang.IllegalArgumentException - if size is not positive.

setSampleSize

@Deprecated
public void setSampleSize(int size)
Deprecated. as of 2.1 (class will become immutable in 3.0)

Modify the sample size.

Specified by:
setSampleSize in interface HypergeometricDistribution
Parameters:
size - the new sample size.
Throws:
java.lang.IllegalArgumentException - if size is negative.

setSampleSizeInternal

private void setSampleSizeInternal(int size)
Modify the sample size.

Parameters:
size - the new sample size.
Throws:
java.lang.IllegalArgumentException - if size is negative.

upperCumulativeProbability

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

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

innerCumulativeProbability

private double innerCumulativeProbability(int x0,
                                          int x1,
                                          int dx,
                                          int n,
                                          int m,
                                          int k)
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 + 1, x0 + 2, ..., x1, in the order directed by dx.

Parameters:
x0 - the inclusive, lower bound
x1 - the inclusive, upper bound
dx - the direction of summation. 1 indicates summing from x0 to x1. 0 indicates summing from x1 to x0.
n - the population size.
m - number of successes in the population.
k - the sample size.
Returns:
P(x0 ≤ X ≤ x1).

getSupportLowerBound

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

Returns:
lower bound of the support
Since:
2.2

getSupportUpperBound

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

Returns:
upper bound of the support
Since:
2.2

getNumericalMean

protected double getNumericalMean()
Returns the mean. For population size N, number of successes m, and sample size n, the mean is n * m / N

Returns:
the mean
Since:
2.2

getNumericalVariance

public double getNumericalVariance()
Returns 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) ]

Returns:
the variance
Since:
2.2


Copyright (c) 2003-2013 Apache Software Foundation