Random gen = new Random();
out.printf("n\tq0\tq1\tq2\tq3\tq4\n");
// for each horizon time span of interest
for (int n : sizes) {
System.out.printf("%d\n", n);
OnlineSummarizer summary = new OnlineSummarizer();
// replicate the test many times
for (int j = 0; j < replications; j++) {
// pick probabilities at random
double[] p = new double[bandits];
for (int k = 0; k < bandits; k++) {
p[k] = gen.nextDouble();
}
// order them to make error interpretation easier
Arrays.sort(p);
BetaBayesModel s = new BetaBayesModel(bandits, RandomUtils.getRandom());
int wins = 0;
for (int i = 0; i < n; i++) {
int k = s.sample();
final double u = gen.nextDouble();
boolean r = u <= p[k];
wins += r ? 1 : 0;
s.train(k, r ? 1 : 0);
}
summary.add((double) wins / n - p[bandits - 1]);
}
out.printf("%d\t", n);
for (int quartile = 0; quartile <= 4; quartile++) {
out.printf("%.3f%s", summary.getQuartile(quartile), quartile < 4 ? "\t" : "\n");
}
out.flush();
finalMedianRegret = summary.getMedian();
// System.out.printf("%.3f\n", summary.getMean());
}
return finalMedianRegret;
}