Search in sources :

Example 1 with MultivariateGaussianMixture

use of smile.stat.distribution.MultivariateGaussianMixture in project smile by haifengl.

the class MultivariateGaussianMixtureDemo method main.

public static void main(String[] args) {
    double[] mu1 = { 1.0, 1.0, 1.0 };
    double[][] sigma1 = { { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 } };
    double[] mu2 = { -2.0, -2.0, -2.0 };
    double[][] sigma2 = { { 1.0, 0.3, 0.8 }, { 0.3, 1.0, 0.5 }, { 0.8, 0.5, 1.0 } };
    double[] mu3 = { 4.0, 2.0, 3.0 };
    double[][] sigma3 = { { 1.0, 0.8, 0.3 }, { 0.8, 1.0, 0.5 }, { 0.3, 0.5, 1.0 } };
    double[] mu4 = { 3.0, 5.0, 1.0 };
    double[][] sigma4 = { { 1.0, 0.5, 0.5 }, { 0.5, 1.0, 0.5 }, { 0.5, 0.5, 1.0 } };
    double[][] data = new double[3000][];
    MultivariateGaussianDistribution g1 = new MultivariateGaussianDistribution(mu1, sigma1);
    double[][] data1 = new double[500][];
    for (int i = 0; i < data1.length; i++) {
        data[i] = g1.rand();
        data1[i] = data[i];
    }
    MultivariateGaussianDistribution g2 = new MultivariateGaussianDistribution(mu2, sigma2);
    double[][] data2 = new double[1000][];
    for (int i = 0; i < data2.length; i++) {
        data[500 + i] = g2.rand();
        data2[i] = data[500 + i];
    }
    MultivariateGaussianDistribution g3 = new MultivariateGaussianDistribution(mu3, sigma3);
    double[][] data3 = new double[1000][];
    for (int i = 0; i < data3.length; i++) {
        data[1500 + i] = g3.rand();
        data3[i] = data[1500 + i];
    }
    MultivariateGaussianDistribution g4 = new MultivariateGaussianDistribution(mu4, sigma4);
    double[][] data4 = new double[500][];
    for (int i = 0; i < data4.length; i++) {
        data[2500 + i] = g4.rand();
        data4[i] = data[2500 + i];
    }
    System.out.println(new MultivariateGaussianDistribution(data1));
    System.out.println(new MultivariateGaussianDistribution(data2));
    System.out.println(new MultivariateGaussianDistribution(data3));
    System.out.println(new MultivariateGaussianDistribution(data4));
    MultivariateGaussianMixture mixture = new MultivariateGaussianMixture(data, 4);
    System.out.println(mixture);
    mixture = new MultivariateGaussianMixture(data, 6);
    System.out.println(mixture);
    mixture = new MultivariateGaussianMixture(data);
    System.out.println(mixture);
    double[] mu100 = new double[20];
    double[] sigma100 = new double[20];
    for (int i = 0; i < sigma100.length; i++) sigma100[i] = 1;
    MultivariateGaussianDistribution g100 = new MultivariateGaussianDistribution(mu100, sigma100);
    double[] data100 = new double[500000];
    for (int i = 0; i < data100.length; i++) {
        double[] x = g100.rand();
        data100[i] = Math.norm(x);
    }
    System.out.println(Math.mean(data100));
    System.out.println(Math.sd(data100));
    JFrame frame = new JFrame("Norm of Samples of Gaussian Mixture of Dimension 100");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(Histogram.plot(data100, 100));
    frame.setVisible(true);
}
Also used : MultivariateGaussianDistribution(smile.stat.distribution.MultivariateGaussianDistribution) JFrame(javax.swing.JFrame) MultivariateGaussianMixture(smile.stat.distribution.MultivariateGaussianMixture)

Aggregations

JFrame (javax.swing.JFrame)1 MultivariateGaussianDistribution (smile.stat.distribution.MultivariateGaussianDistribution)1 MultivariateGaussianMixture (smile.stat.distribution.MultivariateGaussianMixture)1