org.apache.commons.math.distribution
Class ExponentialDistributionImpl

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

public class ExponentialDistributionImpl
extends AbstractContinuousDistribution
implements ExponentialDistribution, java.io.Serializable

The default implementation of ExponentialDistribution.

Version:
$Id: ExponentialDistributionImpl.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
ExponentialDistributionImpl(double mean)
          Create a exponential distribution with the given mean.
ExponentialDistributionImpl(double mean, double inverseCumAccuracy)
          Create a exponential distribution with the given mean.
 
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.
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.
 double getMean()
          Access the mean.
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.
 double sample()
          Generates a random value sampled from this distribution.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractContinuousDistribution
reseedRandomGenerator, 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
 
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

ExponentialDistributionImpl

public ExponentialDistributionImpl(double mean)
Create a exponential distribution with the given mean.

Parameters:
mean - mean of this distribution.

ExponentialDistributionImpl

public ExponentialDistributionImpl(double mean,
                                   double inverseCumAccuracy)
Create a exponential distribution with the given mean.

Parameters:
mean - Mean of this distribution.
inverseCumAccuracy - Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).
Throws:
NotStrictlyPositiveException - if mean <= 0.
Since:
2.1
Method Detail

getMean

public double getMean()
Access the mean.

Specified by:
getMean in interface ExponentialDistribution
Returns:
the mean.

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.

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:
the 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 < 0 or p > 1.

sample

public double sample()
Generates a random value sampled from this distribution.

Algorithm Description: Uses the Inversion Method to generate exponentially distributed random values from uniform deviates.

Specified by:
sample in interface ContinuousDistribution
Overrides:
sample in class AbstractContinuousDistribution
Returns:
a random value.
Since:
2.2

getDomainLowerBound

protected double getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a CDF root.

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.

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.

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

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

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 mean parameter k, the mean is k

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 mean parameter k, the variance is k^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.