DoubleQuantileFinder exactFinder = QuantileFinderFactory.newDoubleQuantileFinder(false, -1, 0.0, delta, quantiles, null);
System.out.println(exactFinder);
DoubleArrayList list = new DoubleArrayList(size);
for (int chunk=0; chunk<chunks; chunk++) {
list.setSize(0);
int d = chunk*size;
timer2.start();
for (int i=0; i<size; i++) {
list.add((double)(i + d));
}
timer2.stop();
//System.out.println("unshuffled="+list);
if (doShuffle) {
Timer timer3 = new Timer().start();
list.shuffle();
System.out.println("shuffling took ");
timer3.stop().display();
}
//System.out.println("shuffled="+list);
//list.sort();
//System.out.println("sorted="+list);
timer.start();
approxFinder.addAllOf(list);
timer.stop();
if (computeExactQuantilesAlso) {
exactFinder.addAllOf(list);
}
}
System.out.println("list.add() took" + timer2);
System.out.println("approxFinder.add() took" + timer);
//System.out.println("free="+Runtime.getRuntime().freeMemory());
//System.out.println("total="+Runtime.getRuntime().totalMemory());
timer.reset().start();
//approxFinder.close();
DoubleArrayList approxQuantiles = approxFinder.quantileElements(new DoubleArrayList(phis));
timer.stop().display();
System.out.println("Phis="+new DoubleArrayList(phis));
System.out.println("ApproxQuantiles="+approxQuantiles);
//System.out.println("MaxLevel of full buffers="+maxLevelOfFullBuffers(approxFinder.bufferSet));
//System.out.println("total buffers filled="+ approxFinder.totalBuffersFilled);
//System.out.println("free="+Runtime.getRuntime().freeMemory());
//System.out.println("total="+Runtime.getRuntime().totalMemory());
if (computeExactQuantilesAlso) {
System.out.println("Comparing with exact quantile computation...");
timer.reset().start();
//exactFinder.close();
DoubleArrayList exactQuantiles = exactFinder.quantileElements(new DoubleArrayList(phis));
timer.stop().display();
System.out.println("ExactQuantiles="+exactQuantiles);
//double[] errors1 = errors1(exactQuantiles.elements(), approxQuantiles.elements());
//System.out.println("Error1="+new DoubleArrayList(errors1));
/*
final DoubleArrayList buffer = new DoubleArrayList((int)exactFinder.size());
exactFinder.forEach(
new cern.colt.function.DoubleFunction() {
public void apply(double element) {
buffer.add(element);
}
}
);
*/
DoubleArrayList observedEpsilons = observedEpsilonsAtPhis(new DoubleArrayList(phis), (ExactDoubleQuantileFinder) exactFinder, approxFinder, epsilon);
System.out.println("observedEpsilons="+observedEpsilons);
double element = 1000.0f;
System.out.println("exact phi("+element+")="+exactFinder.phi(element));
System.out.println("apprx phi("+element+")="+approxFinder.phi(element));
System.out.println("exact elem(phi("+element+"))="+exactFinder.quantileElements(new DoubleArrayList(new double[] {exactFinder.phi(element)})));
System.out.println("apprx elem(phi("+element+"))="+approxFinder.quantileElements(new DoubleArrayList(new double[] {approxFinder.phi(element)})));
}
}