Example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getStandardDeviation

List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getStandardDeviation

Introduction

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

Prototype

public double getStandardDeviation() 

Source Link

Document

Returns the standard deviation of the available values.

Usage

From source file:com.github.jessemull.microflexbiginteger.stat.StandardDeviationTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array.//w w  w  . j  a va  2  s .co  m
 */
@Test
public void testAggregatedSetArrayIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    WellSet[] setArrayIndices = new WellSet[arrayIndices.length];

    for (int i = 0; i < setArrayIndices.length; i++) {
        setArrayIndices[i] = arrayIndices[i].dataSet();
    }

    Map<WellSet, BigDecimal> aggregatedReturnedMap = deviation.setsAggregated(setArrayIndices, begin,
            end - begin, mc);
    Map<WellSet, BigDecimal> aggregatedResultMap = new TreeMap<WellSet, BigDecimal>();

    for (WellSet set : setArrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (Well well : set) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSet plate : setArrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.StandardDeviationBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array./*from w ww .j  av a2s  .c om*/
 */
@Test
public void testAggregatedSetArrayIndices() {

    int size = arrayIndices[0].first().size();
    int begin = random.nextInt(size - 5);
    int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

    WellSetBigInteger[] setArrayIndices = new WellSetBigInteger[arrayIndices.length];

    for (int i = 0; i < setArrayIndices.length; i++) {
        setArrayIndices[i] = arrayIndices[i].dataSet();
    }

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = deviation.setsAggregated(setArrayIndices, begin,
            end - begin, mc);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : setArrayIndices) {

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();

        for (WellBigInteger well : set) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigInteger plate : setArrayIndices) {

        BigDecimal result = aggregatedResultMap.get(plate);
        BigDecimal returned = aggregatedReturnedMap.get(plate);
        BigDecimal[] corrected = correctRoundingErrors(result, returned);

        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.itemanalysis.jmetrik.stats.descriptives.DescriptiveAnalysis.java

public void publishTable(VariableAttributes v) {
    TextTable table = null;//w  ww.j av a  2  s.  c om
    TextTableColumnFormat[] cformats = new TextTableColumnFormat[2];
    cformats[0] = new TextTableColumnFormat();
    cformats[0].setStringFormat(15, TextTableColumnFormat.OutputAlignment.LEFT);
    cformats[1] = new TextTableColumnFormat();
    cformats[1].setDoubleFormat(10, 4, TextTableColumnFormat.OutputAlignment.RIGHT);

    DescriptiveStatistics temp = data.get(v);
    table = new TextTable();
    table.addAllColumnFormats(cformats, 17);
    table.getRowAt(0).addHeader(0, 2, v.getName().toString(), TextTablePosition.CENTER);
    table.getRowAt(1).addHorizontalRule(0, 2, "=");
    table.getRowAt(2).addHeader(0, 1, "Statistic", TextTablePosition.CENTER);
    table.getRowAt(2).addHeader(1, 1, "Value", TextTablePosition.CENTER);
    table.getRowAt(3).addHorizontalRule(0, 2, "-");

    table.addStringAt(4, 0, "N");
    table.addDoubleAt(4, 1, maxProgress);
    table.addStringAt(5, 0, "Valid N");
    table.addDoubleAt(5, 1, temp.getN());
    table.addStringAt(6, 0, "Min");
    table.addDoubleAt(6, 1, temp.getMin());
    table.addStringAt(7, 0, "Max");
    table.addDoubleAt(7, 1, temp.getMax());
    table.addStringAt(8, 0, "Mean");
    table.addDoubleAt(8, 1, temp.getMean());
    table.addStringAt(9, 0, "Std. Dev.");
    table.addDoubleAt(9, 1, temp.getStandardDeviation());
    table.addStringAt(10, 0, "Skewness");
    table.addDoubleAt(10, 1, temp.getSkewness());
    table.addStringAt(11, 0, "Kurtosis");
    table.addDoubleAt(11, 1, temp.getKurtosis());
    table.addStringAt(12, 0, "First Quartile");
    table.addDoubleAt(12, 1, temp.getPercentile(25));
    table.addStringAt(13, 0, "Median");
    table.addDoubleAt(13, 1, temp.getPercentile(50));
    table.addStringAt(14, 0, "Third Quartile");
    table.addDoubleAt(14, 1, temp.getPercentile(75));
    table.addStringAt(15, 0, "IQR");
    table.addDoubleAt(15, 1, temp.getPercentile(75) - temp.getPercentile(25));
    table.getRowAt(16).addHorizontalRule(0, 2, "=");

    publish(table.toString() + "\n");

}

From source file:knop.psfj.FovDataSet.java

/**
 * Gets the min.// w ww.j av  a  2  s.co m
 *
 * @param column the column
 * @return the min
 */
public double getMin(String column) {
    if (column.contains("fwhm")) {
        return getTheoriticalValue(column) / 2;
    }

    if (column.contains("delta") || column.contains("norm")) {
        return -1;
    }

    DescriptiveStatistics columnStats = getColumnStatistics(column);
    double median = columnStats.getPercentile(50);
    double stdDev = columnStats.getStandardDeviation();
    if (stdDev == 0)
        return -1;
    return median - (stdDev * 2);

}

From source file:knop.psfj.FovDataSet.java

/**
 * Gets the max.//from   w  w  w  .jav a2  s.  co m
 *
 * @param column the column
 * @return the max
 */
public double getMax(String column) {
    if (column.contains("fwhm")) {
        return getTheoriticalValue(column) * 2;
    }

    if (column.contains("norm"))
        return 1;

    if (column.equals("z_profile") || column.contains("delta")) {
        return 1;
    }

    DescriptiveStatistics columnStats = getColumnStatistics(column);
    double median = columnStats.getPercentile(50);
    double stdDev = columnStats.getStandardDeviation();
    if (stdDev == 0)
        return 1;
    return median + (stdDev * 2);
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileDataTable.java

/**
 * Computes the column-wise standard deviation of values whose column 
 * key matches any of the labels passed as arguments. The result is 
 * appended to the bottom of the table and prefixed with a '#' symbol
 * to prevent methods such as {@link #columnMultiply(double, String...)}
 * to operate on them./*from www .  j a  v  a  2 s  .co m*/
 * @param rowLabel the name of the result as it should appear in the
 * leftmost row
 * @param labels a set of filters to match column keys against
 */
public void insertColumnStdev(String rowLabel, String... labels) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    List<String> columnKeys = getColumnKeys();
    List<String> rowKeys = getRowKeys();
    rowLabel = "# " + rowLabel;

    for (String label : labels) {
        for (String columnKey : columnKeys) {

            if (isSubsetOf(columnKey, label)) {
                for (String rowKey : rowKeys) {
                    if (!StringUtils.startsWith(rowKey, "#")) {
                        stats.addValue(getValue(rowKey, columnKey).doubleValue());
                    }
                }
            }

            setValue(stats.getStandardDeviation(), rowLabel, columnKey);
            stats.clear();
        }
    }
}

From source file:net.adamjak.thomas.graph.application.run.TestRunner.java

private void save(Map<String, Object> results, boolean rawData) {
    SnarkTestTypes testType = (SnarkTestTypes) results.get("testType");

    if (this.outputFile.getName().split("\\.")[this.outputFile.getName().split("\\.").length - 1].toLowerCase()
            .equals("ods")) {

        String[] columnNames;/*from   w  w w  .j a v  a  2 s  .  c  o m*/
        Object[][] data;

        if (testType == SnarkTestTypes.ALL_ALGORITHMS) {
            GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

            columnNames = String.valueOf("Algorithm,Graph ID,Avarage time,Standard deviation,Minimum,Maximum")
                    .split(",");
            data = new Object[graphTestResult[0].length][6];

            for (int cls = 0; cls < graphTestResult[0][0].length; cls++) {
                Class<?> c = (Class<?>) graphTestResult[0][0][cls].getValue("algorithmClass");

                for (int graph = 0; graph < graphTestResult[0].length; graph++) {
                    SummaryStatistics summaryStatistics = new SummaryStatistics();

                    for (int run = 0; run < graphTestResult.length; run++) {
                        summaryStatistics
                                .addValue((double) graphTestResult[run][graph][cls].getValue("timeInSeconds"));
                    }

                    data[graph][0] = c.getSimpleName();
                    data[graph][1] = graph;
                    data[graph][2] = summaryStatistics.getMean();
                    data[graph][3] = summaryStatistics.getStandardDeviation();
                    data[graph][4] = summaryStatistics.getMin();
                    data[graph][5] = summaryStatistics.getMax();
                }
            }
        } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) {
            GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

            columnNames = String
                    .valueOf("Graph ID,Start vertex,Avarage time,Standard deviation,Minimum,Maximum")
                    .split(",");
            data = new Object[graphTestResult[0].length][6];

            for (int vid = 0; vid < graphTestResult[0][0].length; vid++) {
                for (int graph = 0; graph < graphTestResult[0].length; graph++) {
                    SummaryStatistics summaryStatistics = new SummaryStatistics();

                    for (int run = 0; run < graphTestResult.length; run++) {
                        summaryStatistics
                                .addValue((double) graphTestResult[run][graph][vid].getValue("timeInSeconds"));
                    }

                    data[graph][0] = graph;
                    data[graph][1] = vid;
                    data[graph][2] = summaryStatistics.getMean();
                    data[graph][3] = summaryStatistics.getStandardDeviation();
                    data[graph][4] = summaryStatistics.getMin();
                    data[graph][5] = summaryStatistics.getMax();
                }
            }
        } else {
            GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData");

            columnNames = String.valueOf("Graph ID,Avarage time,Standard deviation,Minimum,Maximum").split(",");
            data = new Object[graphTestResult[0].length][5];

            for (int graph = 0; graph < graphTestResult[0].length; graph++) {
                SummaryStatistics summaryStatistics = new SummaryStatistics();

                for (int run = 0; run < graphTestResult.length; run++) {
                    summaryStatistics.addValue((double) graphTestResult[run][graph].getValue("timeInSeconds"));
                }

                data[graph][0] = graph;
                data[graph][1] = summaryStatistics.getMean();
                data[graph][2] = summaryStatistics.getStandardDeviation();
                data[graph][3] = summaryStatistics.getMin();
                data[graph][4] = summaryStatistics.getMax();
            }
        }

        try {
            SpreadSheet.createEmpty(new JTable(data, columnNames).getModel()).saveAs(outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (rawData == true) {
            if (testType == SnarkTestTypes.ALL_ALGORITHMS) {
                GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

                columnNames = String.valueOf("Class,Run,Graph,Time").split(",");
                data = new Object[graphTestResult.length * graphTestResult[0].length
                        * graphTestResult[0][0].length][4];

                int row = 0;
                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        for (int k = 0; k < graphTestResult[i][j].length; k++) {
                            data[row][0] = graphTestResult[i][j][k].getValue("algorithmClass");
                            data[row][1] = i;
                            data[row][2] = j;
                            data[row][3] = graphTestResult[i][j][k].getValue("time");
                            row++;
                        }
                    }
                }
            } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) {
                GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

                columnNames = String.valueOf("Run,Graph,Vertex,Time").split(",");
                data = new Object[graphTestResult.length * graphTestResult[0].length
                        * graphTestResult[0][0].length][4];

                int row = 0;
                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        for (int k = 0; k < graphTestResult[i][j].length; k++) {
                            data[row][0] = i;
                            data[row][1] = j;
                            data[row][2] = k;
                            data[row][3] = graphTestResult[i][j][k].getValue("time");
                            row++;
                        }
                    }
                }
            } else if (testType == SnarkTestTypes.ALGORITHM_COMPARATION) {
                GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData");

                columnNames = String.valueOf("Run,Graph,Time,Class").split(",");
                data = new Object[graphTestResult.length * graphTestResult[0].length][4];

                int row = 0;
                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        data[row][0] = i;
                        data[row][1] = j;
                        data[row][2] = graphTestResult[i][j].getValue("time");
                        data[row][3] = ((Class<?>) graphTestResult[i][j]
                                .getValue(GraphTestResult.SNARK_TESTER_CLASS_KEY)).getSimpleName();
                        row++;
                    }
                }
            } else {
                GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData");

                columnNames = String.valueOf("Run,Graph,Time").split(",");
                data = new Object[graphTestResult.length * graphTestResult[0].length][3];

                int row = 0;
                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        data[row][0] = i;
                        data[row][1] = j;
                        data[row][2] = graphTestResult[i][j].getValue("time");
                        row++;
                    }
                }
            }

            try {
                SpreadSheet.createEmpty(new JTable(data, columnNames).getModel()).saveAs(outputFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        StringBuilder sbData = new StringBuilder();

        if (testType == SnarkTestTypes.ALL_ALGORITHMS) {
            GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

            sbData.append(",,All data,,,,,Data without extremes,,,,,\n");
            sbData.append(
                    "Graph ID,Graph ID,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval\n");

            for (int cls = 0; cls < graphTestResult[0][0].length; cls++) {
                Class<?> c = (Class<?>) graphTestResult[0][0][cls].getValue("algorithmClass");

                for (int graph = 0; graph < graphTestResult[0].length; graph++) {
                    DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics();

                    for (int run = 0; run < graphTestResult.length; run++) {
                        descriptiveStatistics
                                .addValue((double) graphTestResult[run][graph][cls].getValue("timeInSeconds"));
                    }

                    DescriptiveStatistics descriptiveStatisticsWithoutExtremes = StatisticsUtils
                            .statisticsWithoutExtremes(descriptiveStatistics, StatisticsUtils.GrubbsLevel.L005);

                    sbData.append(c.getSimpleName());
                    sbData.append(",");
                    sbData.append(graph);
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getMean());
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getStandardDeviation());
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getMin());
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getMax());
                    sbData.append(",");
                    sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatistics,
                            StatisticsUtils.NormCritical.U0050));
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getMean());
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getStandardDeviation());
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getMin());
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getMax());
                    sbData.append(",");
                    sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatisticsWithoutExtremes,
                            StatisticsUtils.NormCritical.U0050));
                    sbData.append("\n");
                }
            }
        } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) {
            GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

            sbData.append(",,All data,,,,,Data without extremes,,,,,\n");
            sbData.append(
                    "Graph ID,Start vertex,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval\n");

            for (int vid = 0; vid < graphTestResult[0][0].length; vid++) {
                for (int graph = 0; graph < graphTestResult[0].length; graph++) {
                    DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics();

                    for (int run = 0; run < graphTestResult.length; run++) {
                        descriptiveStatistics
                                .addValue((double) graphTestResult[run][graph][vid].getValue("timeInSeconds"));
                    }

                    DescriptiveStatistics descriptiveStatisticsWithoutExtremes = StatisticsUtils
                            .statisticsWithoutExtremes(descriptiveStatistics, StatisticsUtils.GrubbsLevel.L005);

                    sbData.append(graph);
                    sbData.append(",");
                    sbData.append(vid);
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getMean());
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getStandardDeviation());
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getMin());
                    sbData.append(",");
                    sbData.append(descriptiveStatistics.getMax());
                    sbData.append(",");
                    sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatistics,
                            StatisticsUtils.NormCritical.U0050));
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getMean());
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getStandardDeviation());
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getMin());
                    sbData.append(",");
                    sbData.append(descriptiveStatisticsWithoutExtremes.getMax());
                    sbData.append(",");
                    sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatisticsWithoutExtremes,
                            StatisticsUtils.NormCritical.U0050));
                    sbData.append("\n");
                }
            }
        } else {

            GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData");

            sbData.append(",All data,,,,,Data without extremes,,,,,\n");
            sbData.append(
                    "Graph ID,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval\n");

            for (int graph = 0; graph < graphTestResult[0].length; graph++) {
                DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics();

                for (int run = 0; run < graphTestResult.length; run++) {
                    descriptiveStatistics
                            .addValue((double) graphTestResult[run][graph].getValue("timeInSeconds"));
                }

                DescriptiveStatistics descriptiveStatisticsWithoutExtremes = StatisticsUtils
                        .statisticsWithoutExtremes(descriptiveStatistics, StatisticsUtils.GrubbsLevel.L005);

                sbData.append(graph);
                sbData.append(",");
                sbData.append(descriptiveStatistics.getMean());
                sbData.append(",");
                sbData.append(descriptiveStatistics.getStandardDeviation());
                sbData.append(",");
                sbData.append(descriptiveStatistics.getMin());
                sbData.append(",");
                sbData.append(descriptiveStatistics.getMax());
                sbData.append(",");
                sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatistics,
                        StatisticsUtils.NormCritical.U0050));
                sbData.append(",");
                sbData.append(descriptiveStatisticsWithoutExtremes.getMean());
                sbData.append(",");
                sbData.append(descriptiveStatisticsWithoutExtremes.getStandardDeviation());
                sbData.append(",");
                sbData.append(descriptiveStatisticsWithoutExtremes.getMin());
                sbData.append(",");
                sbData.append(descriptiveStatisticsWithoutExtremes.getMax());
                sbData.append(",");
                sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatisticsWithoutExtremes,
                        StatisticsUtils.NormCritical.U0050));
                sbData.append("\n");
            }

        }

        this.saveStringIntoFile(this.outputFile, sbData.toString());

        if (rawData == true) {
            StringBuilder sbRawData = new StringBuilder();

            if (testType == SnarkTestTypes.ALL_ALGORITHMS) {
                GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

                sbRawData.append("Class,Run,Graph,Time\n");

                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        for (int k = 0; k < graphTestResult[i][j].length; k++) {
                            sbRawData.append(graphTestResult[i][j][k].getValue("algorithmClass"));
                            sbRawData.append(",");
                            sbRawData.append(i);
                            sbRawData.append(",");
                            sbRawData.append(j);
                            sbRawData.append(",");
                            sbRawData.append(graphTestResult[i][j][k].getValue("time"));
                            sbRawData.append("\n");
                        }
                    }
                }
            } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) {
                GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData");

                sbRawData.append("Run,Graph,Vertex,Time\n");

                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        for (int k = 0; k < graphTestResult[i][j].length; k++) {
                            sbRawData.append(i);
                            sbRawData.append(",");
                            sbRawData.append(j);
                            sbRawData.append(",");
                            sbRawData.append(k);
                            sbRawData.append(",");
                            sbRawData.append(graphTestResult[i][j][k].getValue("time"));
                            sbRawData.append("\n");
                        }
                    }
                }
            } else if (testType == SnarkTestTypes.ALGORITHM_COMPARATION) {
                GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData");

                sbRawData.append("Run,Graph,Time,Class\n");

                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        sbRawData.append(i);
                        sbRawData.append(",");
                        sbRawData.append(j);
                        sbRawData.append(",");
                        sbRawData.append(graphTestResult[i][j].getValue("time"));
                        sbRawData.append(",");
                        sbRawData.append(((Class<?>) graphTestResult[i][j]
                                .getValue(GraphTestResult.SNARK_TESTER_CLASS_KEY)).getSimpleName());
                        sbRawData.append("\n");
                    }
                }
            } else {
                GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData");

                sbRawData.append("Run,Graph,Time\n");

                for (int i = 0; i < graphTestResult.length; i++) {
                    for (int j = 0; j < graphTestResult[i].length; j++) {
                        sbRawData.append(i);
                        sbRawData.append(",");
                        sbRawData.append(j);
                        sbRawData.append(",");
                        sbRawData.append(graphTestResult[i][j].getValue("time"));
                        sbRawData.append("\n");
                    }
                }
            }

            this.saveStringIntoFile(new File(this.outputFile.getParent(), "raw_" + this.outputFile.getName()),
                    sbRawData.toString());
        }
    }
}

From source file:knop.psfj.FovDataSet.java

/**
 * Gets the column median.// w  ww. j a  v  a  2 s . co  m
 *
 * @param column the column
 * @return the column median
 */
public String getColumnMedian(String column) {
    // TODO Auto-generated method stub
    DescriptiveStatistics stats = getColumnStatistics(column);
    //System.out.println("stddev : " + stats.getStandardDeviation());
    return "" + MathUtils.formatDouble(stats.getPercentile(50), getColumnUnit(column)) + " +/- "
            + MathUtils.formatDouble(stats.getStandardDeviation(), getColumnUnit(column));
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeries.java

/**
 * Computes the standard deviation of the data points in this time series.
 * /*from   w  w w.  j a  v a 2s . co m*/
 * @return the standard deviation of this time series
 */
public double operatorStdev() {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i < this.getItemCount(); i++)
        stats.addValue(getValue(i).doubleValue());

    return stats.getStandardDeviation();
}

From source file:edu.snu.leader.util.ParseableStatistics.java

/**
 * Called immediately after evaluation occurs.
 *
 * @param state The current state of evolution
 *///w w  w.ja va 2 s.c  o  m
@Override
public void postEvaluationStatistics(final EvolutionState state) {
    // Before we do anything, get the time
    long evalTime = (System.currentTimeMillis() - _evalStartTime);
    println("eval-time = " + evalTime, state);
    println("eval-time-human = " + TimeUnit.MILLISECONDS.toMinutes(evalTime) + "m "
            + TimeUnit.MILLISECONDS.toSeconds(evalTime) + "s", state);
    _evalTotalTime += evalTime;

    // Call the superclass impl
    super.postEvaluationStatistics(state);

    // Define the variables to prevent a lot of gc
    Individual bestOfGenInd = null;
    Individual currentInd = null;
    Subpopulation subPop = null;
    int subPopSize = 0;
    String prefix = null;
    double indFitness = 0.0d;

    // Get the statistics objects
    DescriptiveStatistics fitnessStats = new DescriptiveStatistics();

    // Iterate over the sub-populations
    for (int i = 0; i < state.population.subpops.length; i++) {
        // Save some commonly accessed variables here
        subPop = state.population.subpops[i];
        subPopSize = subPop.individuals.length;
        prefix = "subpop[" + _2_DIGIT_FORMATTER.format(i) + "].";

        // Iterate over all the individuals in the sub-population
        bestOfGenInd = null;
        //            _bestFound[i] = bestOfGenInd;
        //            _bestFoundGen[i] = state.generation;
        for (int j = 0; j < subPopSize; j++) {
            // Get the current individual
            currentInd = subPop.individuals[j];

            // Get the fitness statistic
            indFitness = ((SimpleFitness) currentInd.fitness).fitness();
            fitnessStats.addValue(indFitness);

            // Is this individual the best found for this subpopulation
            // for this generation?
            if ((null == bestOfGenInd) || (currentInd.fitness.betterThan(bestOfGenInd.fitness))) {
                bestOfGenInd = currentInd;

                // Is it the best of the run?
                if ((_bestFound[i] == null) || (currentInd.fitness.betterThan(_bestFound[i].fitness))) {
                    // Yup
                    _bestFound[i] = currentInd;
                    _bestFoundGen[i] = state.generation;
                }
            }
        }

        // Compute and log the mean values and variance of the fitness stats
        println(prefix + "fitness-mean = " + fitnessStats.getMean(), state);
        println(prefix + "fitness-variance = " + fitnessStats.getVariance(), state);
        println(prefix + "fitness-std-dev = " + fitnessStats.getStandardDeviation(), state);

        // Display the best individual's stats
        print(buildIndDescription(bestOfGenInd, state, true, prefix + "best-individual."), state);

        println(prefix + "best-individual-found-so-far.fitness = "
                + ((SimpleFitness) _bestFound[i].fitness).fitness(), state);
        println(prefix + "best-individual-found-so-far.generation = " + _bestFoundGen[i], state);
    }

    state.output.flush();
}