@Test public void testMultivariateGaussianDistribution() { System.out.println("MultivariateGaussianDistribution"); MathEx.setSeed(19650218); 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, new Matrix(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); } } } }
public MultivariateGaussianDistribution(double[] mean, double variance) { if (variance <= 0) { throw new IllegalArgumentException("Variance is not positive: " + variance); } mu = new double[mean.length]; sigma = new Matrix(mu.length, mu.length); for (int i = 0; i < mu.length; i++) { mu[i] = mean[i]; sigma.set(i, i, variance); } diagonal = true; length = mu.length + 1; init(); }
MultivariateGaussianDistribution implements MultivariateDistribution, MultivariateExponentialFamily { public MultivariateGaussianDistribution(double[] mean, double variance) { if (variance <= 0) { throw new IllegalArgumentException("Variance is not positive: " + variance); } mu = new double[mean.length]; sigma = new Matrix(mu.length, mu.length); for (int i = 0; i < mu.length; i++) { mu[i] = mean[i]; sigma.set(i, i, variance); } diagonal = true; length = mu.length + 1; init(); } }
MultivariateGaussianDistribution implements MultivariateDistribution, MultivariateExponentialFamily { public MultivariateGaussianDistribution(double[] mean, double variance) { if (variance <= 0) { throw new IllegalArgumentException("Variance is not positive: " + variance); } mu = new double[mean.length]; sigma = new Matrix(mu.length, mu.length); for (int i = 0; i < mu.length; i++) { mu[i] = mean[i]; sigma.set(i, i, variance); } diagonal = true; length = mu.length + 1; init(); } MultivariateGaussianDistribution(double[] mean, double variance);  MultivariateGaussianDistribution(double[] mean, double[] variance);  MultivariateGaussianDistribution(double[] mean, Matrix cov); }
MultivariateGaussianDistribution implements MultivariateDistribution, MultivariateExponentialFamily { public MultivariateGaussianDistribution(double[] mean, double variance) { if (variance <= 0) { throw new IllegalArgumentException("Variance is not positive: " + variance); } mu = new double[mean.length]; sigma = new Matrix(mu.length, mu.length); for (int i = 0; i < mu.length; i++) { mu[i] = mean[i]; sigma.set(i, i, variance); } diagonal = true; length = mu.length + 1; init(); } MultivariateGaussianDistribution(double[] mean, double variance);  MultivariateGaussianDistribution(double[] mean, double[] variance);  MultivariateGaussianDistribution(double[] mean, Matrix cov); static MultivariateGaussianDistribution fit(double[][] data); static MultivariateGaussianDistribution fit(double[][] data, boolean diagonal); @Override int length(); @Override double entropy(); @Override double[] mean(); @Override Matrix cov(); double scatter(); @Override double logp(double[] x); @Override double p(double[] x); @Override double cdf(double[] x); double[] rand(); double[][] rand(int n); @Override MultivariateMixture.Component M(double[][] data, double[] posteriori); @Override String toString(); }
MultivariateGaussianDistribution implements MultivariateDistribution, MultivariateExponentialFamily { public MultivariateGaussianDistribution(double[] mean, double variance) { if (variance <= 0) { throw new IllegalArgumentException("Variance is not positive: " + variance); } mu = new double[mean.length]; sigma = new Matrix(mu.length, mu.length); for (int i = 0; i < mu.length; i++) { mu[i] = mean[i]; sigma.set(i, i, variance); } diagonal = true; length = mu.length + 1; init(); } MultivariateGaussianDistribution(double[] mean, double variance);  MultivariateGaussianDistribution(double[] mean, double[] variance);  MultivariateGaussianDistribution(double[] mean, Matrix cov); static MultivariateGaussianDistribution fit(double[][] data); static MultivariateGaussianDistribution fit(double[][] data, boolean diagonal); @Override int length(); @Override double entropy(); @Override double[] mean(); @Override Matrix cov(); double scatter(); @Override double logp(double[] x); @Override double p(double[] x); @Override double cdf(double[] x); double[] rand(); double[][] rand(int n); @Override MultivariateMixture.Component M(double[][] data, double[] posteriori); @Override String toString(); final double[] mu; final Matrix sigma; final boolean diagonal; }