Class MultivariateNormal
-
- All Implemented Interfaces:
-
java.io.Serializable,jline.lang.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.
-
-
Constructor Summary
Constructors Constructor Description MultivariateNormal(Array<double> mu, Matrix Sigma)Creates a multivariate normal distribution. MultivariateNormal(Matrix mu, Matrix Sigma)Creates a multivariate normal distribution.
-
Method Summary
Modifier and Type Method Description intgetDimension()Gets the dimensionality of this distribution. MatrixgetMeanVector()Gets the mean vector. MatrixgetCovariance()Gets the covariance matrix. MatrixgetCorrelation()Gets the correlation matrix from the covariance matrix. doublegetMean()Gets the mean of the first component (for Prior compatibility). doublegetVar()Gets the variance of the first component. doublegetSCV()Gets the squared coefficient of variation (not meaningful for multivariate). doublegetSkewness()Gets the skewness. Array<double>sample(int n, Random random)Generates random samples from the distribution. MatrixsampleMatrix(int n, Random random)Generates random samples from the distribution. doubleevalPDF(Matrix x)Evaluates the probability density function. doubleevalPDF(Array<double> x)Evaluates the probability density function. doubleevalCDF(double t)CDF is not well-defined for multivariate distributions. doubleevalLST(double s)LST is not well-defined for multivariate distributions. MultivariateNormalgetMarginal(Array<int> indices)Extracts a marginal distribution for a subset of dimensions. NormalgetMarginalUniv(int index)Extracts a univariate marginal distribution. MatrixCellgetProcess()Gets the process representation with actual distribution parameters. StringtoString()-
Methods inherited from class jline.lang.processes.Distribution
evalProbInterval, getName, getNumParams, getParam, getRate, getSupport, isContinuous, isDisabled, isDiscrete, isImmediate, isMarkovian, mean, name, numParams, param, rate, sample, scv, setNumParams, setParam, skewness, support, var -
Methods inherited from class jline.lang.Copyable
copy -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getDimension
int getDimension()
Gets the dimensionality of this distribution.
- Returns:
the number of dimensions d
-
getMeanVector
Matrix getMeanVector()
Gets the mean vector.
- Returns:
d x 1 Matrix containing the mean
-
getCovariance
Matrix getCovariance()
Gets the covariance matrix.
- Returns:
d x d Matrix containing the covariance
-
getCorrelation
Matrix getCorrelation()
Gets the correlation matrix from the covariance matrix.
- Returns:
d x d Matrix containing the correlation coefficients
-
getMean
double getMean()
Gets the mean of the first component (for Prior compatibility). For multivariate use, prefer getMeanVector().
- Returns:
the mean of the first dimension
-
getVar
double getVar()
Gets the variance of the first component.
- Returns:
the variance of the first dimension
-
getSCV
double getSCV()
Gets the squared coefficient of variation (not meaningful for multivariate).
- Returns:
Double.NaN (not defined for multivariate distributions)
-
getSkewness
double getSkewness()
Gets the skewness.
- Returns:
0.0 (multivariate normal is symmetric)
-
sample
Array<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).
- Parameters:
n- the number of samples to generaterandom- the random number generator to use- Returns:
flattened array of n*d samples (each dimension is a column)
-
sampleMatrix
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 generaterandom- the random number generator to use- Returns:
n x d Matrix of samples
-
evalPDF
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
double evalPDF(Array<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
double evalCDF(double t)
CDF is not well-defined for multivariate distributions.
- Parameters:
t- ignored- Returns:
never returns
-
evalLST
double evalLST(double s)
LST is not well-defined for multivariate distributions.
- Parameters:
s- ignored- Returns:
never returns
-
getMarginal
MultivariateNormal getMarginal(Array<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
Normal getMarginalUniv(int index)
Extracts a univariate marginal distribution.
- Parameters:
index- dimension index to extract (0-based)- Returns:
Normal distribution for that dimension
-
getProcess
MatrixCell getProcess()
Gets the process representation with actual distribution parameters.
- Returns:
MatrixCell containing mu and Sigma
-
-
-
-