use of smile.stat.distribution.GaussianDistribution in project smile by haifengl.
the class GaussianDistributionDemo method stateChanged.
@Override
public void stateChanged(ChangeEvent e) {
if (e.getSource() == sigmaSlider) {
sigma = sigmaSlider.getValue() / 10.0;
if (sigma == 0)
sigma = 0.01;
GaussianDistribution dist = new GaussianDistribution(0, sigma);
double[][] p = new double[200][2];
double[][] q = new double[200][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i - 100) / 10.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i - 100) / 10.0;
q[i][1] = dist.cdf(p[i][0]);
}
pdf.clear();
pdf.line(p, Line.Style.SOLID, Color.BLUE);
cdf.clear();
cdf.line(q, Line.Style.SOLID, Color.BLUE);
double[] data = new double[500];
for (int i = 0; i < data.length; i++) {
data[i] = dist.rand();
}
histogram.clear();
histogram.histogram(data, 20, Color.BLUE);
qqplot.clear();
qqplot.add(new QQPlot(data, dist));
canvas.repaint();
}
}
use of smile.stat.distribution.GaussianDistribution 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