List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getPercentile
public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException
From source file:es.upm.oeg.tools.rdfshapes.libdemo.CommonsMathDemo.java
public static void main(String[] args) { DescriptiveStatistics stats = new DescriptiveStatistics(); int inputArray[] = { 3, 4, 5, 6, 2, 3, 4, 3, 3, 4, 3, 6, 3, 2, 3, 1, 2, 1, 1, 1, 3 }; // Add the data from the array for (int i = 0; i < inputArray.length; i++) { stats.addValue(inputArray[i]);// w w w . ja va 2s . c o m } double mean = stats.getMean(); double std = stats.getStandardDeviation(); double median = stats.getPercentile(50); System.out.println("mean" + stats.getMean()); System.out.println("standard deviation" + stats.getStandardDeviation()); System.out.println("skewness" + stats.getSkewness()); }
From source file:com.sop4j.SimpleStatistics.java
public static void main(String[] args) { final MersenneTwister rng = new MersenneTwister(); // used for RNG... READ THE DOCS!!! final int[] values = new int[NUM_VALUES]; final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values final Frequency frequency = new Frequency(); // add numbers into our stats for (int i = 0; i < NUM_VALUES; ++i) { values[i] = rng.nextInt(MAX_VALUE); descriptiveStats.addValue(values[i]); summaryStats.addValue(values[i]); frequency.addValue(values[i]);// ww w. j a v a2 s . c o m } // print out some standard stats System.out.println("MIN: " + summaryStats.getMin()); System.out.println("AVG: " + String.format("%.3f", summaryStats.getMean())); System.out.println("MAX: " + summaryStats.getMax()); // get some more complex stats only offered by DescriptiveStatistics System.out.println("90%: " + descriptiveStats.getPercentile(90)); System.out.println("MEDIAN: " + descriptiveStats.getPercentile(50)); System.out.println("SKEWNESS: " + String.format("%.4f", descriptiveStats.getSkewness())); System.out.println("KURTOSIS: " + String.format("%.4f", descriptiveStats.getKurtosis())); // quick and dirty stats (need a little help from Guava to convert from int[] to double[]) System.out.println("MIN: " + StatUtils.min(Doubles.toArray(Ints.asList(values)))); System.out.println("AVG: " + String.format("%.4f", StatUtils.mean(Doubles.toArray(Ints.asList(values))))); System.out.println("MAX: " + StatUtils.max(Doubles.toArray(Ints.asList(values)))); // some stats based upon frequencies System.out.println("NUM OF 7s: " + frequency.getCount(7)); System.out.println("CUMULATIVE FREQUENCY OF 7: " + frequency.getCumFreq(7)); System.out.println("PERCENTAGE OF 7s: " + frequency.getPct(7)); }
From source file:fr.inria.eventcloud.benchmarks.QuadrupleStatsEvaluator.java
public static void main(String[] args) throws FileNotFoundException { final DescriptiveStatistics g = new DescriptiveStatistics(); final DescriptiveStatistics s = new DescriptiveStatistics(); final DescriptiveStatistics p = new DescriptiveStatistics(); final DescriptiveStatistics o = new DescriptiveStatistics(); RDFDataMgr.parse(new StreamRDF() { @Override//from ww w . ja va 2 s . com public void triple(Triple triple) { } @Override public void start() { } @Override public void quad(Quad quad) { g.addValue(SemanticCoordinate.applyDopingFunction(quad.getGraph()) // quad.getGraph().toString() .length()); s.addValue(SemanticCoordinate.applyDopingFunction(quad.getSubject()) // quad.getSubject().toString() .length()); p.addValue(SemanticCoordinate.applyDopingFunction(quad.getPredicate()) // quad.getPredicate().toString() .length()); o.addValue(SemanticCoordinate.applyDopingFunction(quad.getObject()) // quad.getObject().toString() .length()); } @Override public void prefix(String prefix, String iri) { } @Override public void finish() { } @Override public void base(String base) { } }, new FileInputStream(args[0]), Lang.TRIG); double percentage = 0.99; System.out.println("g --> " + g.getPercentile(percentage)); System.out.println("s --> " + s.getPercentile(percentage)); System.out.println("p --> " + p.getPercentile(percentage)); System.out.println("o --> " + o.getPercentile(percentage)); }
From source file:com.weibo.motan.demo.client.DemoRpcClient.java
public static void main(String[] args) throws Exception { final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); int threads = Integer.parseInt(args[0]); DubboBenchmark.BenchmarkMessage msg = prepareArgs(); final byte[] msgBytes = msg.toByteArray(); int n = 1000000; final CountDownLatch latch = new CountDownLatch(n); ExecutorService es = Executors.newFixedThreadPool(threads); final AtomicInteger trans = new AtomicInteger(0); final AtomicInteger transOK = new AtomicInteger(0); ApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "classpath:motan_demo_client.xml" }); MotanDemoService service = (MotanDemoService) ctx.getBean("motanDemoReferer"); long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { es.submit(() -> {/*from w w w . j a v a2 s. c o m*/ try { long t = System.currentTimeMillis(); DubboBenchmark.BenchmarkMessage m = testSay(service, msgBytes); t = System.currentTimeMillis() - t; stats.addValue(t); trans.incrementAndGet(); if (m != null && m.getField1().equals("OK")) { transOK.incrementAndGet(); } } finally { latch.countDown(); } }); } latch.await(); start = System.currentTimeMillis() - start; System.out.printf("sent requests : %d\n", n); System.out.printf("received requests : %d\n", trans.get()); System.out.printf("received requests_OK : %d\n", transOK.get()); System.out.printf("throughput (TPS) : %d\n", n * 1000 / start); System.out.printf("mean: %f\n", stats.getMean()); System.out.printf("median: %f\n", stats.getPercentile(50)); System.out.printf("max: %f\n", stats.getMax()); System.out.printf("min: %f\n", stats.getMin()); System.out.printf("99P: %f\n", stats.getPercentile(90)); }
From source file:es.upm.oeg.tools.rdfshapes.utils.CadinalityResultGenerator.java
public static void main(String[] args) throws Exception { String endpoint = "http://3cixty.eurecom.fr/sparql"; List<String> classList = Files.readAllLines(Paths.get(classListPath), Charset.defaultCharset()); String classPropertyQueryString = readFile(classPropertyQueryPath, Charset.defaultCharset()); String propertyCardinalityQueryString = readFile(propertyCardinalityQueryPath, Charset.defaultCharset()); String individualCountQueryString = readFile(individualCountQueryPath, Charset.defaultCharset()); DecimalFormat df = new DecimalFormat("0.0000"); //Create the Excel workbook and sheet XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("Cardinality"); int currentExcelRow = 0; int classStartRow = 0; for (String clazz : classList) { Map<String, String> litMap = new HashMap<>(); Map<String, String> iriMap = ImmutableMap.of("class", clazz); String queryString = bindQueryString(individualCountQueryString, ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap)); int individualCount; List<RDFNode> c = executeQueryForList(queryString, endpoint, "c"); if (c.size() == 1) { individualCount = c.get(0).asLiteral().getInt(); } else {//ww w . j ava 2 s . co m continue; } // If there are zero individuals, continue if (individualCount == 0) { throw new IllegalStateException("Check whether " + classListPath + " and " + endpoint + " match."); } // System.out.println("***"); // System.out.println("### **" + clazz + "** (" + individualCount + ")"); // System.out.println("***"); // System.out.println(); classStartRow = currentExcelRow; XSSFRow row = sheet.createRow(currentExcelRow); XSSFCell cell = row.createCell(0); cell.setCellValue(clazz); cell.getCellStyle().setAlignment(CellStyle.ALIGN_CENTER); queryString = bindQueryString(classPropertyQueryString, ImmutableMap.of(IRI_BINDINGS, iriMap, LITERAL_BINDINGS, litMap)); List<RDFNode> nodeList = executeQueryForList(queryString, endpoint, "p"); for (RDFNode property : nodeList) { if (property.isURIResource()) { DescriptiveStatistics stats = new DescriptiveStatistics(); String propertyURI = property.asResource().getURI(); // System.out.println("* " + propertyURI); // System.out.println(); XSSFRow propertyRow = sheet.getRow(currentExcelRow); if (propertyRow == null) { propertyRow = sheet.createRow(currentExcelRow); } currentExcelRow++; XSSFCell propertyCell = propertyRow.createCell(1); propertyCell.setCellValue(propertyURI); Map<String, String> litMap2 = new HashMap<>(); Map<String, String> iriMap2 = ImmutableMap.of("class", clazz, "p", propertyURI); queryString = bindQueryString(propertyCardinalityQueryString, ImmutableMap.of(IRI_BINDINGS, iriMap2, LITERAL_BINDINGS, litMap2)); List<Map<String, RDFNode>> solnMaps = executeQueryForList(queryString, endpoint, ImmutableSet.of("card", "count")); int sum = 0; List<CardinalityCount> cardinalityList = new ArrayList<>(); if (solnMaps.size() > 0) { for (Map<String, RDFNode> soln : solnMaps) { int count = soln.get("count").asLiteral().getInt(); int card = soln.get("card").asLiteral().getInt(); for (int i = 0; i < count; i++) { stats.addValue(card); } CardinalityCount cardinalityCount = new CardinalityCount(card, count, (((double) count) / individualCount) * 100); cardinalityList.add(cardinalityCount); sum += count; } // Check for zero cardinality instances int count = individualCount - sum; if (count > 0) { for (int i = 0; i < count; i++) { stats.addValue(0); } CardinalityCount cardinalityCount = new CardinalityCount(0, count, (((double) count) / individualCount) * 100); cardinalityList.add(cardinalityCount); } } Map<Integer, Double> cardMap = new HashMap<>(); for (CardinalityCount count : cardinalityList) { cardMap.put(count.getCardinality(), count.getPrecentage()); } XSSFCell instanceCountCell = propertyRow.createCell(2); instanceCountCell.setCellValue(individualCount); XSSFCell minCell = propertyRow.createCell(3); minCell.setCellValue(stats.getMin()); XSSFCell maxCell = propertyRow.createCell(4); maxCell.setCellValue(stats.getMax()); XSSFCell p1 = propertyRow.createCell(5); p1.setCellValue(stats.getPercentile(1)); XSSFCell p99 = propertyRow.createCell(6); p99.setCellValue(stats.getPercentile(99)); XSSFCell mean = propertyRow.createCell(7); mean.setCellValue(df.format(stats.getMean())); for (int i = 0; i < 21; i++) { XSSFCell dataCell = propertyRow.createCell(8 + i); Double percentage = cardMap.get(i); if (percentage != null) { dataCell.setCellValue(df.format(percentage)); } else { dataCell.setCellValue(0); } } // System.out.println("| Min Card. |Max Card. |"); // System.out.println("|---|---|"); // System.out.println("| ? | ? |"); // System.out.println(); } } //System.out.println("class start: " + classStartRow + ", class end: " + (currentExcelRow -1)); //We have finished writting properties of one class, now it's time to merge the cells int classEndRow = currentExcelRow - 1; if (classStartRow < classEndRow) { sheet.addMergedRegion(new CellRangeAddress(classStartRow, classEndRow, 0, 0)); } } String filename = "3cixty.xls"; FileOutputStream fileOut = new FileOutputStream(filename); wb.write(fileOut); fileOut.close(); }
From source file:edu.gsgp.utils.Utils.java
public static double getIQR(double[] array) { DescriptiveStatistics da = new DescriptiveStatistics(array); return da.getPercentile(75) - da.getPercentile(25); }
From source file:async.nio2.Main.java
private static String toEvaluationString(DescriptiveStatistics stats) { String data = String.format( "0.50 Percentile = %8.2f, " + "0.90 Percentile = %8.2f, " + "0.99 Percentile = %8.2f, " + "min = %8.2f, " + "max = %8.2f", stats.getMean(), stats.getPercentile(90), stats.getPercentile(99), stats.getMin(), stats.getMax()); stats.clear();/*from w w w.ja va 2s. c o m*/ return data; }
From source file:com.caseystella.analytics.outlier.streaming.mad.ConfusionMatrix.java
public static void printStats(String title, DescriptiveStatistics scoreStats) { System.out.println(/*from w w w . j a v a2s . c o m*/ title + ": " + "\n\tMin: " + scoreStats.getMin() + "\n\t1th: " + scoreStats.getPercentile(1) + "\n\t5th: " + scoreStats.getPercentile(5) + "\n\t10th: " + scoreStats.getPercentile(10) + "\n\t25th: " + scoreStats.getPercentile(25) + "\n\t50th: " + scoreStats.getPercentile(50) + "\n\t90th: " + scoreStats.getPercentile(90) + "\n\t95th: " + scoreStats.getPercentile(95) + "\n\t99th: " + scoreStats.getPercentile(99) + "\n\tMax: " + scoreStats.getMax()); }
From source file:com.spotify.annoy.jni.base.Benchmark.java
private static void dispStats(List<Long> queryTime) { DescriptiveStatistics s = new DescriptiveStatistics(); for (Long t : queryTime) { s.addValue(t);//from ww w. ja va2 s . c o m } System.out.print(new StringBuilder().append(String.format("Total time: %.5fs\n", s.getSum() / 1.e9)) .append(String.format("Mean time: %.5fs\n", s.getMean() / 1.e9)) .append(String.format("Median time: %.5fs\n", s.getPercentile(.5) / 1.e9)) .append(String.format("Stddev time: %.5fs\n", s.getStandardDeviation() / 1.e9)) .append(String.format("Min time: %.5fs\n", s.getMin() / 1.e9)) .append(String.format("Max time: %.5fs\n", s.getMax() / 1.e9)).toString()); }
From source file:com.intuit.tank.vm.common.util.ReportUtil.java
public static final String[] getSummaryData(String key, DescriptiveStatistics stats) { String[] ret = new String[ReportUtil.SUMMARY_HEADERS.length + PERCENTILES.length]; int i = 0;//from w ww .j av a 2s . com ret[i++] = key;// Page ID ret[i++] = INT_NF.format(stats.getN());// Sample Size ret[i++] = DOUBLE_NF.format(stats.getMean());// Mean ret[i++] = INT_NF.format(stats.getPercentile(50));// Meadian ret[i++] = INT_NF.format(stats.getMin());// Min ret[i++] = INT_NF.format(stats.getMax());// Max ret[i++] = DOUBLE_NF.format(stats.getStandardDeviation());// Std Dev ret[i++] = DOUBLE_NF.format(stats.getKurtosis());// Kurtosis ret[i++] = DOUBLE_NF.format(stats.getSkewness());// Skewness ret[i++] = DOUBLE_NF.format(stats.getVariance());// Varience for (int n = 0; n < PERCENTILES.length; n++) { ret[i++] = INT_NF.format(stats.getPercentile((Integer) PERCENTILES[n][1]));// Percentiles } return ret; }