@Test public void testMixture5() { System.out.println("Mixture5"); double[] data = new double[30000]; GaussianDistribution g1 = new GaussianDistribution(1.0, 1.0); for (int i = 0; i < 5000; i++) data[i] = g1.rand(); GaussianDistribution g2 = new GaussianDistribution(4.0, 1.0); for (int i = 5000; i < 10000; i++) data[i] = g2.rand(); GaussianDistribution g3 = new GaussianDistribution(8.0, 1.0); for (int i = 10000; i < 20000; i++) data[i] = g3.rand(); GaussianDistribution g4 = new GaussianDistribution(-2.0, 1.0); for (int i = 20000; i < 25000; i++) data[i] = g4.rand(); GaussianDistribution g5 = new GaussianDistribution(-5.0, 1.0); for (int i = 25000; i < 30000; i++) data[i] = g5.rand(); GaussianMixture mixture = GaussianMixture.fit(data); System.out.println(mixture); }
public static GaussianMixture fit(int k, double[] x) { if (k < 2) throw new IllegalArgumentException("Invalid number of components in the mixture."); double min = MathEx.min(x); double max = MathEx.max(x); double step = (max - min) / (k+1); Component[] components = new Component[k]; for (int i = 0; i < k; i++) { components[i] = new Component(1.0/k, new GaussianDistribution(min+=step, step)); } ExponentialFamilyMixture model = fit(x, components); return new GaussianMixture(model.L, x.length, model.components); }
GaussianMixture extends ExponentialFamilyMixture { public static GaussianMixture fit(int k, double[] x) { if (k < 2) throw new IllegalArgumentException("Invalid number of components in the mixture."); double min = MathEx.min(x); double max = MathEx.max(x); double step = (max - min) / (k+1); Component[] components = new Component[k]; for (int i = 0; i < k; i++) { components[i] = new Component(1.0/k, new GaussianDistribution(min+=step, step)); } ExponentialFamilyMixture model = fit(x, components); return new GaussianMixture(model.L, x.length, model.components); } }
GaussianMixture extends ExponentialFamilyMixture { public static GaussianMixture fit(int k, double[] x) { if (k < 2) throw new IllegalArgumentException("Invalid number of components in the mixture."); double min = MathEx.min(x); double max = MathEx.max(x); double step = (max - min) / (k+1); Component[] components = new Component[k]; for (int i = 0; i < k; i++) { components[i] = new Component(1.0/k, new GaussianDistribution(min+=step, step)); } ExponentialFamilyMixture model = fit(x, components); return new GaussianMixture(model.L, x.length, model.components); } GaussianMixture(Component... components); private  GaussianMixture(double L, int n, Component... components); }
GaussianMixture extends ExponentialFamilyMixture { public static GaussianMixture fit(int k, double[] x) { if (k < 2) throw new IllegalArgumentException("Invalid number of components in the mixture."); double min = MathEx.min(x); double max = MathEx.max(x); double step = (max - min) / (k+1); Component[] components = new Component[k]; for (int i = 0; i < k; i++) { components[i] = new Component(1.0/k, new GaussianDistribution(min+=step, step)); } ExponentialFamilyMixture model = fit(x, components); return new GaussianMixture(model.L, x.length, model.components); } GaussianMixture(Component... components); private  GaussianMixture(double L, int n, Component... components); static GaussianMixture fit(int k, double[] x); @SuppressWarnings("unchecked") static GaussianMixture fit(double[] x); }
GaussianMixture extends ExponentialFamilyMixture { public static GaussianMixture fit(int k, double[] x) { if (k < 2) throw new IllegalArgumentException("Invalid number of components in the mixture."); double min = MathEx.min(x); double max = MathEx.max(x); double step = (max - min) / (k+1); Component[] components = new Component[k]; for (int i = 0; i < k; i++) { components[i] = new Component(1.0/k, new GaussianDistribution(min+=step, step)); } ExponentialFamilyMixture model = fit(x, components); return new GaussianMixture(model.L, x.length, model.components); } GaussianMixture(Component... components); private  GaussianMixture(double L, int n, Component... components); static GaussianMixture fit(int k, double[] x); @SuppressWarnings("unchecked") static GaussianMixture fit(double[] x);  }