Class AbstractRealDistribution
- java.lang.Object
-
- org.apache.commons.math4.distribution.AbstractRealDistribution
-
- All Implemented Interfaces:
java.io.Serializable,RealDistribution,ContinuousDistribution
- Direct Known Subclasses:
EmpiricalDistribution
public abstract class AbstractRealDistribution extends java.lang.Object implements RealDistribution, java.io.Serializable
Base class for probability distributions on the reals. Default implementations are provided for some of the methods that do not vary from distribution to distribution.This base class provides a default factory method for creating a
sampler instancethat uses the inversion method for generating random samples that follow the distribution.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.ContinuousDistribution
ContinuousDistribution.Sampler
-
-
Field Summary
Fields Modifier and Type Field Description static doubleSOLVER_DEFAULT_ABSOLUTE_ACCURACYDefault absolute accuracy for inverse cumulative computation.
-
Constructor Summary
Constructors Constructor Description AbstractRealDistribution()
-
Method Summary
Modifier and Type Method Description ContinuousDistribution.SamplercreateSampler(UniformRandomProvider rng)Creates a sampler.protected doublegetSolverAbsoluteAccuracy()Returns the solver absolute accuracy for inverse cumulative computation.doubleinverseCumulativeProbability(double p)Computes the quantile function of this distribution.doublelogDensity(double x)Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified pointx.doubleprobability(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x).doubleprobability(double x0, double x1)For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).static double[]sample(int n, ContinuousDistribution.Sampler sampler)Utility function for allocating an array and filling it withnsamples generated by the givensampler.-
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.statistics.distribution.ContinuousDistribution
cumulativeProbability, density, getMean, getSupportLowerBound, getSupportUpperBound, getVariance, isSupportConnected
-
-
-
-
Field Detail
-
SOLVER_DEFAULT_ABSOLUTE_ACCURACY
public static final double SOLVER_DEFAULT_ABSOLUTE_ACCURACY
Default absolute accuracy for inverse cumulative computation.- See Also:
- Constant Field Values
-
-
Method Detail
-
probability
public double probability(double x0, double x1)For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).- Specified by:
probabilityin interfaceContinuousDistribution- Parameters:
x0- Lower bound (excluded).x1- Upper bound (included).- Returns:
- the probability that a random variable with this distribution
takes a value between
x0andx1, excluding the lower and including the upper endpoint. - Throws:
NumberIsTooLargeException- ifx0 > x1. The default implementation uses the identityP(x0 < X <= x1) = P(X <= x1) - P(X <= x0)- Since:
- 3.1
-
inverseCumulativeProbability
public double inverseCumulativeProbability(double p) throws OutOfRangeExceptionComputes the quantile function of this distribution. For a random variableXdistributed according to this distribution, the returned value isinf{x in R | P(X<=x) >= p}for0 < p <= 1,inf{x in R | P(X<=x) > 0}forp = 0.
ContinuousDistribution.getSupportLowerBound()forp = 0,ContinuousDistribution.getSupportUpperBound()forp = 1.
- Specified by:
inverseCumulativeProbabilityin interfaceContinuousDistribution- Parameters:
p- Cumulative probability.- Returns:
- the smallest
p-quantile of this distribution (largest 0-quantile forp = 0). - Throws:
OutOfRangeException
-
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
-
probability
public double probability(double x)
For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.- Specified by:
probabilityin interfaceContinuousDistribution- Parameters:
x- Point at which the PMF is evaluated.- Returns:
- zero.
- Since:
- 3.1
-
logDensity
public double logDensity(double x)
Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified pointx.The default implementation simply computes the logarithm of
density(x).- Specified by:
logDensityin interfaceContinuousDistribution- Parameters:
x- Point at which the PDF is evaluated.- Returns:
- the logarithm of the value of the probability density function
at
x.
-
sample
public static double[] sample(int n, ContinuousDistribution.Sampler sampler)Utility function for allocating an array and filling it withnsamples generated by the givensampler.- Parameters:
n- Number of samples.sampler- Sampler.- Returns:
- an array of size
n.
-
createSampler
public ContinuousDistribution.Sampler createSampler(UniformRandomProvider rng)
Creates a sampler.- Specified by:
createSamplerin interfaceContinuousDistribution- Parameters:
rng- Generator of uniformly distributed numbers.- Returns:
- a sampler that produces random numbers according this distribution.
-
-