public MultivariateGaussianDistribution(double[] mean, double variance) {
        if (variance <= 0) {
            throw new IllegalArgumentException("Variance is not positive: " + variance);
        }

        mu = mean;
        sigma = Matrix.diag(mu.length, variance);

        diagonal = true;
        length = mu.length + 1;

        init();
    }
@Test
    public void testMultivariateGaussianDistribution() {
        System.out.println("MultivariateGaussianDistribution");
        MathEx.setSeed(19650218); // to get repeatable results.
        MultivariateGaussianDistribution instance = new MultivariateGaussianDistribution(mu, sigma[0]);
        double[][] data = instance.rand(2000);
        MultivariateGaussianDistribution est = MultivariateGaussianDistribution.fit(data, true);
        assertArrayEquals(mu, est.mean(), 5E-2);
        for (int i = 0; i < mu.length; i++) {
            assertEquals(sigma[0][i], est.sigma.get(i, i), 5E-2);
            for (int j = 0; j < mu.length; j++) {
                if (i != j) {
                    assertEquals(0, est.sigma.get(i, j), 1E-10);
                }
            }
        }

        instance = new MultivariateGaussianDistribution(mu, Matrix.of(sigma));
        data = instance.rand(2000);
        est = MultivariateGaussianDistribution.fit(data);
        assertArrayEquals(mu, est.mean(), 5E-2);

        for (int i = 0; i < mu.length; i++) {
            for (int j = 0; j < mu.length; j++) {
                assertEquals(sigma[i][j], est.sigma.get(i, j), 5E-2);
            }
        }

        est = MultivariateGaussianDistribution.fit(data, true);
        assertArrayEquals(mu, est.mean(), 5E-2);
        for (int i = 0; i < mu.length; i++) {
            for (int j = 0; j < mu.length; j++) {
                if (i == j) {
                    assertEquals(sigma[i][j], est.sigma.get(i, j), 5E-2);
                } else {
                    assertEquals(0.0, est.sigma.get(i, j), 1E-10);
                }
            }
        }
    }