List of usage examples for org.apache.commons.math3.stat.descriptive.rank Percentile evaluate
public double evaluate(final double[] values, final double p) throws MathIllegalArgumentException
p
th percentile of the values in the values
array. From source file:com.itemanalysis.psychometrics.histogram.Histogram.java
private void createHistogram(double[] x) { n = x.length;/*from ww w. jav a 2s .c o m*/ Min min = new Min(); Max max = new Max(); Mean mean = new Mean(); StandardDeviation sd = new StandardDeviation(); for (int i = 0; i < x.length; i++) { min.increment(x[i]); max.increment(x[i]); mean.increment(x[i]); sd.increment(x[i]); } double range = max.getResult() - min.getResult(); double lowestBoundary = min.getResult() - range / 1000; double largestBoundary = max.getResult() + range / 1000; if (binCalculationType == BinCalculationType.SCOTT) { binCalc = new ScottBinCalculation(n, min.getResult(), max.getResult(), sd.getResult()); } else if (binCalculationType == BinCalculationType.FREEDMAN_DIACONIS) { Percentile percentile = new Percentile(); double q1 = percentile.evaluate(x, 25); double q3 = percentile.evaluate(x, 75); binCalc = new FreedmanDiaconisBinCalculation(n, min.getResult(), max.getResult(), q1, q3); } else if (binCalculationType == BinCalculationType.STURGES) { binCalc = new SturgesBinCalculation(n, min.getResult(), max.getResult()); } numberOfBins = binCalc.numberOfBins(); binWidth = binCalc.binWidth(); //create bins createBins(lowestBoundary, largestBoundary); //count observations in each bin for (int i = 0; i < n; i++) { for (Bin b : bins) { b.increment(x[i]); } } }
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 www.j a v a 2 s . c o 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:edu.cuny.qc.speech.AuToBI.PitchExtractor.java
/** * Calls getPitch with no paramters, automatically setting the min and max values for more precise estimation. * <p/>/*from w ww . j a v a 2s .c om*/ * This is based on the DeLooze and Rauzy (Automatic Detection and Prediction of Topic Changes * Through Automatic Detection of Register variations and Pause Duration. De Looze and Rauzy. 2009) * It's usefulness was described by The importance of optimal parameter setting for pitch extraction. 2010. Acoustical * Society of America. Evanini, Lai and Zechner. */ public Contour soundToPitchTwoPass() throws AuToBIException { // initial min and max values. Contour c = soundToPitch(0.01, 50, 400); // identify relevant percentile values Percentile p = new Percentile(); double[] values = new double[c.contentSize()]; int i = 0; for (Pair<Double, Double> tvp : c) { values[i++] = tvp.second; } double q35 = p.evaluate(values, 35.); double q65 = p.evaluate(values, 65.); // run getPitch again return soundToPitch(0.01, q35 * 0.72 - 10, q65 * 1.9 + 10); }
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))); }/* w w w . j ava2 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.opencloudengine.flamingo.mapreduce.util.MathUtils.java
/** * Percentile? ./*from w w w . ja v a 2 s .c om*/ * * @param values ? * @param quantile ? Quantile * @return Percentile */ public static double percentile(double[] values, double quantile) { Percentile percentile = new Percentile(); return percentile.evaluate(values, quantile); }
From source file:org.openjdk.jmh.util.ListStatistics.java
@Override public double getPercentile(double rank) { if (count == 0) { return Double.NaN; }// ww w.j a v a2 s . c o m if (rank == 0) { return getMin(); } // trim values = Arrays.copyOf(values, count); Percentile p = new Percentile(); return p.evaluate(values, rank); }
From source file:org.opennms.netmgt.measurements.filters.impl.OutlierFilter.java
@Override public void filter(RowSortedTable<Long, String, Double> qrAsTable) { // Extract the values of the input column as a primitive array final Map<Long, Double> column = qrAsTable.column(m_inputColumn); final double values[] = new double[column.size()]; int k = 0;//from w w w . ja v a2s .c o m for (Double value : column.values()) { values[k++] = value; } // Calculate the percentile org.apache.commons.math3.stat.descriptive.rank.Percentile percentileCalculator = new org.apache.commons.math3.stat.descriptive.rank.Percentile(); Double nthPercentile = percentileCalculator.evaluate(values, 100 * m_quantile); // Replace values greater than the percentile with NaNs for (Entry<Long, Double> entry : column.entrySet()) { if (!entry.getValue().isNaN() && entry.getValue() > nthPercentile) { entry.setValue(Double.NaN); } } // Perform linear interpolation on missing values linearInterpolation(qrAsTable); }