use of smile.stat.distribution.BetaDistribution in project smile by haifengl.
the class BetaDistributionDemo method stateChanged.
@Override
public void stateChanged(ChangeEvent e) {
if (e.getSource() == alphaSlider || e.getSource() == betaSlider) {
alpha = alphaSlider.getValue() / 10.0;
beta = betaSlider.getValue() / 10.0;
if (alpha == 0)
alpha = 0.01;
if (beta == 0)
beta = 0.01;
BetaDistribution dist = new BetaDistribution(alpha, beta);
double[][] p = new double[99][2];
double[][] q = new double[99][2];
for (int i = 0; i < p.length; i++) {
p[i][0] = (i + 1) / 100.0;
p[i][1] = dist.p(p[i][0]);
q[i][0] = (i + 1) / 100.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();
}
}
Aggregations