org.apache.commons.math3.distribution

## Class MultivariateNormalDistribution

- java.lang.Object
- - org.apache.commons.math3.distribution.AbstractMultivariateRealDistribution
  - - org.apache.commons.math3.distribution.MultivariateNormalDistribution

- All Implemented Interfaces:
    MultivariateRealDistribution

      public class MultivariateNormalDistribution
      extends AbstractMultivariateRealDistribution

  Implementation of the multivariate normal (Gaussian) distribution.
  Since:
    3.1
  Version:
    $Id: MultivariateNormalDistribution.java 1416643 2012-12-03 19:37:14Z tn $
  See Also:
    Multivariate normal distribution (Wikipedia), Multivariate normal distribution (MathWorld)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private RealMatrix` | `covarianceMatrix` Covariance matrix.
    `private double` | `covarianceMatrixDeterminant` The determinant of the covariance matrix.
    `private RealMatrix` | `covarianceMatrixInverse` The matrix inverse of the covariance matrix.
    `private double[]` | `means` Vector of means.
    `private RealMatrix` | `samplingMatrix` Matrix used in computation of samples.

    - ### Fields inherited from class org.apache.commons.math3.distribution.AbstractMultivariateRealDistribution

      `random`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MultivariateNormalDistribution(double[] means, double[][] covariances)` Creates a multivariate normal distribution with the given mean vector and covariance matrix.
    `MultivariateNormalDistribution(RandomGenerator rng, double[] means, double[][] covariances)` Creates a multivariate normal distribution with the given mean vector and covariance matrix.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `density(double[] vals)` Returns the probability density function (PDF) of this distribution evaluated at the specified point `x`.
    `RealMatrix` | `getCovariances()` Gets the covariance matrix.
    `private double` | `getExponentTerm(double[] values)` Computes the term used in the exponent (see definition of the distribution).
    `double[]` | `getMeans()` Gets the mean vector.
    `double[]` | `getStandardDeviations()` Gets the square root of each element on the diagonal of the covariance matrix.
    `double[]` | `sample()` Generates a random value vector sampled from this distribution.

    - ### Methods inherited from class org.apache.commons.math3.distribution.AbstractMultivariateRealDistribution

      `getDimension, reseedRandomGenerator, sample`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### means

          private final double[] means

      Vector of means.

    - #### covarianceMatrix

          private final RealMatrix covarianceMatrix

      Covariance matrix.

    - #### covarianceMatrixInverse

          private final RealMatrix covarianceMatrixInverse

      The matrix inverse of the covariance matrix.

    - #### covarianceMatrixDeterminant

          private final double covarianceMatrixDeterminant

      The determinant of the covariance matrix.

    - #### samplingMatrix

          private final RealMatrix samplingMatrix

      Matrix used in computation of samples.

  - ### 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.

    - #### MultivariateNormalDistribution

          public MultivariateNormalDistribution(RandomGenerator rng,
                                        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:
        `rng` - Random Number Generator.
        `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 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` - 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.

    - #### sample

          public double[] sample()

      Generates a random value vector sampled from this distribution.
      Specified by:
        `sample` in interface `MultivariateRealDistribution`
      Specified by:
        `sample` in class `AbstractMultivariateRealDistribution`
      Returns:
        a random value vector.

    - #### getExponentTerm

          private double getExponentTerm(double[] values)

      Computes the term used in the exponent (see definition of the distribution).
      Parameters:
        `values` - Values at which to compute density.
      Returns:
        the multiplication factor of density calculations.

Copyright (c) 2003-2013 Apache Software Foundation