use of smile.stat.distribution.Mixture in project smile by haifengl.
the class ExponentialFamilyMixtureDemo method main.
public static void main(String[] args) {
// Mixture of Gaussian, Exponential, and Gamma.
double[] data = new double[2000];
GaussianDistribution gaussian = new GaussianDistribution(-2.0, 1.0);
for (int i = 0; i < 500; i++) data[i] = gaussian.rand();
ExponentialDistribution exp = new ExponentialDistribution(0.8);
for (int i = 500; i < 1000; i++) data[i] = exp.rand();
GammaDistribution gamma = new GammaDistribution(2.0, 3.0);
for (int i = 1000; i < 2000; i++) data[i] = gamma.rand();
List<Mixture.Component> m = new ArrayList<>();
Mixture.Component c = new Mixture.Component();
c.priori = 0.25;
c.distribution = new GaussianDistribution(0.0, 1.0);
m.add(c);
c = new Mixture.Component();
c.priori = 0.25;
c.distribution = new ExponentialDistribution(1.0);
m.add(c);
c = new Mixture.Component();
c.priori = 0.25;
c.distribution = new GammaDistribution(1.0, 2.0);
m.add(c);
ExponentialFamilyMixture mixture = new ExponentialFamilyMixture(m, data);
System.out.println(mixture);
JFrame frame = new JFrame("Mixture of Exponential Family Distributions");
PlotCanvas canvas = Histogram.plot(data, 50);
frame.add(canvas);
double width = (Math.max(data) - Math.min(data)) / 50;
double[][] p = new double[400][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = -10 + i * 0.1;
p[i][1] = mixture.p(p[i][0]) * width;
}
canvas.line(p, Color.RED);
frame.add(QQPlot.plot(data, mixture));
frame.setVisible(true);
}
Aggregations