org.apache.commons.math.distribution
Class BetaDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractContinuousDistribution
          extended by org.apache.commons.math.distribution.BetaDistributionImpl
All Implemented Interfaces:
java.io.Serializable, BetaDistribution, ContinuousDistribution, Distribution

public class BetaDistributionImpl
extends AbstractContinuousDistribution
implements BetaDistribution

Implements the Beta distribution.

References:

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

Field Summary
static double DEFAULT_INVERSE_ABSOLUTE_ACCURACY
          Default inverse cumulative probability accuracy.
 
Fields inherited from class org.apache.commons.math.distribution.AbstractContinuousDistribution
randomData, SOLVER_DEFAULT_ABSOLUTE_ACCURACY
 
Constructor Summary
BetaDistributionImpl(double alpha, double beta)
          Build a new instance.
BetaDistributionImpl(double alpha, double beta, double inverseCumAccuracy)
          Build a new instance.
 
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(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).
 double density(double x)
          Probability density for a particular point.
 double getAlpha()
          Access the alpha shape parameter.
 double getBeta()
          Access the beta shape parameter.
protected  double getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a CDF root.
protected  double getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a CDF root.
protected  double getInitialDomain(double p)
          Access the initial domain value, based on p, used to bracket a CDF root.
protected  double getSolverAbsoluteAccuracy()
          Return the absolute accuracy setting of the solver used to estimate inverse cumulative probabilities.
 double getSupportLowerBound()
          Access the lower bound of the support.
 double getSupportUpperBound()
          Access the upper bound of the support.
 double inverseCumulativeProbability(double p)
          For this distribution, X, this method returns the critical point 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.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractContinuousDistribution
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.ContinuousDistribution
reseedRandomGenerator, sample, sample
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
getNumericalMean, getNumericalVariance, isSupportConnected
 

Field Detail

DEFAULT_INVERSE_ABSOLUTE_ACCURACY

public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY
Default inverse cumulative probability accuracy.

Since:
2.1
See Also:
Constant Field Values
Constructor Detail

BetaDistributionImpl

public BetaDistributionImpl(double alpha,
                            double beta,
                            double inverseCumAccuracy)
Build a new instance.

Parameters:
alpha - First shape parameter (must be positive).
beta - Second shape parameter (must be positive).
inverseCumAccuracy - Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).
Since:
2.1

BetaDistributionImpl

public BetaDistributionImpl(double alpha,
                            double beta)
Build a new instance.

Parameters:
alpha - First shape parameter (must be positive).
beta - Second shape parameter (must be positive).
Method Detail

getAlpha

public double getAlpha()
Access the alpha shape parameter.

Specified by:
getAlpha in interface BetaDistribution
Returns:
alpha.

getBeta

public double getBeta()
Access the beta shape parameter.

Specified by:
getBeta in interface BetaDistribution
Returns:
beta.

density

public double density(double x)
Probability density for a particular point.

Specified by:
density in interface ContinuousDistribution
Specified by:
density in class AbstractContinuousDistribution
Parameters:
x - Point at which the density should be computed.
Returns:
the pdf at point x.

inverseCumulativeProbability

public double inverseCumulativeProbability(double p)
For this distribution, X, this method returns the critical point x, such that P(X < x) = p.

Specified by:
inverseCumulativeProbability in interface ContinuousDistribution
Overrides:
inverseCumulativeProbability in class AbstractContinuousDistribution
Parameters:
p - Desired probability.
Returns:
x, such that P(X < x) = p.

getInitialDomain

protected double getInitialDomain(double p)
Access the initial domain value, based on p, used to bracket a CDF root. This method is used by AbstractContinuousDistribution.inverseCumulativeProbability(double) to find critical values.

Specified by:
getInitialDomain in class AbstractContinuousDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the initial domain value.

getDomainLowerBound

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

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

getDomainUpperBound

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

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

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.

Specified by:
cumulativeProbability in interface Distribution
Parameters:
x - the value at which the distribution function is evaluated.
Returns:
the 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).

The default implementation uses the identity

P(x0 ≤ X ≤ x1) = P(X ≤ x1) - P(X ≤ x0)

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.

getSolverAbsoluteAccuracy

protected double getSolverAbsoluteAccuracy()
Return the absolute accuracy setting of the solver used to estimate inverse cumulative probabilities.

Overrides:
getSolverAbsoluteAccuracy in class AbstractContinuousDistribution
Returns:
the solver absolute accuracy.
Since:
2.1

getSupportLowerBound

public double getSupportLowerBound()
Access the lower bound of the support. The lower bound of the support is always 0 no matter the parameters.

Specified by:
getSupportLowerBound in class AbstractContinuousDistribution
Returns:
lower bound of the support (always 0)

getSupportUpperBound

public double getSupportUpperBound()
Access the upper bound of the support. The upper bound of the support is always 1 no matter the parameters.

Specified by:
getSupportUpperBound in class AbstractContinuousDistribution
Returns:
upper bound of the support (always 1)

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 first shape parameter s1 and second shape parameter s2, the mean is s1 / (s1 + s2)

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 first shape parameter s1 and second shape parameter s2, the variance is [ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ]

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

isSupportLowerBoundInclusive

public boolean isSupportLowerBoundInclusive()
Use this method to get information about whether the lower bound of the support is inclusive or not.

Specified by:
isSupportLowerBoundInclusive in interface Distribution
Specified by:
isSupportLowerBoundInclusive in class AbstractDistribution
Returns:
whether the lower bound of the support is inclusive or not

isSupportUpperBoundInclusive

public boolean isSupportUpperBoundInclusive()
Use this method to get information about whether the upper bound of the support is inclusive or not.

Specified by:
isSupportUpperBoundInclusive in interface Distribution
Specified by:
isSupportUpperBoundInclusive in class AbstractDistribution
Returns:
whether the upper bound of the support is inclusive or not


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