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:
$Revision: 920558 $ $Date: 2010-03-08 17:57:32 -0500 (Mon, 08 Mar 2010) $
See Also:
Serialized Form

Field Summary
private static java.lang.String OUT_OF_RANGE_POINT
          Message for out of range point.
private static long serialVersionUID
          Serializable version identifier
private static java.lang.String WRONG_ORDER_ENDPOINTS_MESSAGE
          Message for endpoints in wrong order.
 
Constructor Summary
protected AbstractIntegerDistribution()
          Default constructor.
 
Method Summary
private  double checkedCumulativeProbability(int argument)
          Computes the cumulative probablity function and checks for NaN values returned.
 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.
 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.
 double probability(double x)
          For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).
 
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
 

Field Detail

WRONG_ORDER_ENDPOINTS_MESSAGE

private static final java.lang.String WRONG_ORDER_ENDPOINTS_MESSAGE
Message for endpoints in wrong order.

See Also:
Constant Field Values

OUT_OF_RANGE_POINT

private static final java.lang.String OUT_OF_RANGE_POINT
Message for out of range point.

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
Serializable version identifier

See Also:
Constant Field Values
Constructor Detail

AbstractIntegerDistribution

protected AbstractIntegerDistribution()
Default constructor.

Method Detail

cumulativeProbability

public double cumulativeProbability(double x)
                             throws MathException
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 - the value at which the distribution function is evaluated.
Returns:
cumulative probability that a random variable with this distribution takes a value less than or equal to x
Throws:
MathException - if the cumulative probability can not be computed due to convergence or other numerical errors.

cumulativeProbability

public double cumulativeProbability(double x0,
                                    double x1)
                             throws MathException
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 - the (inclusive) lower bound
x1 - the (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:
MathException - if the cumulative probability can not be computed due to convergence or other numerical errors.
java.lang.IllegalArgumentException - if x0 > x1

cumulativeProbability

public abstract double cumulativeProbability(int x)
                                      throws MathException
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 - the value at which the PDF is evaluated.
Returns:
PDF for this distribution.
Throws:
MathException - if the cumulative probability can not be computed due to convergence or other numerical errors.

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 - the 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)
                             throws MathException
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 - the inclusive, lower bound
x1 - the inclusive, upper bound
Returns:
the cumulative probability.
Throws:
MathException - if the cumulative probability can not be computed due to convergence or other numerical errors.
java.lang.IllegalArgumentException - if x0 > x1

inverseCumulativeProbability

public int inverseCumulativeProbability(double p)
                                 throws MathException
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 - the desired probability
Returns:
the largest x such that P(X ≤ x) <= p
Throws:
MathException - if the inverse cumulative probability can not be computed due to convergence or other numerical errors.
java.lang.IllegalArgumentException - if p < 0 or p > 1

checkedCumulativeProbability

private double checkedCumulativeProbability(int argument)
                                     throws FunctionEvaluationException
Computes the cumulative probablity function and checks for NaN values returned. Throws MathException if the value is NaN. Wraps and rethrows any MathException encountered evaluating the cumulative probability function in a FunctionEvaluationException. Throws FunctionEvaluationException of the cumulative probability function returns NaN.

Parameters:
argument - input value
Returns:
cumulative probability
Throws:
FunctionEvaluationException - if a MathException occurs computing the cumulative probability

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 - the desired probability for the critical value
Returns:
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 - the desired probability for the critical value
Returns:
domain value upper bound, i.e. P(X < upper bound) > p


Copyright (c) 2003-2012 Apache Software Foundation