List of usage examples for org.apache.commons.math3.stat.descriptive.rank Percentile Percentile
public Percentile()
From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java
public Pair<Float, Float> getPrecisionCI() { Percentile percentile = new Percentile(); percentile.setData(/*from w w w. j av a 2 s. com*/ Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getPrecision()).toArray()); double alpha = (1 - CONF_LEVEL) / 2; return Pair.of((float) percentile.evaluate(100 * alpha), (float) percentile.evaluate(100 * (1 - alpha))); }
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
public void computeApproxChi2Values() { Percentile perc = new Percentile(); EffTestCalculator effCalc = new EffTestCalculator(); effCalc.addGeneIds(genes_);/*from w w w . j a va 2s . c o m*/ effCalc.addMetaGeneIds(metaGenes_); effCalc.setGeneSets(geneSets_); effCalc.initializeGeneVals(); int nrOfLoops = 10000; double[] mins = new double[nrOfLoops]; for (int i = 0; i < nrOfLoops; i++) { mins[i] = effCalc.calcMinVal(); } perc.setData(mins); double p1 = perc.evaluate(1); double p5 = perc.evaluate(5); double p10 = perc.evaluate(10); double p15 = perc.evaluate(15); //double w1 = perc.evaluate(1.0/50); System.out.println(p1); System.out.println(p5); System.out.println(p10); System.out.println(p15); System.out.println("asdf"); }
From source file:edu.jhuapl.bsp.detector.OpenMath.java
public static double prctile(double[] in, double p) { Percentile prc = new Percentile(); double in2[] = copya(in); Arrays.sort(in2);/*from w w w. j a v a2 s . c o m*/ prc.setData(in2); double result = prc.evaluate(p); return result; }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
private double[] boxPlotValues(CoolMapObject object, VNode rowNode, VNode columnNode) { if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return null; } else {//from w ww . j a v a 2 s . co m Integer[] rowIndices; Integer[] colIndices; if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology((CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)).getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology((CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)).getIndexOfColName(columnNode.getName()) }; } //A box plot across all matrices List<CMatrix> matrices = object.getBaseCMatrices(); Double value; ArrayList<Double> values = new ArrayList<Double>(); //add values for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } for (Integer j : colIndices) { if (j == null || j < 0) { continue; } //Double value = (Double) getCoolMapObject().getViewValue(i, j); //This is wrong. it should eb the base matrix value, not the view values for (CMatrix<Double> matrix : matrices) { value = matrix.getValue(i, j); if (value == null || value.isNaN()) { continue; } else { //System.out.println(i + " " + j + " " + v); values.add(value); } } } } if (values.isEmpty()) { return null; } Collections.sort(values); int size = values.size(); double min = values.get(0); double max = values.get(values.size() - 1); double median; if (size % 2 == 0) { median = (values.get(size / 2) + values.get(size / 2 - 1)) / 2; } else { median = (values.get(size / 2)); } double[] valueArray = new double[values.size()]; int c = 0; for (Double d : values) { valueArray[c++] = d.doubleValue(); } Arrays.sort(valueArray); Percentile percentile = new Percentile(); double q1 = percentile.evaluate(valueArray, 25); double q3 = percentile.evaluate(valueArray, 75); // double median = percentile.evaluate(valueArray, 50); return new double[] { min, q1, median, q3, max }; } }
From source file:org.apache.mahout.classifier.df.split.OptIgSplit.java
/** * @return an array of values to split the numeric feature's values on when * building candidate splits. When input size is <= MAX_NUMERIC_SPLITS + 1, it will * return the averages between success values as split points. When larger, it will * return MAX_NUMERIC_SPLITS approximate percentiles through the data. *//*w w w. j a v a 2 s.c o m*/ private static double[] chooseNumericSplitPoints(double[] values) { if (values.length <= 1) { return values; } if (values.length <= MAX_NUMERIC_SPLITS + 1) { double[] splitPoints = new double[values.length - 1]; for (int i = 1; i < values.length; i++) { splitPoints[i - 1] = (values[i] + values[i - 1]) / 2.0; } return splitPoints; } Percentile distribution = new Percentile(); distribution.setData(values); double[] percentiles = new double[MAX_NUMERIC_SPLITS]; for (int i = 0; i < percentiles.length; i++) { double p = 100.0 * ((i + 1.0) / (MAX_NUMERIC_SPLITS + 1.0)); percentiles[i] = distribution.evaluate(p); } return percentiles; }
From source file:org.apache.solr.client.solrj.io.eval.MovingMedianEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }//from ww w . j a v a 2 s. c o m if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a List", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof Number)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a Number", toExpression(constructingFactory), first.getClass().getSimpleName())); } List<?> values = (List<?>) first; int window = ((Number) second).intValue(); List<Number> moving = new ArrayList<>(); DescriptiveStatistics slider = new DescriptiveStatistics(window); Percentile percentile = new Percentile(); for (Object value : values) { slider.addValue(((Number) value).doubleValue()); if (slider.getN() >= window) { double median = percentile.evaluate(slider.getValues(), 50); moving.add(median); } } return moving; }
From source file:org.apache.solr.client.solrj.io.eval.PercentileEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }//from w w w. j av a 2 s. com if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a List", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof Number)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a Number", toExpression(constructingFactory), first.getClass().getSimpleName())); } Percentile percentile = new Percentile(); percentile .setData(((List<?>) first).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray()); return percentile.evaluate(((Number) second).doubleValue()); }
From source file:org.drugis.mtc.summary.QuantileSummary.java
private Percentile getSamples() { List<Double> list = SummaryUtil.getAllChainsLastHalfSamples(d_results, d_parameter); double[] arr = new double[list.size()]; for (int i = 0; i < list.size(); ++i) { arr[i] = list.get(i);//from w ww . j a v a2 s .co m } Percentile percentile = new Percentile(); percentile.setData(arr); return percentile; }
From source file:org.hawkular.metrics.core.impl.cassandra.GaugeBucketedOutputMapper.java
@Override protected GaugeBucketDataPoint newPointInstance(long from, long to, List<GaugeData> gaugeDatas) { double[] values = new double[gaugeDatas.size()]; for (ListIterator<GaugeData> iterator = gaugeDatas.listIterator(); iterator.hasNext();) { GaugeData gaugeData = iterator.next(); values[iterator.previousIndex()] = gaugeData.getValue(); }//from w ww . j av a 2 s .c om Percentile percentile = new Percentile(); percentile.setData(values); return new GaugeBucketDataPoint.Builder(from, to).setMin(new Min().evaluate(values)) .setAvg(new Mean().evaluate(values)).setMedian(percentile.evaluate(50.0)) .setMax(new Max().evaluate(values)).setPercentile95th(percentile.evaluate(95.0)).build(); }
From source file:org.hawkular.metrics.core.impl.cassandra.NumericBucketedOutputMapper.java
@Override protected NumericBucketDataPoint newPointInstance(long from, long to, List<NumericData> numericDatas) { double[] values = new double[numericDatas.size()]; for (ListIterator<NumericData> iterator = numericDatas.listIterator(); iterator.hasNext();) { NumericData numericData = iterator.next(); values[iterator.previousIndex()] = numericData.getValue(); }/*from w ww . ja v a2 s. co m*/ Percentile percentile = new Percentile(); percentile.setData(values); return new NumericBucketDataPoint.Builder(from, to).setMin(new Min().evaluate(values)) .setAvg(new Mean().evaluate(values)).setMedian(percentile.evaluate(50.0)) .setMax(new Max().evaluate(values)).setPercentile95th(percentile.evaluate(95.0)).build(); }