Class LogNormalDistribution
- All Implemented Interfaces:
Serializable,RealDistribution
Parameters:
X is log-normally distributed if its natural logarithm log(X)
is normally distributed. The probability distribution function of X
is given by (for x > 0)
exp(-0.5 * ((ln(x) - m) / s)^2) / (s * sqrt(2 * pi) * x)
mis the scale parameter: this is the mean of the normally distributed natural logarithm of this distribution,sis the shape parameter: this is the standard deviation of the normally distributed natural logarithm of this distribution.
- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault inverse cumulative probability accuracy.Fields inherited from class org.apache.commons.math3.distribution.AbstractRealDistribution
random, randomData, SOLVER_DEFAULT_ABSOLUTE_ACCURACY -
Constructor Summary
ConstructorsConstructorDescriptionCreate a log-normal distribution, where the mean and standard deviation of thenormally distributednatural logarithm of the log-normal distribution are equal to zero and one respectively.LogNormalDistribution(double scale, double shape) Create a log-normal distribution using the specified scale and shape.LogNormalDistribution(double scale, double shape, double inverseCumAccuracy) Create a log-normal distribution using the specified scale, shape and inverse cumulative distribution accuracy.LogNormalDistribution(RandomGenerator rng, double scale, double shape) Creates a log-normal distribution.LogNormalDistribution(RandomGenerator rng, double scale, double shape, double inverseCumAccuracy) Creates a log-normal distribution. -
Method Summary
Modifier and TypeMethodDescriptiondoublecumulativeProbability(double x) For a random variableXwhose values are distributed according to this distribution, this method returnsP(X <= x).doublecumulativeProbability(double x0, double x1) Deprecated.doubledensity(double x) Returns the probability density function (PDF) of this distribution evaluated at the specified pointx.doubleUse this method to get the numerical value of the mean of this distribution.doubleUse this method to get the numerical value of the variance of this distribution.doublegetScale()Returns the scale parameter of this distribution.doublegetShape()Returns the shape parameter of this distribution.protected doubleReturns the solver absolute accuracy for inverse cumulative computation.doubleAccess the lower bound of the support.doubleAccess the upper bound of the support.booleanUse this method to get information about whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support.booleanWhether or not the lower bound of support is in the domain of the density function.booleanWhether or not the upper bound of support is in the domain of the density function.doublelogDensity(double x) Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified pointx.doubleprobability(double x0, double x1) For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).doublesample()Generate a random value sampled from this distribution.Methods inherited from class org.apache.commons.math3.distribution.AbstractRealDistribution
inverseCumulativeProbability, probability, reseedRandomGenerator, sample
-
Field Details
-
DEFAULT_INVERSE_ABSOLUTE_ACCURACY
Default inverse cumulative probability accuracy.- See Also:
-
-
Constructor Details
-
LogNormalDistribution
public LogNormalDistribution()Create a log-normal distribution, where the mean and standard deviation of thenormally distributednatural logarithm of the log-normal distribution are equal to zero and one respectively. In other words, the scale of the returned distribution is0, while its shape is1.Note: this constructor will implicitly create an instance of
Well19937cas random generator to be used for sampling only (seesample()andAbstractRealDistribution.sample(int)). In case no sampling is needed for the created distribution, it is advised to passnullas random generator via the appropriate constructors to avoid the additional initialisation overhead. -
LogNormalDistribution
Create a log-normal distribution using the specified scale and shape.Note: this constructor will implicitly create an instance of
Well19937cas random generator to be used for sampling only (seesample()andAbstractRealDistribution.sample(int)). In case no sampling is needed for the created distribution, it is advised to passnullas random generator via the appropriate constructors to avoid the additional initialisation overhead.- Parameters:
scale- the scale parameter of this distributionshape- the shape parameter of this distribution- Throws:
NotStrictlyPositiveException- ifshape <= 0.
-
LogNormalDistribution
public LogNormalDistribution(double scale, double shape, double inverseCumAccuracy) throws NotStrictlyPositiveException Create a log-normal distribution using the specified scale, shape and inverse cumulative distribution accuracy.Note: this constructor will implicitly create an instance of
Well19937cas random generator to be used for sampling only (seesample()andAbstractRealDistribution.sample(int)). In case no sampling is needed for the created distribution, it is advised to passnullas random generator via the appropriate constructors to avoid the additional initialisation overhead.- Parameters:
scale- the scale parameter of this distributionshape- the shape parameter of this distributioninverseCumAccuracy- Inverse cumulative probability accuracy.- Throws:
NotStrictlyPositiveException- ifshape <= 0.
-
LogNormalDistribution
public LogNormalDistribution(RandomGenerator rng, double scale, double shape) throws NotStrictlyPositiveException Creates a log-normal distribution.- Parameters:
rng- Random number generator.scale- Scale parameter of this distribution.shape- Shape parameter of this distribution.- Throws:
NotStrictlyPositiveException- ifshape <= 0.- Since:
- 3.3
-
LogNormalDistribution
public LogNormalDistribution(RandomGenerator rng, double scale, double shape, double inverseCumAccuracy) throws NotStrictlyPositiveException Creates a log-normal distribution.- Parameters:
rng- Random number generator.scale- Scale parameter of this distribution.shape- Shape parameter of this distribution.inverseCumAccuracy- Inverse cumulative probability accuracy.- Throws:
NotStrictlyPositiveException- ifshape <= 0.- Since:
- 3.1
-
-
Method Details
-
getScale
Returns the scale parameter of this distribution.- Returns:
- the scale parameter
-
getShape
Returns the shape parameter of this distribution.- Returns:
- the shape parameter
-
density
Returns the probability density function (PDF) of this distribution evaluated at the specified pointx. In general, the PDF is the derivative of theCDF. If the derivative does not exist atx, then an appropriate replacement should be returned, e.g.Double.POSITIVE_INFINITY,Double.NaN, or the limit inferior or limit superior of the difference quotient. For scalem, and shapesof this distribution, the PDF is given by0ifx <= 0,exp(-0.5 * ((ln(x) - m) / s)^2) / (s * sqrt(2 * pi) * x)otherwise.
- Parameters:
x- the point at which the PDF is evaluated- Returns:
- the value of the probability density function at point
x
-
logDensity
Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified pointx. In general, the PDF is the derivative of theCDF. If the derivative does not exist atx, then an appropriate replacement should be returned, e.g.Double.POSITIVE_INFINITY,Double.NaN, or the limit inferior or limit superior of the difference quotient. Note that due to the floating point precision and under/overflow issues, this method will for some distributions be more precise and faster than computing the logarithm ofRealDistribution.density(double). The default implementation simply computes the logarithm ofdensity(x). See documentation ofdensity(double)for computation details.- Overrides:
logDensityin classAbstractRealDistribution- Parameters:
x- the point at which the PDF is evaluated- Returns:
- the logarithm of the value of the probability density function at point
x
-
cumulativeProbability
For a random variableXwhose values are distributed according to this distribution, this method returnsP(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution. For scalem, and shapesof this distribution, the CDF is given by0ifx <= 0,0ifln(x) - m < 0andm - ln(x) > 40 * s, as in these cases the actual value is withinDouble.MIN_VALUEof 0,1ifln(x) - m >= 0andln(x) - m > 40 * s, as in these cases the actual value is withinDouble.MIN_VALUEof 1,0.5 + 0.5 * erf((ln(x) - m) / (s * sqrt(2))otherwise.
- Parameters:
x- the point at which the CDF is evaluated- Returns:
- the probability that a random variable with this
distribution takes a value less than or equal to
x
-
cumulativeProbability
@Deprecated public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException Deprecated.For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1). The default implementation uses the identityP(x0 < X <= x1) = P(X <= x1) - P(X <= x0)- Specified by:
cumulativeProbabilityin interfaceRealDistribution- Overrides:
cumulativeProbabilityin classAbstractRealDistribution- Parameters:
x0- the exclusive lower boundx1- the inclusive upper bound- 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
-
probability
For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).- Overrides:
probabilityin classAbstractRealDistribution- 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)
-
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.- Overrides:
getSolverAbsoluteAccuracyin classAbstractRealDistribution- Returns:
- the maximum absolute error in inverse cumulative probability estimates
-
getNumericalMean
Use this method to get the numerical value of the mean of this distribution. For scalemand shapes, the mean isexp(m + s^2 / 2).- Returns:
- the mean or
Double.NaNif it is not defined
-
getNumericalVariance
Use this method to get the numerical value of the variance of this distribution. For scalemand shapes, the variance is(exp(s^2) - 1) * exp(2 * m + s^2).- Returns:
- the variance (possibly
Double.POSITIVE_INFINITYas for certain cases inTDistribution) orDouble.NaNif it is not defined
-
getSupportLowerBound
Access the lower bound of the support. This method must return the same value asinverseCumulativeProbability(0). In other words, this method must return
The lower bound of the support is always 0 no matter the parameters.inf {x in R | P(X invalid input: '<'= x) > 0}.- Returns:
- lower bound of the support (always 0)
-
getSupportUpperBound
Access the upper bound of the support. This method must return the same value asinverseCumulativeProbability(1). In other words, this method must return
The upper bound of the support is always positive infinity no matter the parameters.inf {x in R | P(X invalid input: '<'= x) = 1}.- Returns:
- upper bound of the support (always
Double.POSITIVE_INFINITY)
-
isSupportLowerBoundInclusive
Whether or not the lower bound of support is in the domain of the density function. Returns true iffgetSupporLowerBound()is finite anddensity(getSupportLowerBound())returns a non-NaN, non-infinite value.- Returns:
- true if the lower bound of support is finite and the density function returns a non-NaN, non-infinite value there
-
isSupportUpperBoundInclusive
Whether or not the upper bound of support is in the domain of the density function. Returns true iffgetSupportUpperBound()is finite anddensity(getSupportUpperBound())returns a non-NaN, non-infinite value.- Returns:
- true if the upper bound of support is finite and the density function returns a non-NaN, non-infinite value there
-
isSupportConnected
Use this method to get information about whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support. The support of this distribution is connected.- Returns:
true
-
sample
Generate a random value sampled from this distribution. The default implementation uses the inversion method.- Specified by:
samplein interfaceRealDistribution- Overrides:
samplein classAbstractRealDistribution- Returns:
- a random value.
-
RealDistribution.cumulativeProbability(double,double)