SSJ
V. 2.0.

umontreal.iro.lecuyer.randvarmulti
Class MultinormalCholeskyGen

java.lang.Object
  extended by umontreal.iro.lecuyer.randvarmulti.RandomMultivariateGen
      extended by umontreal.iro.lecuyer.randvarmulti.MultinormalCholeskyGen

public class MultinormalCholeskyGen
extends RandomMultivariateGen

Extends RandomMultivariateGen for a multivariate normal (or multinormal) distribution, generated via a Cholesky decomposition of the covariance matrix. The d-dimensional multivariate normal distribution with mean vector μRd and (symmetric positive-definite) covariance matrix Σ, denoted N(μ, Σ), has density

f (X) = $\displaystyle {\frac{1}{{\sqrt{(2\pi)^d\det(\boldSigma)}}}}$exp(- (X - μ)tΣ-1(X - μ)/2),

for all XRd. If ZN( 0,I) where I is the identity matrix, Z is said to have the standard multinormal distribution. For the special case of d = 2, if the random vector X = (X1, X2)t has a bivariate normal distribution, then it has mean μ = (μ1, μ2)t, and covariance matrix

Σ = [$\displaystyle \begin{array}{cc}
 \sigma_1^2 & \rho\sigma_1\sigma_2 \\
 \rho\sigma_1\sigma_2 &\sigma_2^2
 \end{array}$]

if and only if Var[X1] = σ12, Var[X2] = σ22, where σ1 > 0 and σ2 > 0, and the linear correlation between X1 and X2 is ρ.

In this class, the covariance matrix is decomposed (by the constructor) as Σ = AAt where A is a lower-triangular matrix (this is the Cholesky decomposition), and X is generated via

X = μ + AZ,

where Z is a d-dimensional vector of independent standard normal random variates. The constructor specifies how these normal variates are generated.


Constructor Summary
MultinormalCholeskyGen(NormalGen gen1, double[] mu, double[][] sigma)
          Equivalent to MultinormalCholeskyGen (gen1, mu, new DenseDoubleMatrix2D (sigma)).
MultinormalCholeskyGen(NormalGen gen1, double[] mu, DoubleMatrix2D sigma)
          Constructs a multinormal generator with mean vector mu and covariance matrix sigma.
MultinormalCholeskyGen(NormalGen gen1, int d)
          Constructs a generator with the standard multinormal distribution (with μ = 0 and Σ = I) in d dimensions.
 
Method Summary
 DoubleMatrix2D getCholeskyDecompSigma()
          Returns the lower-triangular matrix A in the Cholesky decomposition of Σ.
 double[] getMu()
          Returns the mean vector used by this generator.
 double getMu(int i)
          Returns the i-th component of the mean vector for this generator.
 DoubleMatrix2D getSigma()
          Returns the covariance matrix Σ used by this generator.
 void nextPoint(double[] p)
          Generates a point from this multinormal distribution.
static void nextPoint(NormalGen gen1, double[] mu, double[][] sigma, double[] p)
          Equivalent to nextPoint (gen1, mu, new DenseDoubleMatrix2D (sigma), p).
static void nextPoint(NormalGen gen1, double[] mu, DoubleMatrix2D sigma, double[] p)
          Generates a d-dimensional vector from the multinormal distribution with mean vector mu and covariance matrix sigma, using the one-dimensional normal generator gen1 to generate the coordinates of Z, and using the cholesky decomposition of Σ.
 void setMu(double[] mu)
          Sets the mean vector to mu.
 void setMu(int i, double mui)
          Sets the i-th component of the mean vector to mui.
 void setSigma(DoubleMatrix2D sigma)
          Sets the covariance matrix Σ of this multinormal generator to sigma (and recomputes A).
 
Methods inherited from class umontreal.iro.lecuyer.randvarmulti.RandomMultivariateGen
getDimension, getStream, nextArrayOfPoints, setStream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultinormalCholeskyGen

public MultinormalCholeskyGen(NormalGen gen1,
                              int d)
Constructs a generator with the standard multinormal distribution (with μ = 0 and Σ = I) in d dimensions. Each vector Z will be generated via d successive calls to gen1, which must be a standard normal generator.

Parameters:
gen1 - the one-dimensional generator
d - the dimension of the generated vectors
Throws:
IllegalArgumentException - if the one-dimensional normal generator uses a normal distribution with μ not equal to 0, or σ not equal to 1.
IllegalArgumentException - if d is negative.
NullPointerException - if gen1 is null.

MultinormalCholeskyGen

public MultinormalCholeskyGen(NormalGen gen1,
                              double[] mu,
                              DoubleMatrix2D sigma)
Constructs a multinormal generator with mean vector mu and covariance matrix sigma. The mean vector must have the same length as the dimensions of the covariance matrix, which must be symmetric and positive-definite. If any of the above conditions is violated, an exception is thrown. The vector Z is generated by calling d times the generator gen1, which must be standard normal.

Parameters:
gen1 - the one-dimensional generator
mu - the mean vector.
sigma - the covariance matrix.
Throws:
NullPointerException - if any argument is null.
IllegalArgumentException - if the length of the mean vector is incompatible with the dimensions of the covariance matrix.

MultinormalCholeskyGen

public MultinormalCholeskyGen(NormalGen gen1,
                              double[] mu,
                              double[][] sigma)
Equivalent to MultinormalCholeskyGen (gen1, mu, new DenseDoubleMatrix2D (sigma)).

Method Detail

getMu

public double[] getMu()
Returns the mean vector used by this generator.

Returns:
the current mean vector.

getMu

public double getMu(int i)
Returns the i-th component of the mean vector for this generator.

Parameters:
i - the index of the required component.
Returns:
the value of μi.
Throws:
ArrayIndexOutOfBoundsException - if i is negative or greater than or equal to getDimension.

setMu

public void setMu(double[] mu)
Sets the mean vector to mu.

Parameters:
mu - the new mean vector.
Throws:
NullPointerException - if mu is null.
IllegalArgumentException - if the length of mu does not correspond to getDimension.

setMu

public void setMu(int i,
                  double mui)
Sets the i-th component of the mean vector to mui.

Parameters:
i - the index of the modified component.
mui - the new value of μi.
Throws:
ArrayIndexOutOfBoundsException - if i is negative or greater than or equal to getDimension.

getSigma

public DoubleMatrix2D getSigma()
Returns the covariance matrix Σ used by this generator.

Returns:
the used covariance matrix.

getCholeskyDecompSigma

public DoubleMatrix2D getCholeskyDecompSigma()
Returns the lower-triangular matrix A in the Cholesky decomposition of Σ.

Returns:
the Cholesky decomposition of the covariance matrix.

setSigma

public void setSigma(DoubleMatrix2D sigma)
Sets the covariance matrix Σ of this multinormal generator to sigma (and recomputes A).

Parameters:
sigma - the new covariance matrix.
Throws:
IllegalArgumentException - if sigma has incorrect dimensions.

nextPoint

public static void nextPoint(NormalGen gen1,
                             double[] mu,
                             DoubleMatrix2D sigma,
                             double[] p)
Generates a d-dimensional vector from the multinormal distribution with mean vector mu and covariance matrix sigma, using the one-dimensional normal generator gen1 to generate the coordinates of Z, and using the cholesky decomposition of Σ. The resulting vector is put into p. Note that this static method may be very slow for large dimension, because it computes the Cholesky decomposition at every call. It is therefore recommended to use a MultinormalCholeskyGen object instead, as soon as the method is to be called more than once.

Parameters:
p - the array to be filled with the generated point.
Throws:
IllegalArgumentException - if the one-dimensional normal generator uses a normal distribution with μ not equal to 0, or σ not equal to 1.
IllegalArgumentException - if the length of the mean vector is different from the dimensions of the covariance matrix, or if the covariance matrix is not symmetric and positive-definite.
NullPointerException - if any argument is null.

nextPoint

public static void nextPoint(NormalGen gen1,
                             double[] mu,
                             double[][] sigma,
                             double[] p)
Equivalent to nextPoint (gen1, mu, new DenseDoubleMatrix2D (sigma), p).


nextPoint

public void nextPoint(double[] p)
Generates a point from this multinormal distribution.

Specified by:
nextPoint in class RandomMultivariateGen
Parameters:
p - the array to be filled with the generated point

SSJ
V. 2.0.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.