List of usage examples for org.apache.commons.math.stat.descriptive DescriptiveStatistics getSortedValues
public double[] getSortedValues()
From source file:de.bfs.radon.omsimulation.gui.data.OMCharts.java
/** * Creates a chart displaying the distribution of certain selected statistical * values. Uses red for normal rooms and blue for cellar rooms. * //w w w . j ava 2 s. co m * @param title * The headline of the chart. Will be hidden if set to null. * @param statistics * The selected statistics of a campaign containing all needed * values. * @param roomType * The room type to determine the colour of the chart. * @param preview * Will hide annotations, labels and headlines if true. * @return A chart displaying the distribution of certain selected statistical * values. */ public static JFreeChart createDistributionChart(String title, DescriptiveStatistics statistics, OMRoomType roomType, boolean preview) { Color lineColor = new Color(0, 0, 0, 128); Color rangeColor = new Color(222, 222, 222, 128); if (roomType == OMRoomType.Room) { lineColor = new Color(255, 0, 0, 128); rangeColor = new Color(255, 222, 222, 128); } else { if (roomType == OMRoomType.Cellar) { lineColor = new Color(0, 0, 255, 128); rangeColor = new Color(222, 222, 255, 128); } else { lineColor = new Color(0, 128, 0, 255); rangeColor = new Color(222, 255, 222, 128); } } double[] distValues = statistics.getSortedValues(); XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries distSeries = new XYSeries("Distribution"); for (int i = 0; i < distValues.length; i++) { distSeries.add(distValues[i], (0.5 + (double) i) / (double) distValues.length); } dataSet.addSeries(distSeries); JFreeChart chart = ChartFactory.createXYLineChart(title, "Rn [Bq/m\u00B3]", "F(emp)", dataSet, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); float[] dash = { 5, 3 }; int pos = 0; double y = (Double) distSeries.getY(pos); XYPointerAnnotation minPointer = new XYPointerAnnotation("MIN=" + (int) distValues[pos], distValues[pos], y, Math.PI * 1.5); plot.addAnnotation(minPointer); pos = (int) (((double) distValues.length / 100. * 5.0) - 1.0); while (pos < 0) { pos++; } if (pos > 0) { y = (Double) distSeries.getY(pos); } else { y = (Double) distSeries.getY(pos + 1); } final double posQ5 = distValues[pos]; XYPointerAnnotation q05Pointer = new XYPointerAnnotation("Q5=" + (int) distValues[pos], distValues[pos], y, Math.PI * 1.5); plot.addAnnotation(q05Pointer); pos = (int) (((double) distValues.length / 2.0) - 1.0); y = (Double) distSeries.getY(pos); XYPointerAnnotation q50Pointer = new XYPointerAnnotation("Q50=" + (int) distValues[pos], distValues[pos], y, Math.PI * 1.5); plot.addAnnotation(q50Pointer); ValueMarker medMarker = new ValueMarker(distValues[pos], lineColor, new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addDomainMarker(medMarker); pos = (int) (((double) distValues.length / 100.0 * 95.0) - 1.0); if (pos < distValues.length - 1) { y = (Double) distSeries.getY(pos); } else { y = (Double) distSeries.getY(pos - 1); } final double posQ95 = distValues[pos]; XYPointerAnnotation q95Pointer = new XYPointerAnnotation("Q95=" + (int) distValues[pos], distValues[pos], y, Math.PI * 0.5); plot.addAnnotation(q95Pointer); pos = distValues.length - 1; y = (Double) distSeries.getY(pos); XYPointerAnnotation maxPointer = new XYPointerAnnotation("MAX=" + (int) distValues[pos], distValues[pos], y, Math.PI * 0.5); plot.addAnnotation(maxPointer); IntervalMarker percentiles = new IntervalMarker(posQ5, posQ95); percentiles.setPaint(rangeColor); percentiles.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addDomainMarker(percentiles, Layer.BACKGROUND); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, lineColor); return chart; }
From source file:guineu.modules.dataanalysis.Media.mediaFilterTask.java
public double[] getSTDDev(Dataset dataset) { DescriptiveStatistics stats = new DescriptiveStatistics(); double[] median = new double[dataset.getNumberRows()]; int numRows = 0; for (PeakListRow peak : dataset.getRows()) { stats.clear();/* w w w .j a va 2s . c om*/ for (String nameExperiment : dataset.getAllColumnNames()) { try { stats.addValue((Double) peak.getPeak(nameExperiment)); } catch (Exception e) { } } double[] values = stats.getSortedValues(); median[numRows++] = values[values.length / 2]; } return median; }
From source file:org.matsim.contrib.socnetgen.sna.graph.analysis.AnalyzerTask.java
protected void writeRawData(DescriptiveStatistics stats, String name) { try {/* ww w. j a v a 2s.c om*/ BufferedWriter writer = new BufferedWriter( new FileWriter(String.format("%1$s/%2$s.raw.txt", getOutputDirectory(), name))); for (double val : stats.getSortedValues()) { writer.write(String.valueOf(val)); writer.newLine(); } writer.close(); } catch (IOException e) { e.printStackTrace(); } }