org.apache.commons.math.distribution
Class AbstractIntegerDistribution

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractIntegerDistribution
All Implemented Interfaces:
java.io.Serializable, DiscreteDistribution, Distribution, IntegerDistribution
Direct Known Subclasses:
BinomialDistributionImpl, HypergeometricDistributionImpl, PascalDistributionImpl, PoissonDistributionImpl, ZipfDistributionImpl

public abstract class AbstractIntegerDistribution
extends AbstractDistribution
implements IntegerDistribution, java.io.Serializable

Base class for integer-valued discrete distributions. Default implementations are provided for some of the methods that do not vary from distribution to distribution.

Version:
$Id: AbstractIntegerDistribution.java 1178295 2011-10-03 04:36:27Z psteitz $
See Also:
Serialized Form

Field Summary
protected  RandomDataImpl randomData
          RandomData instance used to generate samples from the distribution.
 
Constructor Summary
protected AbstractIntegerDistribution()
          Default constructor.
 
Method Summary
 double cumulativeProbability(double x)
          For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x).
 double cumulativeProbability(double x0, double x1)
          For a random variable X whose values are distributed according to this distribution, this method returns P(x0 <= X <= x1).
abstract  double cumulativeProbability(int x)
          For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x).
 double cumulativeProbability(int x0, int x1)
          For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X < x1).
protected abstract  int getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a PDF root.
protected abstract  int getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a PDF root.
abstract  int getSupportLowerBound()
          Access the lower bound of the support.
abstract  int getSupportUpperBound()
          Access the upper bound of the support.
 int inverseCumulativeProbability(double p)
          For a random variable X whose values are distributed according to this distribution, this method returns the largest x, such that P(X <= x) <= p.
 boolean isSupportLowerBoundInclusive()
          Use this method to get information about whether the lower bound of the support is inclusive or not.
 boolean isSupportUpperBoundInclusive()
          Use this method to get information about whether the upper bound of the support is inclusive or not.
 double probability(double x)
          For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).
 void reseedRandomGenerator(long seed)
          Reseed the random generator used to generate samples.
 int sample()
          Generates a random value sampled from this distribution.
 int[] sample(int sampleSize)
          Generates a random sample from the distribution.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractDistribution
calculateNumericalMean, calculateNumericalVariance, 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
probability
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
getNumericalMean, getNumericalVariance, isSupportConnected
 

Field Detail

randomData

protected final RandomDataImpl randomData
RandomData instance used to generate samples from the distribution.

Since:
2.2
Constructor Detail

AbstractIntegerDistribution

protected AbstractIntegerDistribution()
Default constructor.

Method Detail

cumulativeProbability

public double cumulativeProbability(double x)
For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x). In other words, this method represents the (cumulative) distribution function, or CDF, for this distribution. If x does not represent an integer value, the CDF is evaluated at the greatest integer less than x.

Specified by:
cumulativeProbability in interface Distribution
Parameters:
x - Value at which the distribution function is evaluated.
Returns:
the cumulative probability that a random variable with this distribution takes a value less than or equal to x.

cumulativeProbability

public double cumulativeProbability(double x0,
                                    double x1)
For a random variable X whose values are distributed according to this distribution, this method returns P(x0 <= X <= x1).

Specified by:
cumulativeProbability in interface Distribution
Overrides:
cumulativeProbability in class AbstractDistribution
Parameters:
x0 - Inclusive lower bound.
x1 - Inclusive upper bound.
Returns:
the probability that a random variable with this distribution will take a value between x0 and x1, including the endpoints.
Throws:
NumberIsTooSmallException - if x1 > x0.

cumulativeProbability

public abstract double cumulativeProbability(int x)
For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x). In other words, this method represents the probability distribution function, or PDF, for this distribution.

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

probability

public double probability(double x)
For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function, or PMF, for the distribution. If x does not represent an integer value, 0 is returned.

Specified by:
probability in interface DiscreteDistribution
Parameters:
x - Value at which the probability density function is evaluated.
Returns:
the value of the probability density function at x.

cumulativeProbability

public double cumulativeProbability(int x0,
                                    int x1)
For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X < x1).

Specified by:
cumulativeProbability in interface IntegerDistribution
Parameters:
x0 - Inclusive lower bound.
x1 - Inclusive upper bound.
Returns:
the cumulative probability.
Throws:
NumberIsTooSmallException - if x0 > x1.

inverseCumulativeProbability

public int inverseCumulativeProbability(double p)
For a random variable X whose values are distributed according to this distribution, this method returns the largest x, such that P(X <= x) <= p.

Specified by:
inverseCumulativeProbability in interface IntegerDistribution
Parameters:
p - Desired probability.
Returns:
the largest x such that P(X < x) <= p.
Throws:
OutOfRangeException - if p < 0 or p > 1.

reseedRandomGenerator

public void reseedRandomGenerator(long seed)
Reseed the random generator used to generate samples.

Specified by:
reseedRandomGenerator in interface IntegerDistribution
Parameters:
seed - New seed.

sample

public int sample()
Generates a random value sampled from this distribution. The default implementation uses the inversion method.

Specified by:
sample in interface IntegerDistribution
Returns:
a random value.
Since:
2.2

sample

public int[] sample(int sampleSize)
Generates a random sample from the distribution. The default implementation generates the sample by calling sample() in a loop.

Specified by:
sample in interface IntegerDistribution
Parameters:
sampleSize - number of random values to generate.
Returns:
an array representing the random sample.
Throws:
NotStrictlyPositiveException - if sampleSize <= 0.
Since:
2.2

getDomainLowerBound

protected abstract int getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a PDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

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

getDomainUpperBound

protected abstract int getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a PDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

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

getSupportLowerBound

public abstract int getSupportLowerBound()
Access the lower bound of the support.

Returns:
lower bound of the support (Integer.MIN_VALUE for negative infinity)

getSupportUpperBound

public abstract int getSupportUpperBound()
Access the upper bound of the support.

Returns:
upper bound of the support (Integer.MAX_VALUE for positive infinity)

isSupportLowerBoundInclusive

public boolean isSupportLowerBoundInclusive()
Use this method to get information about whether the lower bound of the support is inclusive or not. For discrete support, only true here is meaningful.

Specified by:
isSupportLowerBoundInclusive in interface Distribution
Specified by:
isSupportLowerBoundInclusive in class AbstractDistribution
Returns:
true (always but at Integer.MIN_VALUE because of the nature of discrete support)

isSupportUpperBoundInclusive

public boolean isSupportUpperBoundInclusive()
Use this method to get information about whether the upper bound of the support is inclusive or not. For discrete support, only true here is meaningful.

Specified by:
isSupportUpperBoundInclusive in interface Distribution
Specified by:
isSupportUpperBoundInclusive in class AbstractDistribution
Returns:
true (always but at Integer.MAX_VALUE because of the nature of discrete support)


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