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

public Class MultivariateNormalDistribution

extends AbstractMultivariateRealDistribution
Class Inheritance
Imports
org.apache.commons.math3.exception.DimensionMismatchException, org.apache.commons.math3.linear.Array2DRowRealMatrix, .EigenDecomposition, .NonPositiveDefiniteMatrixException, .RealMatrix, .SingularMatrixException, org.apache.commons.math3.random.RandomGenerator, .Well19937c, org.apache.commons.math3.util.FastMath, .MathArrays

Implementation of the multivariate normal (Gaussian) distribution.
Since
3.1
See Also
Multivariate normal distribution (Wikipedia), Multivariate normal distribution (MathWorld)

Field Summary

Modifier and TypeField and Description
private final RealMatrix
covarianceMatrix

Covariance matrix.

private final double
covarianceMatrixDeterminant

The determinant of the covariance matrix.

private final RealMatrix
covarianceMatrixInverse

The matrix inverse of the covariance matrix.

private final double[]
means

Vector of means.

private final RealMatrix
samplingMatrix

Matrix used in computation of samples.

Inherited from org.apache.commons.math3.distribution.AbstractMultivariateRealDistribution:
random

Constructor Summary

AccessConstructor and Description
public
MultivariateNormalDistribution(final double[]
Vector of means.
means
,
final double[][]
Covariance matrix.
covariances
)

Creates a multivariate normal distribution with the given mean vector and covariance matrix.

public
MultivariateNormalDistribution(RandomGenerator
Random Number Generator.
rng
,
final double[]
Vector of means.
means
,
final double[][]
Covariance matrix.
covariances
)

Creates a multivariate normal distribution with the given mean vector and covariance matrix.

Method Summary

Modifier and TypeMethod and Description
public double
density(final double[]
Point at which the PDF is evaluated.
vals
)

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

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

public RealMatrix

Returns:

the covariance matrix.
getCovariances
()

Gets the covariance matrix.

private double

Returns:

the multiplication factor of density calculations.
getExponentTerm
(final double[]
Values at which to compute density.
values
)

Computes the term used in the exponent (see definition of the distribution).

public double[]

Returns:

the mean vector.
getMeans
()

Gets the mean vector.

public double[]

Returns:

the standard deviations.
getStandardDeviations
()

Gets the square root of each element on the diagonal of the covariance matrix.

public double[]
Inherited from org.apache.commons.math3.distribution.AbstractMultivariateRealDistribution:
getDimensionreseedRandomGeneratorsample

Field Detail

covarianceMatrixback to summary
private final RealMatrix covarianceMatrix

Covariance matrix.

covarianceMatrixDeterminantback to summary
private final double covarianceMatrixDeterminant

The determinant of the covariance matrix.

covarianceMatrixInverseback to summary
private final RealMatrix covarianceMatrixInverse

The matrix inverse of the covariance matrix.

meansback to summary
private final double[] means

Vector of means.

samplingMatrixback to summary
private final RealMatrix samplingMatrix

Matrix used in computation of samples.

Constructor Detail

MultivariateNormalDistributionback to summary
public MultivariateNormalDistribution(final double[] means, final double[][] covariances) throws SingularMatrixException, DimensionMismatchException, NonPositiveDefiniteMatrixException

Creates a multivariate normal distribution with the given mean vector and covariance matrix.
The number of dimensions is equal to the length of the mean vector and to the number of rows and columns of the covariance matrix. It is frequently written as "p" in formulae.

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
means:double[]

Vector of means.

covariances:double[][]

Covariance matrix.

Exceptions
SingularMatrixException:
if the eigenvalue decomposition cannot be performed on the provided covariance matrix.
DimensionMismatchException:
if the arrays length are inconsistent.
NonPositiveDefiniteMatrixException:
if any of the eigenvalues is negative.
MultivariateNormalDistributionback to summary
public MultivariateNormalDistribution(RandomGenerator rng, final double[] means, final double[][] covariances) throws SingularMatrixException, DimensionMismatchException, NonPositiveDefiniteMatrixException

Creates a multivariate normal distribution with the given mean vector and covariance matrix.
The number of dimensions is equal to the length of the mean vector and to the number of rows and columns of the covariance matrix. It is frequently written as "p" in formulae.

Parameters
rng:RandomGenerator

Random Number Generator.

means:double[]

Vector of means.

covariances:double[][]

Covariance matrix.

Exceptions
SingularMatrixException:
if the eigenvalue decomposition cannot be performed on the provided covariance matrix.
DimensionMismatchException:
if the arrays length are inconsistent.
NonPositiveDefiniteMatrixException:
if any of the eigenvalues is negative.

Method Detail

densityback to summary
public double density(final double[] vals) throws DimensionMismatchException

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

Doc from org.apache.commons.math3.distribution.MultivariateRealDistribution.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 cumulative distribution function. 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.

Parameters
vals:double[]

Point at which the PDF is evaluated.

Returns:double

the value of the probability density function at point x.

getCovariancesback to summary
public RealMatrix getCovariances()

Gets the covariance matrix.

Returns:RealMatrix

the covariance matrix.

getExponentTermback to summary
private double getExponentTerm(final double[] values)

Computes the term used in the exponent (see definition of the distribution).

Parameters
values:double[]

Values at which to compute density.

Returns:double

the multiplication factor of density calculations.

getMeansback to summary
public double[] getMeans()

Gets the mean vector.

Returns:double[]

the mean vector.

getStandardDeviationsback to summary
public double[] getStandardDeviations()

Gets the square root of each element on the diagonal of the covariance matrix.

Returns:double[]

the standard deviations.

sampleback to summary
public double[] sample()

Implements abstract org.apache.commons.math3.distribution.AbstractMultivariateRealDistribution.sample.

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

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

Generates a random value vector sampled from this distribution.

Returns:double[]

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

a random value vector.

Annotations
@Override