org.apache.commons.math.distribution
Class AbstractContinuousDistribution

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractContinuousDistribution
All Implemented Interfaces:
java.io.Serializable, ContinuousDistribution, Distribution
Direct Known Subclasses:
BetaDistributionImpl, CauchyDistributionImpl, ChiSquaredDistributionImpl, ExponentialDistributionImpl, FDistributionImpl, GammaDistributionImpl, NormalDistributionImpl, TDistributionImpl, WeibullDistributionImpl

public abstract class AbstractContinuousDistribution
extends AbstractDistribution
implements ContinuousDistribution, java.io.Serializable

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

Version:
$Id: AbstractContinuousDistribution.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
static double SOLVER_DEFAULT_ABSOLUTE_ACCURACY
          Default accuracy.
 
Constructor Summary
protected AbstractContinuousDistribution()
          Default constructor.
 
Method Summary
abstract  double density(double x)
          Probability density for a particular point.
protected abstract  double getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a CDF root.
protected abstract  double getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a CDF root.
protected abstract  double getInitialDomain(double p)
          Access the initial domain value, based on p, used to bracket a CDF root.
protected  double getSolverAbsoluteAccuracy()
          Returns the solver absolute accuracy for inverse cumulative computation.
abstract  double getSupportLowerBound()
          Access the lower bound of the support.
abstract  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.
 void reseedRandomGenerator(long seed)
          Reseed the random generator used to generate samples.
 double sample()
          Generate a random value sampled from this distribution.
 double[] sample(int sampleSize)
          Generate a random sample from the distribution.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractDistribution
calculateNumericalMean, calculateNumericalVariance, cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive
 
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.Distribution
cumulativeProbability, cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive
 

Field Detail

SOLVER_DEFAULT_ABSOLUTE_ACCURACY

public static final double SOLVER_DEFAULT_ABSOLUTE_ACCURACY
Default accuracy.

See Also:
Constant Field Values

randomData

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

Since:
2.2
Constructor Detail

AbstractContinuousDistribution

protected AbstractContinuousDistribution()
Default constructor.

Method Detail

density

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

Specified by:
density in interface ContinuousDistribution
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
Parameters:
p - Desired probability.
Returns:
x, such that P(X < x) = p.
Throws:
OutOfRangeException - if p is not a valid probability.

reseedRandomGenerator

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

Specified by:
reseedRandomGenerator in interface ContinuousDistribution
Parameters:
seed - New seed.
Since:
2.2

sample

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

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

sample

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

Specified by:
sample in interface ContinuousDistribution
Parameters:
sampleSize - Number of random values to generate.
Returns:
an array representing the random sample.
Throws:
NotStrictlyPositiveException - if sampleSize is not positive.
Since:
2.2

getInitialDomain

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

Parameters:
p - Desired probability for the critical value.
Returns:
the initial domain value.

getDomainLowerBound

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

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

getDomainUpperBound

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

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

getSolverAbsoluteAccuracy

protected double getSolverAbsoluteAccuracy()
Returns the solver absolute accuracy for inverse cumulative computation. You can override this method in order to use a Brent solver with an absolute accuracy different from the default.

Returns:
the maximum absolute error in inverse cumulative probability estimates
Since:
2.1

getSupportLowerBound

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

Returns:
lower bound of the support (might be Double.NEGATIVE_INFINITY)

getSupportUpperBound

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

Returns:
upper bound of the support (might be Double.POSITIVE_INFINITY)


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