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

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

Introduction

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

Prototype

public double getMin() 

Source Link

Document

Returns the minimum of the available values

Usage

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

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*from ww w  .  j  a  va 2 s.co m*/
@Test
public void testAggregatedSetCollection() {

    List<WellSetBigInteger> collection = new ArrayList<WellSetBigInteger>();

    for (PlateBigInteger plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = min.setsAggregated(collection);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : collection) {

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

        for (WellBigInteger well : set) {
            resultList.addAll(well.toBigDecimal());
        }

        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.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigInteger set : collection) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

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

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

/**
 * Tests the aggregated plate statistics method using an array.
 *///  www . j av a 2  s .  c om
@Test
public void testAggregatedSetArray() {

    WellSetBigInteger[] setArray = new WellSetBigInteger[array.length];

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

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = min.setsAggregated(setArray);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : setArray) {

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

        for (WellBigInteger well : set) {
            resultList.addAll(well.toBigDecimal());
        }

        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.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigInteger set : setArray) {

        BigDecimal result = aggregatedResultMap.get(set);
        BigDecimal returned = aggregatedReturnedMap.get(set);

        BigDecimal[] corrected = correctRoundingErrors(result, returned);

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

}

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

/**
 * Tests the plate statistics method using the values between the indices.
 *///from  ww w.ja  v  a 2 s .c  o m
@Test
public void testPlateIndices() {

    for (PlateBigInteger plate : arrayIndices) {

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

        Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>();
        Map<WellBigInteger, BigDecimal> returnedMap = min.plate(plate, begin, end - begin);

        for (WellBigInteger well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigInteger well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

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

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

/**
 * Tests set calculation using indices./*from  w w  w.  j a  v  a 2 s  . c om*/
 */
@Test
public void testSetIndices() {

    for (PlateBigInteger plate : arrayIndices) {

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

        Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>();
        Map<WellBigInteger, BigDecimal> returnedMap = min.set(plate.dataSet(), begin, end - begin);

        for (WellBigInteger well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigInteger bi : well) {
                input[index++] = bi.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigInteger well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

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

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

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the collection.//from   ww w . j  a va  2 s  .c  om
 */
@Test
public void testAggregatedSetCollectionIndices() {

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

    List<WellSetBigInteger> collection = new ArrayList<WellSetBigInteger>();

    for (PlateBigInteger plate : arrayIndices) {
        collection.add(plate.dataSet());
    }

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = min.setsAggregated(collection, begin,
            end - begin);
    Map<WellSetBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<WellSetBigInteger, BigDecimal>();

    for (WellSetBigInteger set : collection) {

        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.getMin();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);
        aggregatedResultMap.put(set, aggregatedResult);
    }

    for (WellSetBigInteger set : collection) {

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

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

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

/**
 * Tests the aggregated plate statistics method using the values between the indices of
 * the array./*from w  ww.  ja  v  a 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);

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

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

    Map<WellSetBigInteger, BigDecimal> aggregatedReturnedMap = min.setsAggregated(setArrayIndices, begin,
            end - begin);
    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.getMin();

        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.intuit.tank.persistence.databases.BucketDataItemTest.java

/**
 * Run the DescriptiveStatistics getStats() method test.
 * //from ww w.j a  v a2s. c om
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/10/14 10:32 AM
 */
@Test
public void testGetStats_1() throws Exception {
    BucketDataItem fixture = new BucketDataItem(1, new Date(), new DescriptiveStatistics());

    DescriptiveStatistics result = fixture.getStats();

    assertNotNull(result);
    assertEquals(
            "DescriptiveStatistics:\nn: 0\nmin: NaN\nmax: NaN\nmean: NaN\nstd dev: NaN\nmedian: NaN\nskewness: NaN\nkurtosis: NaN\n",
            result.toString());
    assertEquals(Double.NaN, result.getMax(), 1.0);
    assertEquals(Double.NaN, result.getVariance(), 1.0);
    assertEquals(Double.NaN, result.getMean(), 1.0);
    assertEquals(-1, result.getWindowSize());
    assertEquals(0.0, result.getSumsq(), 1.0);
    assertEquals(Double.NaN, result.getKurtosis(), 1.0);
    assertEquals(0.0, result.getSum(), 1.0);
    assertEquals(Double.NaN, result.getSkewness(), 1.0);
    assertEquals(Double.NaN, result.getPopulationVariance(), 1.0);
    assertEquals(Double.NaN, result.getStandardDeviation(), 1.0);
    assertEquals(Double.NaN, result.getGeometricMean(), 1.0);
    assertEquals(0L, result.getN());
    assertEquals(Double.NaN, result.getMin(), 1.0);
}

From source file:knop.psfj.BeadFrame.java

/**
 * Gets the minimum value among X, Y and Z fitting goodness.
 * /*from  w  w  w .  j  a  va 2s.c om*/
 * @return the fitting goodness
 */
public double getMinimumFittingGoodness() {

    DescriptiveStatistics stats = new DescriptiveStatistics(R2);
    return stats.getMin();
}

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 va2  s. co 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:com.alibaba.dubbo.demo.consumer.DemoAction.java

public void start() throws Exception {
    int threads = 100;

    final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics();

    DubboBenchmark.BenchmarkMessage msg = prepareArgs();
    final byte[] msgBytes = msg.toByteArray();

    int n = 1000000;
    final CountDownLatch latch = new CountDownLatch(n);

    ExecutorService es = Executors.newFixedThreadPool(threads);

    final AtomicInteger trans = new AtomicInteger(0);
    final AtomicInteger transOK = new AtomicInteger(0);

    long start = System.currentTimeMillis();
    for (int i = 0; i < n; i++) {
        es.submit(() -> {//from  w  w  w  .  j av  a  2 s .c  o  m
            try {

                long t = System.currentTimeMillis();
                DubboBenchmark.BenchmarkMessage m = testSay(msgBytes);
                t = System.currentTimeMillis() - t;
                stats.addValue(t);

                trans.incrementAndGet();

                if (m != null && m.getField1().equals("OK")) {
                    transOK.incrementAndGet();
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                latch.countDown();
            }
        });
    }

    latch.await();

    start = System.currentTimeMillis() - start;

    System.out.printf("sent     requests    : %d\n", n);
    System.out.printf("received requests    : %d\n", trans.get());
    System.out.printf("received requests_OK : %d\n", transOK.get());
    System.out.printf("throughput  (TPS)    : %d\n", n * 1000 / start);

    System.out.printf("mean: %f\n", stats.getMean());
    System.out.printf("median: %f\n", stats.getPercentile(50));
    System.out.printf("max: %f\n", stats.getMax());
    System.out.printf("min: %f\n", stats.getMin());

    System.out.printf("99P: %f\n", stats.getPercentile(90));
}