25package umontreal.ssj.randvarmulti;
27import cern.colt.matrix.DoubleMatrix2D;
28import cern.colt.matrix.impl.DenseDoubleMatrix2D;
29import cern.colt.matrix.linalg.CholeskyDecomposition;
30import umontreal.ssj.probdist.NormalDist;
31import umontreal.ssj.randvar.NormalGen;
32import umontreal.ssj.rng.RandomStream;
56 private void initL() {
57 if (mu.length != sigma.rows() || mu.length != sigma.columns())
58 throw new IllegalArgumentException(
"Incompatible mean vector and covariance matrix");
59 CholeskyDecomposition decomp =
new CholeskyDecomposition(sigma);
63 sqrtSigma = decomp.getL();
80 super(gen1, mu, sigma);
101 super(gen1, mu, sigma);
112 return sqrtSigma.copy();
123 if (sigma.rows() != mu.length || sigma.columns() != mu.length)
124 throw new IllegalArgumentException(
"Invalid dimensions of covariance matrix");
125 CholeskyDecomposition decomp =
new CholeskyDecomposition(sigma);
129 this.sigma.assign(sigma);
130 this.sqrtSigma = decomp.getL();
138 nextPoint(gen1, mu,
new DenseDoubleMatrix2D(sigma), p);
165 throw new NullPointerException(
"gen1 is null");
168 if (dist.
getMu() != 0.0)
169 throw new IllegalArgumentException(
"mu != 0");
171 throw new IllegalArgumentException(
"sigma != 1");
173 if (mu.length != sigma.rows() || mu.length != sigma.columns())
174 throw new IllegalArgumentException(
"Incompatible mean vector and covariance matrix dimensions");
175 CholeskyDecomposition decomp =
new CholeskyDecomposition(sigma);
176 double[] temp =
new double[mu.length];
177 DoubleMatrix2D sqrtSigma = decomp.getL();
178 for (
int i = 0; i < temp.length; i++) {
179 temp[i] = gen1.nextDouble();
180 if (temp[i] == Double.NEGATIVE_INFINITY)
182 if (temp[i] == Double.POSITIVE_INFINITY)
185 for (
int i = 0; i < temp.length; i++) {
187 for (
int c = 0; c <= i; c++)
188 p[i] += sqrtSigma.getQuick(i, c) * temp[c];
202 for (
int i = 0; i < n; i++) {
203 temp[i] = gen1.nextDouble();
204 if (temp[i] == Double.NEGATIVE_INFINITY)
206 if (temp[i] == Double.POSITIVE_INFINITY)
209 for (
int i = 0; i < n; i++) {
212 for (
int c = 0; c <= i; c++)
213 p[i] += sqrtSigma.getQuick(i, c) * temp[c];
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a (page 80)).
double getMu()
Returns the parameter .
double getSigma()
Returns the parameter .
This class implements methods for generating random variates from the normal distribution .
void setSigma(DoubleMatrix2D sigma)
Sets the covariance matrix of this multinormal generator to sigma (and recomputes ).
MultinormalCholeskyGen(NormalGen gen1, double[] mu, DoubleMatrix2D sigma)
Constructs a multinormal generator with mean vector mu and covariance matrix sigma.
DoubleMatrix2D getCholeskyDecompSigma()
Returns the lower-triangular matrix in the Cholesky decomposition of .
void nextPoint(double[] p)
Generates a point from this multinormal distribution.
static void nextPoint(NormalGen gen1, double[] mu, DoubleMatrix2D sigma, double[] p)
Generates a -dimensional vector from the multinormal distribution with mean vector mu and covariance ...
static void nextPoint(NormalGen gen1, double[] mu, double[][] sigma, double[] p)
Equivalent to nextPoint(gen1, mu, new DenseDoubleMatrix2D(sigma), p).
MultinormalCholeskyGen(NormalGen gen1, double[] mu, double[][] sigma)
Equivalent to MultinormalCholeskyGen(gen1, mu, new DenseDoubleMatrix2D(sigma)).
MultinormalGen(NormalGen gen1, int d)
Constructs a generator with the standard multinormal distribution (with and.