Class MultivariateNormal

All Implemented Interfaces:
Serializable, Copyable

public class MultivariateNormal extends ContinuousDistribution implements Serializable
A multivariate normal (Gaussian) distribution. Represents a d-dimensional normal distribution with mean vector mu and covariance matrix Sigma. The distribution can be used standalone or within a Prior for mixture models.
See Also:
  • Constructor Details

    • MultivariateNormal

      public MultivariateNormal(double[] mu, Matrix Sigma)
      Creates a multivariate normal distribution.
      Parameters:
      mu - Mean vector (d-dimensional)
      Sigma - Covariance matrix (d x d, must be positive definite)
      Throws:
      IllegalArgumentException - if Sigma is not positive definite or dimensions don't match
    • MultivariateNormal

      public MultivariateNormal(Matrix mu, Matrix Sigma)
      Creates a multivariate normal distribution.
      Parameters:
      mu - Mean vector (d x 1 Matrix)
      Sigma - Covariance matrix (d x d, must be positive definite)
      Throws:
      IllegalArgumentException - if Sigma is not positive definite or dimensions don't match
  • Method Details

    • getDimension

      public int getDimension()
      Gets the dimensionality of this distribution.
      Returns:
      the number of dimensions d
    • getMeanVector

      public Matrix getMeanVector()
      Gets the mean vector.
      Returns:
      d x 1 Matrix containing the mean
    • getCovariance

      public Matrix getCovariance()
      Gets the covariance matrix.
      Returns:
      d x d Matrix containing the covariance
    • getCorrelation

      public Matrix getCorrelation()
      Gets the correlation matrix from the covariance matrix.
      Returns:
      d x d Matrix containing the correlation coefficients
    • getMean

      public double getMean()
      Gets the mean of the first component (for Prior compatibility). For multivariate use, prefer getMeanVector().
      Specified by:
      getMean in class Distribution
      Returns:
      the mean of the first dimension
    • getVar

      public double getVar()
      Gets the variance of the first component.
      Overrides:
      getVar in class Distribution
      Returns:
      the variance of the first dimension
    • getSCV

      public double getSCV()
      Gets the squared coefficient of variation (not meaningful for multivariate).
      Specified by:
      getSCV in class Distribution
      Returns:
      Double.NaN (not defined for multivariate distributions)
    • getSkewness

      public double getSkewness()
      Gets the skewness.
      Specified by:
      getSkewness in class Distribution
      Returns:
      0.0 (multivariate normal is symmetric)
    • sample

      public double[] sample(int n, Random random)
      Generates random samples from the distribution. Uses the Cholesky decomposition: X = mu + L*Z where Z ~ N(0, I).
      Specified by:
      sample in class Distribution
      Parameters:
      n - the number of samples to generate
      random - the random number generator to use
      Returns:
      flattened array of n*d samples (each dimension is a column)
    • sampleMatrix

      public Matrix sampleMatrix(int n, Random random)
      Generates random samples from the distribution. Returns samples as an n x d matrix.
      Parameters:
      n - the number of samples to generate
      random - the random number generator to use
      Returns:
      n x d Matrix of samples
    • evalPDF

      public double evalPDF(Matrix x)
      Evaluates the probability density function.
      Parameters:
      x - the point at which to evaluate (d x 1 Matrix)
      Returns:
      the PDF value at x
    • evalPDF

      public double evalPDF(double[] x)
      Evaluates the probability density function.
      Parameters:
      x - the point at which to evaluate (d-dimensional array)
      Returns:
      the PDF value at x
    • evalCDF

      public double evalCDF(double t)
      CDF is not well-defined for multivariate distributions.
      Specified by:
      evalCDF in class Distribution
      Parameters:
      t - ignored
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - always
    • evalLST

      public double evalLST(double s)
      LST is not well-defined for multivariate distributions.
      Specified by:
      evalLST in class ContinuousDistribution
      Parameters:
      s - ignored
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - always
    • getMarginal

      public MultivariateNormal getMarginal(int[] indices)
      Extracts a marginal distribution for a subset of dimensions.
      Parameters:
      indices - array of dimension indices to keep (0-based)
      Returns:
      MultivariateNormal distribution for the marginal
    • getMarginalUniv

      public Normal getMarginalUniv(int index)
      Extracts a univariate marginal distribution.
      Parameters:
      index - dimension index to extract (0-based)
      Returns:
      Normal distribution for that dimension
    • getProcess

      public MatrixCell getProcess()
      Gets the process representation with actual distribution parameters.
      Specified by:
      getProcess in class ContinuousDistribution
      Returns:
      MatrixCell containing mu and Sigma
    • toString

      public String toString()
      Overrides:
      toString in class Object