org.apache.commons.math.distribution
Class GammaDistributionImpl

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.GammaDistributionImpl
All Implemented Interfaces:
java.io.Serializable, ContinuousDistribution, Distribution, GammaDistribution

public class GammaDistributionImpl
extends AbstractContinuousDistribution
implements GammaDistribution, java.io.Serializable

The default implementation of GammaDistribution.

Version:
$Id: GammaDistributionImpl.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
GammaDistributionImpl(double alpha, double beta)
          Create a new gamma distribution with the given alpha and beta values.
GammaDistributionImpl(double alpha, double beta, double inverseCumAccuracy)
          Create a new gamma distribution with the given alpha and beta values.
 
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 this distribution, X, this method returns P(X < x).
 double density(double x)
          Probability density for a particular point.
 double getAlpha()
          Access the alpha shape parameter.
 double getBeta()
          Access the beta scale 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
cumulativeProbability, 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
cumulativeProbability, 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

GammaDistributionImpl

public GammaDistributionImpl(double alpha,
                             double beta)
Create a new gamma distribution with the given alpha and beta values.

Parameters:
alpha - the shape parameter.
beta - the scale parameter.

GammaDistributionImpl

public GammaDistributionImpl(double alpha,
                             double beta,
                             double inverseCumAccuracy)
Create a new gamma distribution with the given alpha and beta values.

Parameters:
alpha - Shape parameter.
beta - Scale parameter.
inverseCumAccuracy - Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).
Throws:
NotStrictlyPositiveException - if alpha <= 0 or beta <= 0.
Since:
2.1
Method Detail

cumulativeProbability

public double cumulativeProbability(double x)
For this distribution, X, this method returns P(X < x). The implementation of this method is based on:

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

inverseCumulativeProbability

public double inverseCumulativeProbability(double p)
For this distribution, X, this method returns the critical point x, such that P(X < x) = p. It will return 0 when p = 0 and Double.POSITIVE_INFINITY when p = 1.

Specified by:
inverseCumulativeProbability in interface ContinuousDistribution
Overrides:
inverseCumulativeProbability in class AbstractContinuousDistribution
Parameters:
p - Desired probability.
Returns:
x, such that P(X < x) = p.
Throws:
OutOfRangeException - if p is not a valid probability.

getAlpha

public double getAlpha()
Access the alpha shape parameter.

Specified by:
getAlpha in interface GammaDistribution
Returns:
alpha.

getBeta

public double getBeta()
Access the beta scale parameter.

Specified by:
getBeta in interface GammaDistribution
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.

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 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 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.

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 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.

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 positive infinity no matter the parameters.

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

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 shape parameter alpha and scale parameter beta, the mean is alpha * beta

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 shape parameter alpha and scale parameter beta, the variance is alpha * beta^2

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.