25package umontreal.ssj.randvarmulti;
27import umontreal.ssj.probdist.NormalDist;
28import umontreal.ssj.randvar.NormalGen;
29import umontreal.ssj.rng.RandomStream;
30import cern.colt.matrix.DoubleMatrix2D;
31import cern.colt.matrix.linalg.CholeskyDecomposition;
32import cern.colt.matrix.impl.DenseDoubleMatrix2D;
71 protected double[] mu;
72 protected DoubleMatrix2D sigma;
73 protected DoubleMatrix2D sqrtSigma;
74 protected double[] temp;
75 protected static final double MYINF = 37.54;
77 private void initMN(
NormalGen gen1,
double[] mu,
int d) {
79 throw new NullPointerException(
"gen1 is null");
81 if (gen1.getMu() != 0.0)
82 throw new IllegalArgumentException(
"mu != 0");
83 if (gen1.getSigma() != 1.0)
84 throw new IllegalArgumentException(
"sigma != 1");
95 this.mu =
new double[d];
97 dimension = mu.length;
98 this.mu = (
double[]) mu.clone();
100 temp =
new double[dimension];
121 initMN(gen1,
null, d);
122 sigma =
new DenseDoubleMatrix2D(d, d);
123 sqrtSigma =
new DenseDoubleMatrix2D(d, d);
124 for (
int i = 0; i < d; i++) {
125 sigma.setQuick(i, i, 1.0);
126 sqrtSigma.setQuick(i, i, 1.0);
147 initMN(gen1, mu, -1);
148 this.sigma = sigma.copy();
156 initMN(gen1, mu, -1);
157 this.sigma =
new DenseDoubleMatrix2D(sigma);
191 if (mu.length !=
this.mu.length)
192 throw new IllegalArgumentException(
"Incompatible length of mean vector");
204 public void setMu(
int i,
double mui) {
225 for (
int i = 0; i < n; i++) {
226 temp[i] = gen1.nextDouble();
227 if (temp[i] == Double.NEGATIVE_INFINITY)
229 if (temp[i] == Double.POSITIVE_INFINITY)
232 for (
int i = 0; i < n; i++) {
234 for (
int c = 0; c < n; c++)
235 p[i] += sqrtSigma.getQuick(i, c) * temp[c];
This class implements methods for generating random variates from the normal distribution .
MultinormalGen(NormalGen gen1, double[] mu, DoubleMatrix2D sigma)
Constructs a multinormal generator with mean vector mu and covariance matrix sigma.
void nextPoint(double[] p)
Generates a point from this multinormal distribution.
MultinormalGen(NormalGen gen1, int d)
Constructs a generator with the standard multinormal distribution (with and.
MultinormalGen(NormalGen gen1, double[] mu, double[][] sigma)
Equivalent to MultinormalGen(gen1, mu, new DenseDoubleMatrix2D (sigma)).
double getMu(int i)
Returns the -th component of the mean vector for this generator.
void setMu(int i, double mui)
Sets the -th component of the mean vector to mui.
DoubleMatrix2D getSigma()
Returns the covariance matrix used by this generator.
void setMu(double[] mu)
Sets the mean vector to mu.
double[] getMu()
Returns the mean vector used by this generator.
This class is the multivariate counterpart of.