double v1 = entropy.get(trueValue, 1);
entropy.set(trueValue, 1, (Math.log(limited) - v1) / samples + v1);
}
// add to buffers
DoubleArrayList buf = scores[trueValue];
if (buf.size() >= maxBufferSize) {
// but if too many points are seen, we insert into a random
// place and discard the predecessor. The random place could
// be anywhere, possibly not even in the buffer.
// this is a special case of Knuth's permutation algorithm
// but since we don't ever shuffle the first maxBufferSize
// samples, the result isn't just a fair sample of the prefixes
// of all permutations. The CONTENTs of the result, however,
// will be a fair and uniform sample of maxBufferSize elements
// chosen from all elements without replacement
int index = rand.nextInt(samples);
if (index < buf.size()) {
buf.set(index, score);
}
} else {
// for small buffers, we collect all points without permuting
// since we sort the data later, permuting now would just be
// pedantic
buf.add(score);
}
}