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

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

Introduction

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

Prototype

public double getMean() 

Source Link

Document

Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm"> arithmetic mean </a> of the available values

Usage

From source file:org.mskcc.cbio.cgds.scripts.ImportProteinArrayData.java

private double[] convertToZscores(String[] strs) {
    double[] data = new double[strs.length - 1];
    for (int i = 1; i < strs.length; i++) {
        data[i - 1] = Double.parseDouble(strs[i]);
    }//from   w  ww  . j a va2s. com

    DescriptiveStatistics ds = new DescriptiveStatistics(data);
    double mean = ds.getMean();
    double std = ds.getStandardDeviation();

    for (int i = 0; i < data.length; i++) {
        data[i] = (data[i] - mean) / std;
    }
    return data;
}

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

/**
 * Returns statistical summary of all the data.
 * //from  w w w.  j a  v a 2  s .com
 * @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. j  av a 2s.co  m*/
 * 
 * @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   w ww .  j  a  va  2s .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  ww  . j  a v a  2s  .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.tellervo.desktop.graph.SkeletonPlot.java

private Integer getSkeletonCategoryFromCropper1979(Integer value, DescriptiveStatistics windowStats,
        Double criticalLevel) {/*w  w w .  j av  a2  s  .  c  o  m*/
    Integer skeletonCategory = 0;

    if (criticalLevel == null)
        criticalLevel = 0.5;
    double mean = windowStats.getMean();
    double stdev = windowStats.getStandardDeviation();
    double smallRingThreshold = mean - (stdev * criticalLevel);
    int min = (int) windowStats.getMin();

    if (value == min) {
        skeletonCategory = 10;
    } else if (value > smallRingThreshold) {
        skeletonCategory = 0;
    } else {
        Integer range = (int) (smallRingThreshold - min);
        Integer categoryStepSize = range / 10;
        skeletonCategory = (int) (0 - ((value - smallRingThreshold) / categoryStepSize));
    }

    return skeletonCategory;
}

From source file:org.xenmaster.monitoring.data.Record.java

protected final void applyStatistics(Collection<Double> values) {
    // Let's get statistical
    DescriptiveStatistics ds = new DescriptiveStatistics();

    for (double util : values) {
        ds.addValue(util);/*from   ww w. ja  v  a2s  .c o m*/
    }

    double a = ds.getMean();
    double stdDev = ds.getStandardDeviation();

    // TODO: actually test this and generate warning
    // Check if all vCPUs have a fair load, e.g. [45, 60, 50] would be fair, [90, 4, 2] indicates you should learn threading
    if (stdDev > 0.8) {
        Logger.getLogger(getClass())
                .info((vm ? "VM" : "Host") + " " + reference + " has an unfair load distribution");
    }

    if (stdDev > 0) {
        try {
            NormalDistributionImpl ndi = new NormalDistributionImpl(ds.getMean(), stdDev);
            double cp = ndi.cumulativeProbability(90);
            if (cp > 0.8) {
                // 80% of the CPUs have a >90% load
                // TODO warning
                Logger.getLogger(getClass()).info((vm ? "VM" : "Host") + " " + reference
                        + " has a load >=90% on 80% of the available CPUs");
            }
        } catch (MathException ex) {
            Logger.getLogger(getClass()).error("Flawed maths", ex);
        }
    }
}

From source file:playground.artemc.pricing.SocialCostCalculator.java

private void calcStatistics() {

    // Get a DescriptiveStatistics instance
    DescriptiveStatistics tripStats = new DescriptiveStatistics();
    DescriptiveStatistics tripStatsNormalized = new DescriptiveStatistics();

    // Add the data from the array
    for (LegTrip legTrip : performedLegs) {
        double distance = 0.0;
        double cost = 0.0;
        for (LinkTrip linkTrip : legTrip.linkTrips) {
            double socialCosts = calcSocCosts(linkTrip.link_id, linkTrip.enterTime);
            if (socialCosts > 0.0)
                cost = cost + socialCosts;
            distance = legTrip.distance + network.getLinks().get(linkTrip.link_id).getLength();
        }/*from   w  w  w. j ava  2  s. co m*/

        legTrip.distance = distance;
        legTrip.cost = cost;

        tripStats.addValue(cost);

        /*
         * Normalize a legs social cost by dividing them by the leg travel time or leg distance.
         */
        //double legTravelTime = legTrip.arrivalTime - legTrip.departureTime;
        if (cost > 0.0 && legTrip.distance > 0.0)
            tripStatsNormalized.addValue(cost / legTrip.distance);
    }

    // Compute some statistics
    double sum = tripStats.getSum();
    double mean = tripStats.getMean();
    double std = tripStats.getStandardDeviation();
    double median = tripStats.getPercentile(50);
    double quantile25 = tripStats.getPercentile(25);
    double quantile75 = tripStats.getPercentile(75);

    double sumNormalized = tripStatsNormalized.getSum();
    double meanNormalized = tripStatsNormalized.getMean();
    double stdNormalized = tripStatsNormalized.getStandardDeviation();
    double medianNormalized = tripStatsNormalized.getPercentile(50);
    double quantile25Normalized = tripStatsNormalized.getPercentile(25);
    double quantile75Normalized = tripStatsNormalized.getPercentile(75);

    log.info("Sum of all leg costs: " + sum);
    log.info("Mean leg costs: " + mean);
    log.info("Standard deviation: " + std);
    log.info("Median leg costs: " + median);
    log.info("25% quantile leg costs: " + quantile25);
    log.info("75% quantile leg costs: " + quantile75);

    log.info("Normalized sum of all leg costs: " + sumNormalized);
    log.info("Normalized mean leg costs: " + meanNormalized);
    log.info("Normalized standard deviation: " + stdNormalized);
    log.info("Normalized median leg costs: " + medianNormalized);
    log.info("Normalized 25% quantile leg costs: " + quantile25Normalized);
    log.info("Normalized 75% quantile leg costs: " + quantile75Normalized);

    meanSocialCosts.add(mean);
    medianSocialCosts.add(median);
    quantil25PctSocialCosts.add(quantile25);
    quantil75PctSocialCosts.add(quantile75);

    meanNormalizedSocialCosts.add(meanNormalized);
    medianNormalizedSocialCosts.add(medianNormalized);
    quantil25PctNormalizedSocialCosts.add(quantile25Normalized);
    quantil75PctNormalizedSocialCosts.add(quantile75Normalized);
}

From source file:playground.christoph.socialcosts.SocialCostCalculator.java

private void calcStatistics() {

    // Get a DescriptiveStatistics instance
    DescriptiveStatistics stats = new DescriptiveStatistics();
    DescriptiveStatistics statsNormalized = new DescriptiveStatistics();

    // Add the data from the array
    for (LegTrip legTrip : performedLegs) {
        double costs = 0.0;
        for (LinkTrip linkTrip : legTrip.linkTrips) {
            double socialCosts = calcSocCosts(linkTrip.link_id, linkTrip.enterTime);
            if (socialCosts > 0.0)
                costs = costs + socialCosts;
        }/*  w w  w .j  ava  2s.c  o m*/
        stats.addValue(costs);

        /*
         * Normalize a legs social cost by dividing them by the leg travel time.
         * As a result we get something like social costs per traveled second.
         * Another option would be doing this on link level instead of leg level.
         */
        double legTravelTime = legTrip.arrivalTime - legTrip.departureTime;
        if (costs > 0.0 && legTravelTime > 0.0)
            statsNormalized.addValue(costs / legTravelTime);
    }

    // Compute some statistics
    double sum = stats.getSum();
    double mean = stats.getMean();
    double std = stats.getStandardDeviation();
    double median = stats.getPercentile(50);
    double quantile25 = stats.getPercentile(25);
    double quantile75 = stats.getPercentile(75);

    double sumNormalized = statsNormalized.getSum();
    double meanNormalized = statsNormalized.getMean();
    double stdNormalized = statsNormalized.getStandardDeviation();
    double medianNormalized = statsNormalized.getPercentile(50);
    double quantile25Normalized = statsNormalized.getPercentile(25);
    double quantile75Normalized = statsNormalized.getPercentile(75);

    log.info("Sum of all leg costs: " + sum);
    log.info("Mean leg costs: " + mean);
    log.info("Standard deviation: " + std);
    log.info("Median leg costs: " + median);
    log.info("25% quantile leg costs: " + quantile25);
    log.info("75% quantile leg costs: " + quantile75);

    log.info("Normalized sum of all leg costs: " + sumNormalized);
    log.info("Normalized mean leg costs: " + meanNormalized);
    log.info("Normalized standard deviation: " + stdNormalized);
    log.info("Normalized median leg costs: " + medianNormalized);
    log.info("Normalized 25% quantile leg costs: " + quantile25Normalized);
    log.info("Normalized 75% quantile leg costs: " + quantile75Normalized);

    meanSocialCosts.add(mean);
    medianSocialCosts.add(median);
    quantil25PctSocialCosts.add(quantile25);
    quantil75PctSocialCosts.add(quantile75);

    meanNormalizedSocialCosts.add(meanNormalized);
    medianNormalizedSocialCosts.add(medianNormalized);
    quantil25PctNormalizedSocialCosts.add(quantile25Normalized);
    quantil75PctNormalizedSocialCosts.add(quantile75Normalized);
}

From source file:playground.johannes.coopsim.analysis.ScoreTask.java

@Override
public void analyze(Set<Trajectory> trajectories, Map<String, DescriptiveStatistics> results) {
    DescriptiveStatistics allScores = new DescriptiveStatistics();
    for (Trajectory t : trajectories)
        allScores.addValue(t.getPerson().getSelectedPlan().getScore());
    results.put("score", allScores);

    DescriptiveStatistics actScores = ActivityEvaluator.stopLogging();
    results.put("score_act", actScores);

    DescriptiveStatistics legScores = LegEvaluator.stopLogging();
    results.put("score_leg", legScores);

    Map<String, DescriptiveStatistics> jointScore = JointActivityEvaluator2.stopLogging();
    //      Map<String, DescriptiveStatistics> jointScore = JointActivityEvaluator.stopLogging();
    for (Entry<String, DescriptiveStatistics> entry : jointScore.entrySet()) {
        results.put("score_join_" + entry.getKey(), entry.getValue());
    }/* ww  w . j  a v a  2 s  . c  om*/

    DescriptiveStatistics typeScore = ActivityTypeEvaluator.stopLogging();
    results.put("score_type", typeScore);

    try {
        writeHistograms(allScores, "score", 50, 50);
        writeHistograms(actScores, "score_act", 50, 50);
        writeHistograms(legScores, "score_leg", 50, 50);
        for (Entry<String, DescriptiveStatistics> entry : jointScore.entrySet()) {
            writeHistograms(entry.getValue(), new LinearDiscretizer(0.5), "score_join_" + entry.getKey(),
                    false);
            writeHistograms(entry.getValue(), "score_join_" + entry.getKey(), 50, 50);
        }

        writeHistograms(typeScore, new DummyDiscretizer(), "score_type", false);
    } catch (IOException e) {
        e.printStackTrace();
    }

    scores.add(allScores.getMean());

    if (scores.size() >= MIN_SAMPLES) {
        SimpleRegression reg = new SimpleRegression();

        for (int i = scores.size() - MIN_SAMPLES; i < scores.size(); i++) {
            reg.addData(i, scores.get(i));
        }

        if (reg.getSlope() < THRESHOLD)
            converged = true;
    }

}