List of usage examples for com.google.common.math Quantiles scale
public static Scale scale(int scale)
From source file:org.apache.aurora.scheduler.sla.SlaUtil.java
/** * Reports the percentile value from the continuous distribution described by a given list of * samples.//from www . j a va 2 s .com * * Example: [30, 60, 70, 90], the 50 percentile is 65.0 (i.e. larger values cover 50% of the PDF * (Probability Density Function)). * Example: [30, 60, 70, 90], the 75 percentile is 52.5 (i.e. larger values cover 75% of the PDF). * Example: [30, 60, 70, 90], the 90 percentile is 39.0 (i.e. larger values cover 85% of the PDF). * Example: [30, 60, 70, 90], the 99 percentile is 30.9 (i.e. larger values cover 95% of the PDF). * * @param list List to calculate percentile for. * @param percentile Percentile value to apply. * @return Element at the given percentile. */ static Number percentile(List<Long> list, double percentile) { if (list.isEmpty()) { return 0.0; } // index should be a full integer. use quantile scale to allow reporting of percentile values // such as p99.9. double percentileCopy = percentile; int quantileScale = 100; while ((percentileCopy - Math.floor(percentileCopy)) > 0) { quantileScale *= 10; percentileCopy *= 10; } return Quantiles.scale(quantileScale).index((int) Math.floor(quantileScale - percentileCopy)).compute(list); }