Class MultivariateNormalDistribution
- java.lang.Object
-
- org.apache.commons.math4.legacy.distribution.AbstractMultivariateRealDistribution
-
- org.apache.commons.math4.legacy.distribution.MultivariateNormalDistribution
-
- All Implemented Interfaces:
MultivariateRealDistribution
public class MultivariateNormalDistribution extends AbstractMultivariateRealDistribution
Implementation of the multivariate normal (Gaussian) distribution.- Since:
- 3.1
- See Also:
- Multivariate normal distribution (Wikipedia), Multivariate normal distribution (MathWorld)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.math4.legacy.distribution.MultivariateRealDistribution
MultivariateRealDistribution.Sampler
-
-
Constructor Summary
Constructors Constructor Description MultivariateNormalDistribution(double[] means, double[][] covariances)
Creates a multivariate normal distribution with the given mean vector and covariance matrix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultivariateRealDistribution.Sampler
createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Creates a sampler.double
density(double[] vals)
Returns the probability density function (PDF) of this distribution evaluated at the specified pointx
.RealMatrix
getCovariances()
Gets the covariance matrix.double[]
getMeans()
Gets the mean vector.double[]
getStandardDeviations()
Gets the square root of each element on the diagonal of the covariance matrix.-
Methods inherited from class org.apache.commons.math4.legacy.distribution.AbstractMultivariateRealDistribution
getDimension, sample
-
-
-
-
Constructor Detail
-
MultivariateNormalDistribution
public MultivariateNormalDistribution(double[] means, 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:
means
- Vector of means.covariances
- Covariance matrix.- Throws:
DimensionMismatchException
- if the arrays length are inconsistent.SingularMatrixException
- if the eigenvalue decomposition cannot be performed on the provided covariance matrix.NonPositiveDefiniteMatrixException
- if any of the eigenvalues is negative.
-
-
Method Detail
-
getMeans
public double[] getMeans()
Gets the mean vector.- Returns:
- the mean vector.
-
getCovariances
public RealMatrix getCovariances()
Gets the covariance matrix.- Returns:
- the covariance matrix.
-
density
public double density(double[] vals) throws DimensionMismatchException
Returns the probability density function (PDF) of this distribution evaluated at the specified pointx
. In general, the PDF is the derivative of the cumulative distribution function. 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.- Parameters:
vals
- Point at which the PDF is evaluated.- Returns:
- the value of the probability density function at point
x
. - Throws:
DimensionMismatchException
-
getStandardDeviations
public double[] getStandardDeviations()
Gets the square root of each element on the diagonal of the covariance matrix.- Returns:
- the standard deviations.
-
createSampler
public MultivariateRealDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Creates a sampler.- Specified by:
createSampler
in interfaceMultivariateRealDistribution
- Specified by:
createSampler
in classAbstractMultivariateRealDistribution
- Parameters:
rng
- Generator of uniformly distributed numbers.- Returns:
- a sampler that produces random numbers according this distribution.
-
-