org.apache.commons.math.distribution
Class NormalDistributionImpl

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

public class NormalDistributionImpl
extends AbstractContinuousDistribution
implements NormalDistribution, java.io.Serializable

Default implementation of NormalDistribution.

Version:
$Id: NormalDistributionImpl.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
NormalDistributionImpl()
          Create a normal distribution with mean equal to zero and standard deviation equal to one.
NormalDistributionImpl(double mean, double sd)
          Create a normal distribution using the given mean and standard deviation.
NormalDistributionImpl(double mean, double sd, double inverseCumAccuracy)
          Create a normal distribution using the given mean, standard deviation and inverse cumulative distribution accuracy.
 
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 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.
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 getStandardDeviation()
          Access the standard deviation.
 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()
          Generate 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
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
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

NormalDistributionImpl

public NormalDistributionImpl(double mean,
                              double sd)
Create a normal distribution using the given mean and standard deviation.

Parameters:
mean - Mean for this distribution.
sd - Standard deviation for this distribution.

NormalDistributionImpl

public NormalDistributionImpl(double mean,
                              double sd,
                              double inverseCumAccuracy)
Create a normal distribution using the given mean, standard deviation and inverse cumulative distribution accuracy.

Parameters:
mean - Mean for this distribution.
sd - Standard deviation for this distribution.
inverseCumAccuracy - Inverse cumulative probability accuracy.
Throws:
NotStrictlyPositiveException - if sd <= 0.
Since:
2.1

NormalDistributionImpl

public NormalDistributionImpl()
Create a normal distribution with mean equal to zero and standard deviation equal to one.

Method Detail

getMean

public double getMean()
Access the mean.

Specified by:
getMean in interface NormalDistribution
Returns:
the mean for this distribution.

getStandardDeviation

public double getStandardDeviation()
Access the standard deviation.

Specified by:
getStandardDeviation in interface NormalDistribution
Returns:
the standard deviation for this distribution.

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). If xis more than 40 standard deviations from the mean, 0 or 1 is returned, as in these cases the actual value is within Double.MIN_VALUE of 0 or 1.

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

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 Double.NEGATIVE_INFINITY when p = 0 and Double.POSITIVE_INFINITY for 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.

sample

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

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

getSupportLowerBound

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

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

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

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 standard deviation parameter s, the variance is s^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.