Example usage for org.apache.commons.math.stat.descriptive DescriptiveStatistics getMax

List of usage examples for org.apache.commons.math.stat.descriptive DescriptiveStatistics getMax

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive DescriptiveStatistics getMax.

Prototype

public double getMax() 

Source Link

Document

Returns the maximum of the available values

Usage

From source file:org.matsim.contrib.socnetgen.sna.graph.analysis.TransitivityTest.java

@SuppressWarnings("unchecked")
public void test() {
    SparseGraphBuilder builder = new SparseGraphBuilder();
    SparseGraph graph = builder.createGraph();

    SparseVertex v1 = builder.addVertex(graph);
    SparseVertex v2 = builder.addVertex(graph);
    SparseVertex v3 = builder.addVertex(graph);
    SparseVertex v4 = builder.addVertex(graph);

    builder.addEdge(graph, v1, v2);//from  w ww  . j a  va  2 s  .  co m
    builder.addEdge(graph, v1, v4);
    builder.addEdge(graph, v1, v3);
    builder.addEdge(graph, v2, v4);

    Transitivity degree = Transitivity.getInstance();

    DescriptiveStatistics distr = degree.localClusteringDistribution(graph.getVertices());
    assertEquals(7 / 12.0, distr.getMean(), 0.01);
    assertEquals(0.0, distr.getMin());
    assertEquals(1.0, distr.getMax());

    TObjectDoubleHashMap<Vertex> values = (TObjectDoubleHashMap<Vertex>) degree
            .localClusteringCoefficients((Set<? extends Vertex>) graph.getVertices());

    assertEquals(1 / 3.0, values.get(v1));
    assertEquals(1.0, values.get(v2));
    assertEquals(1.0, values.get(v4));
    assertEquals(0.0, values.get(v3));

    assertEquals(3 / 5.0, degree.globalClusteringCoefficient(graph));
}

From source file:org.matsim.contrib.socnetgen.sna.graph.io.PajekDegreeColorizer.java

public PajekDegreeColorizer(Graph g, boolean logScale) {
    super();//  w  w  w  .ja v a 2 s  . co m
    setLogScale(logScale);
    DescriptiveStatistics stats = Degree.getInstance().statistics(g.getVertices());
    k_min = stats.getMin();
    k_max = stats.getMax();
}

From source file:org.matsim.contrib.socnetgen.sna.graph.spatial.io.VertexDegreeColorizer.java

/**
 * Creates a colorizer which color spectrum is scaled to the degree
 * distribution of <tt>graph</tt>.
 * //from w  w w  .  j  a v  a  2s. c  o  m
 * @param graph
 *            a graph
 */
public VertexDegreeColorizer(Graph graph) {
    Degree degree = Degree.getInstance();
    DescriptiveStatistics distr = degree.statistics(graph.getVertices());
    k_min = (int) distr.getMin();
    k_max = (int) distr.getMax();
}

From source file:org.openehealth.ipf.commons.test.performance.processingtime.ProcessingTimeDescriptiveStatistics.java

/**
 * Returns statistical summary of all the data.
 * /*from  ww w . ja v a 2s  .  co  m*/
 * @return a <code>StatisticalSummary</code> object
 */
@Override
public StatisticalSummary getStatisticalSummaryByName(String name) {
    DescriptiveStatistics stats = statisticsByMeasurementName.get(name);

    return new StatisticalSummaryValues(stats.getMean(), stats.getVariance(), stats.getN(), stats.getMax(),
            stats.getMin(), stats.getSum());
}

From source file:org.processmining.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window./*from w w w  . java2 s . c  om*/
 * 
 * @param sortedArray
 *            int[]
 */

public void displayPerformanceMetrics() {
    String type = dcPanel.getTimeOption();
    ArrayList<DescriptiveStatistics> aList = dcModel.getTimeStatistics();
    ArrayList<String> aTitles = dcModel.getDescriptiveStatisticsTitles();

    ArrayList<String> sortedTitleList = dcModel.getSortedKeySetList();

    this.removeAll();
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // add time option menu
    this.add(Box.createRigidArea(new Dimension(5, 10)));
    JPanel menuPanel = new JPanel(new BorderLayout());
    menuPanel.setPreferredSize(new Dimension(160, 45));
    menuPanel.setMaximumSize(new Dimension(180, 45));
    timeSortLabel.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(timeSortLabel, BorderLayout.NORTH);
    timeBox.setMaximumSize(new Dimension(160, 20));
    timeBox.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    menuPanel.add(timeBox, BorderLayout.CENTER);
    this.add(menuPanel);
    this.add(Box.createRigidArea(new Dimension(5, 10)));

    // for each frequency get the set of patterns that have that frequency
    // (run from high frequency to low)
    int size = 0;
    for (int i = 0; i < aList.size(); i++) {
        try {
            String key;
            DescriptiveStatistics currentDS = null;
            if (i != 0)
                key = sortedTitleList.get(i - 1);
            else {
                key = aTitles.get(0);
                currentDS = aList.get(i);
            }

            if (i > 0 && dcModel.getTypeHashMap().equals(DottedChartPanel.ST_INST)
                    && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;
            size++;

            if (i > 0) {
                for (int j = 1; j < aTitles.size(); j++) {
                    if (aTitles.get(j).equals(key))
                        currentDS = aList.get(j);
                }
            }
            AbstractTableModel otm;
            // create labels that contains information about the pattern
            if (i == 0)
                otm = new OverallMetricTableModel();
            else
                otm = new OneMetricTableModel();
            DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
            dtcr.setBackground(new Color(235, 235, 235));
            JTable table = new JTable(otm);
            table.setPreferredSize(new Dimension(200, 55));
            table.setMaximumSize(new Dimension(200, 55));
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(0).setMaxWidth(100);
            table.getTableHeader().setFont(new Font("SansSerif", Font.PLAIN, 12));
            table.getColumnModel().getColumn(0).setCellRenderer(dtcr);
            table.setBorder(BorderFactory.createEtchedBorder());

            // place throughput times in table
            if (type.equals(DottedChartPanel.TIME_ACTUAL)) {
                if (i == 0) {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getStartDateofLogUniList(key)), 0,
                            1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getEndDateofLogUniList(key)), 1,
                            1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_TIME)) {
                if (i == 0) {
                    table.setValueAt(formatDate(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatDate(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatDate(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatDate(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_RATIO)) {
                if (i == 0) {
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatRatio(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / 100, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / 100, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / 100, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_LOGICAL)
                    || type.equals(DottedChartPanel.TIME_LOGICAL_RELATIVE)) {
                if (i == 0) {
                    table.setValueAt(formatString(dcModel.getLogBoundaryLeft().getTime(), 5), 0, 1);
                    table.setValueAt(formatString(dcModel.getLogBoundaryRight().getTime(), 5), 1, 1);
                } else {
                    table.setValueAt(formatString((dcModel.getStartDateofLogUniList(key)).getTime(), 5), 0, 1);
                    table.setValueAt(formatString((dcModel.getEndDateofLogUniList(key)).getTime(), 5), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean(), 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin(), 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax(), 5), 4, 1);
            }

            JPanel tempPanel = new JPanel(new BorderLayout());
            table.setAlignmentX(CENTER_ALIGNMENT);
            tempPanel.setPreferredSize(new Dimension(160, 98));
            tempPanel.setMaximumSize(new Dimension(180, 98));
            tempPanel.add(table.getTableHeader(), BorderLayout.NORTH);
            tempPanel.add(table, BorderLayout.CENTER);
            JPanel tempPanel2 = new JPanel(new BorderLayout());
            JLabel patternLabel = new JLabel("Component " + key + ":");
            patternLabel.setAlignmentX(LEFT_ALIGNMENT);

            JLabel frequencyLabel = null;
            if (i == 0)
                frequencyLabel = new JLabel("# of components: " + currentDS.getN());
            else
                frequencyLabel = new JLabel("# of dots: " + dcModel.getNumberOfLogUnits(key));

            frequencyLabel.setAlignmentX(LEFT_ALIGNMENT);
            frequencyLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
            tempPanel2.add(patternLabel, BorderLayout.NORTH);
            tempPanel2.add(frequencyLabel, BorderLayout.CENTER);
            tempPanel2.add(tempPanel, BorderLayout.SOUTH);
            this.add(tempPanel2);
            this.add(Box.createRigidArea(new Dimension(5, 10)));
        } catch (NullPointerException ex) {
            // can occur when patternMap does not contain a pattern with
            // this frequency
            size--;
        }
    }
    // make sure the pattern performance information is displayed properly
    this.setPreferredSize(new Dimension(200, 140 * (size + 1)));
    this.revalidate();
    this.repaint();

}

From source file:org.processmining.analysis.performance.fsmanalysis.FSMPerformanceAnalysisUI.java

protected double getData(DescriptiveStatistics ds) {
    String sort = (String) measureSort.getValue();
    if (sort.equals("Minimum")) {
        return ds.getMin();
    } else if (sort.equals("Average")) {
        return (ds.getMean());
    } else if (sort.equals("Median")) {
        return (ds.getPercentile(50));
    } else if (sort.equals("Maximum")) {
        return (ds.getMax());
    } else if (sort.equals("Sum")) {
        return (ds.getSum());
    } else if (sort.equals("StandDev")) {
        return (ds.getStandardDeviation());
    } else if (sort.equals("Variance")) {
        return (ds.getStandardDeviation() * ds.getStandardDeviation());
    } else if (sort.equals("Frequency")) {
        return (ds.getN());
    }/*from  ww  w  .java2  s  . c  o  m*/
    return 0.0;
}

From source file:org.prom5.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window./*from   w  w w .j av  a 2  s.com*/
 * @param sortedArray int[]
 */

public void displayPerformanceMetrics() {
    String type = dcPanel.getTimeOption();
    ArrayList<DescriptiveStatistics> aList = dcModel.getTimeStatistics();
    ArrayList<String> aTitles = dcModel.getDescriptiveStatisticsTitles();

    ArrayList<String> sortedTitleList = dcModel.getSortedKeySetList();

    this.removeAll();
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    //add time option menu
    this.add(Box.createRigidArea(new Dimension(5, 10)));
    JPanel menuPanel = new JPanel(new BorderLayout());
    menuPanel.setPreferredSize(new Dimension(160, 45));
    menuPanel.setMaximumSize(new Dimension(180, 45));
    timeSortLabel.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(timeSortLabel, BorderLayout.NORTH);
    timeBox.setMaximumSize(new Dimension(160, 20));
    timeBox.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    menuPanel.add(timeBox, BorderLayout.CENTER);
    this.add(menuPanel);
    this.add(Box.createRigidArea(new Dimension(5, 10)));

    //for each frequency get the set of patterns that have that frequency
    //(run from high frequency to low)
    int size = 0;
    for (int i = 0; i < aList.size(); i++) {
        try {
            String key;
            DescriptiveStatistics currentDS = null;
            if (i != 0)
                key = sortedTitleList.get(i - 1);
            else {
                key = aTitles.get(0);
                currentDS = aList.get(i);
            }

            if (i > 0 && dcModel.getTypeHashMap().equals(DottedChartPanel.ST_INST)
                    && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;
            size++;

            if (i > 0) {
                for (int j = 1; j < aTitles.size(); j++) {
                    if (aTitles.get(j).equals(key))
                        currentDS = aList.get(j);
                }
            }
            AbstractTableModel otm;
            //create labels that contains information about the pattern
            if (i == 0)
                otm = new OverallMetricTableModel();
            else
                otm = new OneMetricTableModel();
            DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
            dtcr.setBackground(new Color(235, 235, 235));
            JTable table = new JTable(otm);
            table.setPreferredSize(new Dimension(200, 55));
            table.setMaximumSize(new Dimension(200, 55));
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(0).setMaxWidth(100);
            table.getTableHeader().setFont(new Font("SansSerif", Font.PLAIN, 12));
            table.getColumnModel().getColumn(0).setCellRenderer(dtcr);
            table.setBorder(BorderFactory.createEtchedBorder());

            //place throughput times in table
            if (type.equals(DottedChartPanel.TIME_ACTUAL)) {
                if (i == 0) {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getStartDateofLogUniList(key)), 0,
                            1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getEndDateofLogUniList(key)), 1,
                            1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_TIME)) {
                if (i == 0) {
                    table.setValueAt(formatDate(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatDate(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatDate(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatDate(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_RATIO)) {
                if (i == 0) {
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatRatio(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / 100, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / 100, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / 100, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_LOGICAL)
                    || type.equals(DottedChartPanel.TIME_LOGICAL_RELATIVE)) {
                if (i == 0) {
                    table.setValueAt(formatString(dcModel.getLogBoundaryLeft().getTime(), 5), 0, 1);
                    table.setValueAt(formatString(dcModel.getLogBoundaryRight().getTime(), 5), 1, 1);
                } else {
                    table.setValueAt(formatString((dcModel.getStartDateofLogUniList(key)).getTime(), 5), 0, 1);
                    table.setValueAt(formatString((dcModel.getEndDateofLogUniList(key)).getTime(), 5), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean(), 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin(), 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax(), 5), 4, 1);
            }

            JPanel tempPanel = new JPanel(new BorderLayout());
            table.setAlignmentX(CENTER_ALIGNMENT);
            tempPanel.setPreferredSize(new Dimension(160, 98));
            tempPanel.setMaximumSize(new Dimension(180, 98));
            tempPanel.add(table.getTableHeader(), BorderLayout.NORTH);
            tempPanel.add(table, BorderLayout.CENTER);
            JPanel tempPanel2 = new JPanel(new BorderLayout());
            JLabel patternLabel = new JLabel("Component " + key + ":");
            patternLabel.setAlignmentX(LEFT_ALIGNMENT);

            JLabel frequencyLabel = null;
            if (i == 0)
                frequencyLabel = new JLabel("# of components: " + currentDS.getN());
            else
                frequencyLabel = new JLabel("# of dots: " + dcModel.getNumberOfLogUnits(key));

            frequencyLabel.setAlignmentX(LEFT_ALIGNMENT);
            frequencyLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
            tempPanel2.add(patternLabel, BorderLayout.NORTH);
            tempPanel2.add(frequencyLabel, BorderLayout.CENTER);
            tempPanel2.add(tempPanel, BorderLayout.SOUTH);
            this.add(tempPanel2);
            this.add(Box.createRigidArea(new Dimension(5, 10)));
        } catch (NullPointerException ex) {
            //can occur when patternMap does not contain a pattern with this frequency
            size--;
        }
    }
    //make sure the pattern performance information is displayed properly
    this.setPreferredSize(new Dimension(200, 140 * (size + 1)));
    this.revalidate();
    this.repaint();

}

From source file:playground.johannes.gsv.analysis.CountsCompareAnalyzer.java

@Override
public void notifyAfterMobsim(AfterMobsimEvent event) {
    Network network = event.getControler().getScenario().getNetwork();
    DescriptiveStatistics error = new DescriptiveStatistics();
    DescriptiveStatistics errorAbs = new DescriptiveStatistics();
    DescriptivePiStatistics errorWeighted = new WSMStatsFactory().newInstance();

    TDoubleArrayList errorVals = new TDoubleArrayList();
    TDoubleArrayList caps = new TDoubleArrayList();
    TDoubleArrayList speeds = new TDoubleArrayList();

    for (Count count : counts.getCounts().values()) {
        if (!count.getLocId().toString().startsWith(ODCalibrator.VIRTUAL_ID_PREFIX)) {
            double obsVal = 0;
            for (int i = 1; i < 25; i++) {
                obsVal += count.getVolume(i).getValue();
            }//from  w w w.  j a  va 2s.c o m

            if (obsVal > 0) {
                double simVal = calculator.getOccupancy(count.getLocId());
                simVal *= factor;

                double err = (simVal - obsVal) / obsVal;

                error.addValue(err);
                errorAbs.addValue(Math.abs(err));
                errorWeighted.addValue(Math.abs(err), 1 / obsVal);

                Link link = network.getLinks().get(count.getLocId());
                errorVals.add(Math.abs(err));
                caps.add(link.getCapacity());
                speeds.add(link.getFreespeed());
            }
        }
    }

    logger.info(String.format("Relative counts error: mean = %s, var = %s, stderr = %s, min = %s, max = %s",
            error.getMean(), error.getVariance(), error.getStandardDeviation(), error.getMin(),
            error.getMax()));
    logger.info(String.format(
            "Absolute relative counts error: mean = %s, var = %s, stderr = %s, min = %s, max = %s",
            errorAbs.getMean(), errorAbs.getVariance(), errorAbs.getStandardDeviation(), errorAbs.getMin(),
            errorAbs.getMax()));
    logger.info(String.format(
            "Absolute weigthed relative counts error: mean = %s, var = %s, stderr = %s, min = %s, max = %s",
            errorWeighted.getMean(), errorWeighted.getVariance(), errorWeighted.getStandardDeviation(),
            errorWeighted.getMin(), errorWeighted.getMax()));

    String outdir = event.getControler().getControlerIO().getIterationPath(event.getIteration());

    try {
        TDoubleDoubleHashMap map = Correlations.mean(caps.toNativeArray(), errorVals.toNativeArray());
        TXTWriter.writeMap(map, "capacity", "counts", String.format("%s/countsError.capacity.txt", outdir));

        map = Correlations.mean(speeds.toNativeArray(), errorVals.toNativeArray());
        TXTWriter.writeMap(map, "speed", "counts", String.format("%s/countsError.speed.txt", outdir));

        TXTWriter.writeMap(Histogram.createHistogram(error, new LinearDiscretizer(0.1), false), "Error",
                "Frequency", String.format("%s/countsError.hist.txt", outdir));
        TXTWriter.writeMap(Histogram.createHistogram(errorAbs, new LinearDiscretizer(0.1), false),
                "Error (absolute)", "Frequency", String.format("%s/countsErrorAbs.hist.txt", outdir));
        TXTWriter.writeMap(Histogram.createHistogram(errorWeighted, new LinearDiscretizer(0.1), true),
                "Error (weighted)", "Frequency", String.format("%s/countsErrorWeighted.hist.txt", outdir));

        CountsCompare2GeoJSON.write(calculator, counts, factor, network, outdir);
        NetworkLoad2GeoJSON.write(event.getControler().getScenario().getNetwork(), calculator, factor,
                outdir + "/network.json");
    } catch (IOException e) {
        e.printStackTrace();
    }

    String rootOutDir = event.getControler().getControlerIO().getOutputPath();
    boolean append = false;
    if (event.getIteration() > 0) {
        append = true;
    }
    writeErrorFile(error, String.format("%s/countsError.txt", rootOutDir), append);
    writeErrorFile(errorAbs, String.format("%s/countsAbsError.txt", rootOutDir), append);
}

From source file:playground.johannes.gsv.analysis.CountsCompareAnalyzer.java

private void writeErrorFile(DescriptiveStatistics error, String file, boolean append) {
    try {/*www. j  a v  a2 s .  c  o m*/
        BufferedWriter writer = new BufferedWriter(new FileWriter(file, append));
        if (!append) {
            // write header
            writer.write("mean\tvar\tstderr\tmin\tmax");
            writer.newLine();
        }

        writer.write(String.valueOf(error.getMean()));
        writer.write("\t");
        writer.write(String.valueOf(error.getVariance()));
        writer.write("\t");
        writer.write(String.valueOf(error.getStandardDeviation()));
        writer.write("\t");
        writer.write(String.valueOf(error.getMin()));
        writer.write("\t");
        writer.write(String.valueOf(error.getMax()));
        writer.newLine();

        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:playground.johannes.gsv.matrices.analysis.MatrixCompare.java

/**
 * @param args//w  w w . j  a v a  2  s  .  c  o m
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    Matrix m1 = new Matrix("1", null);
    VisumMatrixReader reader = new VisumMatrixReader(m1);
    //      reader.readFile("/home/johannes/gsv/matrices/netz2030.fma");
    reader.readFile("/home/johannes/gsv/matrices/itp.fma");

    Matrix m2 = new Matrix("2", null);
    reader = new VisumMatrixReader(m2);
    reader.readFile("/home/johannes/gsv/matrices/miv.489.fma");
    //      reader.readFile("/home/johannes/gsv/matrices/netz2030.fma");

    MatrixOperations.applyFactor(m1, 1 / 365.0);
    //      MatrixOperations.applyFactor(m2, 11);
    //      MatrixOperations.applyIntracellFactor(m2, 1.3);

    System.out.println(String.format("PSMobility - matrix sum: %s", MatrixOperations.sum(m1, false)));
    System.out.println(String.format("Matsim - matrix sum: %s", MatrixOperations.sum(m2, false)));

    System.out.println(
            String.format("PSMobility: %s cells with zero value.", MatrixOperations.countEmptyCells(m1)));
    System.out
            .println(String.format("Matsim: %s cells with zero value.", MatrixOperations.countEmptyCells(m2)));

    boolean ignoreZeros = false;
    DescriptiveStatistics stats = relErrorAll(m1, m2, false, ignoreZeros);
    System.out.println(String.format("Relative error all cells: mean=%s, med=%s, min=%s, max=%s",
            stats.getMean(), stats.getPercentile(0.5), stats.getMin(), stats.getMax()));
    stats = relErrorAll(m1, m2, true, ignoreZeros);
    System.out.println(String.format("Relative error all cells (abs): mean=%s, med=%s, min=%s, max=%s",
            stats.getMean(), stats.getPercentile(0.5), stats.getMin(), stats.getMax()));

    stats = errorStats(relErrorDestinations(m1, m2, false, ignoreZeros));
    System.out.println(String.format("Destination Error: mean=%s, med=%s, min=%s, max=%s", stats.getMean(),
            stats.getPercentile(0.5), stats.getMin(), stats.getMax()));
    stats = errorStats(relErrorDestinations(m1, m2, true, ignoreZeros));
    System.out.println(String.format("Destination Error (abs): mean=%s, med=%s, min=%s, max=%s",
            stats.getMean(), stats.getPercentile(0.5), stats.getMin(), stats.getMax()));

    stats = errorStats(relErrorOrigins(m1, m2, false, ignoreZeros));
    System.out.println(String.format("Origin Error: mean=%s, med=%s, min=%s, max=%s", stats.getMean(),
            stats.getPercentile(0.5), stats.getMin(), stats.getMax()));
    stats = errorStats(relErrorOrigins(m1, m2, true, ignoreZeros));
    System.out.println(String.format("Origin Error (abs): mean=%s, med=%s, min=%s, max=%s", stats.getMean(),
            stats.getPercentile(0.5), stats.getMin(), stats.getMax()));

    ZoneLayer<Map<String, Object>> zones = ZoneLayerSHP.read("/home/johannes/gsv/matrices/zones_zone.SHP");
    TDoubleDoubleHashMap distErrCorrelation = distErrCorrelation(m1, m2, zones, false, ignoreZeros);
    TXTWriter.writeMap(distErrCorrelation, "distance", "rel. error", "/home/johannes/gsv/matrices/distErr.txt");

    Map<String, String> ids = new HashMap<>();
    ids.put("6412", "FRA");
    ids.put("11000", "BER");
    ids.put("2000", "HAM");
    ids.put("3241", "HAN");
    ids.put("5315", "KLN");
    ids.put("9162", "MUN");
    ids.put("8111", "STG");

    zones = ZoneLayerSHP.read("/home/johannes/gsv/matrices/zones_zone.SHP");
    //      distErrCorrelation = distErrCorrelation(m1, m2, zones, ids.keySet(), false, ignoreZeros);
    //      TXTWriter.writeMap(distErrCorrelation, "distance", "rel. error", "/home/johannes/gsv/matrices/distErr.sel.txt");

    Map<String, double[]> relErrs = relError(m1, m2, ids, false);
    for (java.util.Map.Entry<String, double[]> entry : relErrs.entrySet()) {
        System.out.println(String.format("%s: %.4f; old: %.4f, new; %.4f", entry.getKey(), entry.getValue()[0],
                entry.getValue()[1], entry.getValue()[2]));
    }

    System.out.println("\nDestination errors:");
    TObjectDoubleHashMap<String> destErrors = relErrorDestinations(m1, m2, false, ignoreZeros);
    for (java.util.Map.Entry<String, String> entry : ids.entrySet()) {
        System.out.println(String.format("%s: %.4f", entry.getValue(), destErrors.get(entry.getKey())));
    }

    System.out.println("\nOrigin errors:");
    TObjectDoubleHashMap<String> origErrors = relErrorOrigins(m1, m2, false, ignoreZeros);
    for (java.util.Map.Entry<String, String> entry : ids.entrySet()) {
        System.out.println(String.format("%s: %.4f", entry.getValue(), origErrors.get(entry.getKey())));
    }
}