Package jline.lang.processes
Class MultivariateNormal
java.lang.Object
jline.lang.processes.Distribution
jline.lang.processes.ContinuousDistribution
jline.lang.processes.MultivariateNormal
- All Implemented Interfaces:
Serializable,Copyable
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:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionMultivariateNormal(double[] mu, Matrix Sigma) Creates a multivariate normal distribution.MultivariateNormal(Matrix mu, Matrix Sigma) Creates a multivariate normal distribution. -
Method Summary
Modifier and TypeMethodDescriptiondoubleevalCDF(double t) CDF is not well-defined for multivariate distributions.doubleevalLST(double s) LST is not well-defined for multivariate distributions.doubleevalPDF(double[] x) Evaluates the probability density function.doubleEvaluates the probability density function.Gets the correlation matrix from the covariance matrix.Gets the covariance matrix.intGets the dimensionality of this distribution.getMarginal(int[] indices) Extracts a marginal distribution for a subset of dimensions.getMarginalUniv(int index) Extracts a univariate marginal distribution.doublegetMean()Gets the mean of the first component (for Prior compatibility).Gets the mean vector.Gets the process representation with actual distribution parameters.doublegetSCV()Gets the squared coefficient of variation (not meaningful for multivariate).doubleGets the skewness.doublegetVar()Gets the variance of the first component.double[]Generates random samples from the distribution.sampleMatrix(int n, Random random) Generates random samples from the distribution.toString()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
-
Constructor Details
-
MultivariateNormal
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
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
Gets the mean vector.- Returns:
- d x 1 Matrix containing the mean
-
getCovariance
Gets the covariance matrix.- Returns:
- d x d Matrix containing the covariance
-
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:
getMeanin classDistribution- Returns:
- the mean of the first dimension
-
getVar
public double getVar()Gets the variance of the first component.- Overrides:
getVarin classDistribution- Returns:
- the variance of the first dimension
-
getSCV
public double getSCV()Gets the squared coefficient of variation (not meaningful for multivariate).- Specified by:
getSCVin classDistribution- Returns:
- Double.NaN (not defined for multivariate distributions)
-
getSkewness
public double getSkewness()Gets the skewness.- Specified by:
getSkewnessin classDistribution- Returns:
- 0.0 (multivariate normal is symmetric)
-
sample
Generates random samples from the distribution. Uses the Cholesky decomposition: X = mu + L*Z where Z ~ N(0, I).- Specified by:
samplein classDistribution- 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
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
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:
evalCDFin classDistribution- 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:
evalLSTin classContinuousDistribution- Parameters:
s- ignored- Returns:
- never returns
- Throws:
UnsupportedOperationException- always
-
getMarginal
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
Extracts a univariate marginal distribution.- Parameters:
index- dimension index to extract (0-based)- Returns:
- Normal distribution for that dimension
-
getProcess
Gets the process representation with actual distribution parameters.- Specified by:
getProcessin classContinuousDistribution- Returns:
- MatrixCell containing mu and Sigma
-
toString
-