Top Description Fields Constructors Methods
org.apache.commons.math3.distribution

public Class LogNormalDistribution

extends AbstractRealDistribution
Class Inheritance
Imports
org.apache.commons.math3.exception.NotStrictlyPositiveException, .NumberIsTooLargeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator, .Well19937c, org.apache.commons.math3.special.Erf, org.apache.commons.math3.util.FastMath

Implementation of the log-normal (gaussian) distribution.

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)

Since
3.0
See Also
Log-normal distribution (Wikipedia), Log Normal distribution (MathWorld)

Field Summary

Modifier and TypeField and Description
public static final double
DEFAULT_INVERSE_ABSOLUTE_ACCURACY

Default inverse cumulative probability accuracy.

private final double
logShapePlusHalfLog2Pi

The value of log(shape) + 0.5 * log(2*PI) stored for faster computation.

private final double
scale

The scale parameter of this distribution.

private static final long
private final double
shape

The shape parameter of this distribution.

private final double
private static final double
SQRT2

√(2)

private static final double
SQRT2PI

√(2 π)

Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
randomrandomDataSOLVER_DEFAULT_ABSOLUTE_ACCURACY

Constructor Summary

AccessConstructor and Description
public
LogNormalDistribution()

Create a log-normal distribution, where the mean and standard deviation of the normally distributed natural logarithm of the log-normal distribution are equal to zero and one respectively.

public
LogNormalDistribution(double
the scale parameter of this distribution
scale
,
double
the shape parameter of this distribution
shape
)

Create a log-normal distribution using the specified scale and shape.

public
LogNormalDistribution(double
the scale parameter of this distribution
scale
,
double
the shape parameter of this distribution
shape
,
double
Inverse cumulative probability accuracy.
inverseCumAccuracy
)

Create a log-normal distribution using the specified scale, shape and inverse cumulative distribution accuracy.

public
LogNormalDistribution(RandomGenerator
Random number generator.
rng
,
double
Scale parameter of this distribution.
scale
,
double
Shape parameter of this distribution.
shape
)

Creates a log-normal distribution.

public
LogNormalDistribution(RandomGenerator
Random number generator.
rng
,
double
Scale parameter of this distribution.
scale
,
double
Shape parameter of this distribution.
shape
,
double
Inverse cumulative probability accuracy.
inverseCumAccuracy
)

Creates a log-normal distribution.

Method Summary

Modifier and TypeMethod and Description
public double
cumulativeProbability(double
the point at which the CDF is evaluated
x
)

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x).

public double
cumulativeProbability(double
the exclusive lower bound
x0
,
double
the inclusive upper bound
x1
)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.cumulativeProbability.

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X <= x1).

public double
density(double
the point at which the PDF is evaluated
x
)

Implements org.apache.commons.math3.distribution.RealDistribution.density.

Returns the probability density function (PDF) of this distribution evaluated at the specified point x.

public double
getNumericalMean()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution.

public double
getNumericalVariance()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution.

public double

Returns:

the scale parameter
getScale
()

Returns the scale parameter of this distribution.

public double

Returns:

the shape parameter
getShape
()

Returns the shape parameter of this distribution.

protected double
getSolverAbsoluteAccuracy()

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.getSolverAbsoluteAccuracy.

Returns the solver absolute accuracy for inverse cumulative computation.

public double

Returns:

lower bound of the support (always 0)
getSupportLowerBound
()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Access the lower bound of the support.

public double

Returns:

upper bound of the support (always Double.POSITIVE_INFINITY)
getSupportUpperBound
()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Access the upper bound of the support.

public boolean

Returns:

true
isSupportConnected
()

Implements org.apache.commons.math3.distribution.RealDistribution.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.

public boolean
isSupportLowerBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Whether or not the lower bound of support is in the domain of the density function.

public boolean
isSupportUpperBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Whether or not the upper bound of support is in the domain of the density function.

public double
logDensity(double
the point at which the PDF is evaluated
x
)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.logDensity.

Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified point x.

public double
probability(double
Lower bound (excluded).
x0
,
double
Upper bound (included).
x1
)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X <= x1).

public double
Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
inverseCumulativeProbabilityprobabilityreseedRandomGeneratorsample

Field Detail

DEFAULT_INVERSE_ABSOLUTE_ACCURACYback to summary
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY

Default inverse cumulative probability accuracy.

logShapePlusHalfLog2Piback to summary
private final double logShapePlusHalfLog2Pi

The value of log(shape) + 0.5 * log(2*PI) stored for faster computation.

scaleback to summary
private final double scale

The scale parameter of this distribution.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.distribution.AbstractRealDistribution.serialVersionUID.

Serializable version identifier.

shapeback to summary
private final double shape

The shape parameter of this distribution.

solverAbsoluteAccuracyback to summary
private final double solverAbsoluteAccuracy

Hides org.apache.commons.math3.distribution.AbstractRealDistribution.solverAbsoluteAccuracy.

Inverse cumulative probability accuracy.

SQRT2back to summary
private static final double SQRT2

√(2)

SQRT2PIback to summary
private static final double SQRT2PI

√(2 π)

Constructor Detail

LogNormalDistributionback to summary
public LogNormalDistribution()

Create a log-normal distribution, where the mean and standard deviation of the normally distributed natural logarithm of the log-normal distribution are equal to zero and one respectively. In other words, the scale of the returned distribution is 0, while its shape is 1.

Note

this constructor will implicitly create an instance of Well19937c as random generator to be used for sampling only (see sample() and sample(int)). In case no sampling is needed for the created distribution, it is advised to pass null as random generator via the appropriate constructors to avoid the additional initialisation overhead.

LogNormalDistributionback to summary
public LogNormalDistribution(double scale, double shape) throws NotStrictlyPositiveException

Create a log-normal distribution using the specified scale and shape.

Note

this constructor will implicitly create an instance of Well19937c as random generator to be used for sampling only (see sample() and sample(int)). In case no sampling is needed for the created distribution, it is advised to pass null as random generator via the appropriate constructors to avoid the additional initialisation overhead.

Parameters
scale:double

the scale parameter of this distribution

shape:double

the shape parameter of this distribution

Exceptions
NotStrictlyPositiveException:
if shape <= 0.
LogNormalDistributionback to summary
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 Well19937c as random generator to be used for sampling only (see sample() and sample(int)). In case no sampling is needed for the created distribution, it is advised to pass null as random generator via the appropriate constructors to avoid the additional initialisation overhead.

Parameters
scale:double

the scale parameter of this distribution

shape:double

the shape parameter of this distribution

inverseCumAccuracy:double

Inverse cumulative probability accuracy.

Exceptions
NotStrictlyPositiveException:
if shape <= 0.
LogNormalDistributionback to summary
public LogNormalDistribution(RandomGenerator rng, double scale, double shape) throws NotStrictlyPositiveException

Creates a log-normal distribution.

Parameters
rng:RandomGenerator

Random number generator.

scale:double

Scale parameter of this distribution.

shape:double

Shape parameter of this distribution.

Exceptions
NotStrictlyPositiveException:
if shape <= 0.
Since
3.3
LogNormalDistributionback to summary
public LogNormalDistribution(RandomGenerator rng, double scale, double shape, double inverseCumAccuracy) throws NotStrictlyPositiveException

Creates a log-normal distribution.

Parameters
rng:RandomGenerator

Random number generator.

scale:double

Scale parameter of this distribution.

shape:double

Shape parameter of this distribution.

inverseCumAccuracy:double

Inverse cumulative probability accuracy.

Exceptions
NotStrictlyPositiveException:
if shape <= 0.
Since
3.1

Method Detail

cumulativeProbabilityback to summary
public double cumulativeProbability(double x)

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution. For scale m, and shape s of this distribution, the CDF is given by

  • 0 if x <= 0,
  • 0 if ln(x) - m < 0 and m - ln(x) > 40 * s, as in these cases the actual value is within Double.MIN_VALUE of 0,
  • 1 if ln(x) - m >= 0 and ln(x) - m > 40 * s, as in these cases the actual value is within Double.MIN_VALUE of 1,
  • 0.5 + 0.5 * erf((ln(x) - m) / (s * sqrt(2)) otherwise.
Parameters
x:double

the point at which the CDF is evaluated

Returns:double

the probability that a random variable with this distribution takes a value less than or equal to x

cumulativeProbabilityback to summary
public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.cumulativeProbability.

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.cumulativeProbability.

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)

Parameters
x0:double

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

the exclusive lower bound

x1:double

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

the inclusive upper bound

Returns:double

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

the probability that a random variable with this distribution takes a value between x0 and x1, excluding the lower and including the upper endpoint

Annotations
@Override
@Deprecated
Exceptions
NumberIsTooLargeException:

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

if x0 > x1

densityback to summary
public double density(double x)

Implements org.apache.commons.math3.distribution.RealDistribution.density.

Doc from org.apache.commons.math3.distribution.RealDistribution.density.

Returns the probability density function (PDF) of this distribution evaluated at the specified point x. In general, the PDF is the derivative of the CDF. If the derivative does not exist at x, 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 scale m, and shape s of this distribution, the PDF is given by

  • 0 if x <= 0,
  • exp(-0.5 * ((ln(x) - m) / s)^2) / (s * sqrt(2 * pi) * x) otherwise.
Parameters
x:double

the point at which the PDF is evaluated

Returns:double

the value of the probability density function at point x

getNumericalMeanback to summary
public double getNumericalMean()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Doc from org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution. For scale m and shape s, the mean is exp(m + s^2 / 2).

Returns:double

the mean or Double.NaN if it is not defined

getNumericalVarianceback to summary
public double getNumericalVariance()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Doc from org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution. For scale m and shape s, the variance is (exp(s^2) - 1) * exp(2 * m + s^2).

Returns:double

the variance (possibly Double.POSITIVE_INFINITY as for certain cases in TDistribution) or Double.NaN if it is not defined

getScaleback to summary
public double getScale()

Returns the scale parameter of this distribution.

Returns:double

the scale parameter

getShapeback to summary
public double getShape()

Returns the shape parameter of this distribution.

Returns:double

the shape parameter

getSolverAbsoluteAccuracyback to summary
protected double getSolverAbsoluteAccuracy()

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.getSolverAbsoluteAccuracy.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.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:double

the maximum absolute error in inverse cumulative probability estimates

Annotations
@Override
getSupportLowerBoundback to summary
public double getSupportLowerBound()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Doc from org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Access the lower bound of the support. This method must return the same value as inverseCumulativeProbability(0). In other words, this method must return

inf {x in R | P(X <= x) > 0}.

The lower bound of the support is always 0 no matter the parameters.
Returns:double

lower bound of the support (always 0)

getSupportUpperBoundback to summary
public double getSupportUpperBound()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Doc from org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Access the upper bound of the support. This method must return the same value as inverseCumulativeProbability(1). In other words, this method must return

inf {x in R | P(X <= x) = 1}.

The upper bound of the support is always positive infinity no matter the parameters.
Returns:double

upper bound of the support (always Double.POSITIVE_INFINITY)

isSupportConnectedback to summary
public boolean isSupportConnected()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Doc from org.apache.commons.math3.distribution.RealDistribution.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:boolean

true

isSupportLowerBoundInclusiveback to summary
public boolean isSupportLowerBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Whether or not the lower bound of support is in the domain of the density function. Returns true iff getSupporLowerBound() is finite and density(getSupportLowerBound()) returns a non-NaN, non-infinite value.

Returns:boolean

true if the lower bound of support is finite and the density function returns a non-NaN, non-infinite value there

isSupportUpperBoundInclusiveback to summary
public boolean isSupportUpperBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Whether or not the upper bound of support is in the domain of the density function. Returns true iff getSupportUpperBound() is finite and density(getSupportUpperBound()) returns a non-NaN, non-infinite value.

Returns:boolean

true if the upper bound of support is finite and the density function returns a non-NaN, non-infinite value there

logDensityback to summary
public double logDensity(double x)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.logDensity.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.logDensity.

Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified point x. In general, the PDF is the derivative of the CDF. If the derivative does not exist at x, 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 of density(double). The default implementation simply computes the logarithm of density(x). See documentation of density(double) for computation details.

Parameters
x:double

the point at which the PDF is evaluated

Returns:double

the logarithm of the value of the probability density function at point x

Annotations
@Override
probabilityback to summary
public double probability(double x0, double x1) throws NumberIsTooLargeException

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X <= x1).

Parameters
x0:double

Lower bound (excluded).

x1:double

Upper bound (included).

Returns:double

the probability that a random variable with this distribution takes a value between x0 and x1, excluding the lower and including the upper endpoint.

Annotations
@Override
Exceptions
NumberIsTooLargeException:
if x0 > x1. The default implementation uses the identity P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)
sampleback to summary
public double sample()

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.sample.

Implements org.apache.commons.math3.distribution.RealDistribution.sample.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.sample.

Generate a random value sampled from this distribution. The default implementation uses the inversion method.

Returns:double

Doc from org.apache.commons.math3.distribution.RealDistribution.sample.

a random value.

Annotations
@Override