Example usage for org.apache.commons.math.stat.descriptive SummaryStatistics addValue

List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics addValue

Introduction

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

Prototype

public void addValue(double value) 

Source Link

Document

Add a value to the data

Usage

From source file:it.univpm.deit.semedia.musicuri.utils.experimental.LambdaCalculator.java

public static void main(String[] args) throws Exception {

    //*****************************************************************************
    //*************************   F I L E   I N P U T   ***************************
    //*****************************************************************************

    if ((args.length == 1) && (new File(args[0]).exists())) {
        // get the file's canonical path
        File givenHandle = new File(args[0]);
        String queryAudioCanonicalPath = givenHandle.getCanonicalPath();
        System.out.println("Input: " + queryAudioCanonicalPath);

        //PerformanceStatistic tempStat;
        SummaryStatistics lambdaSummary = SummaryStatistics.newInstance();

        if (givenHandle.isDirectory()) {

            File[] list = givenHandle.listFiles();
            if (list.length == 0) {
                System.out.println("Directory is empty");
                return;
            } else {
                ArrayList allStats = new ArrayList();
                File currentFile;
                for (int i = 0; i < list.length; i++) {
                    currentFile = list[i];
                    try {
                        if (Toolset.isSupportedAudioFile(currentFile)) {
                            System.out.println("\nCalculating optimal lambda : " + currentFile.getName());
                            lambdaSummary.addValue(getBestLambda(new MusicURIQuery(currentFile)));
                        }/*www . j  a  v a2  s. com*/
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                //               System.out.println("\n\nStatistics for Test Case: " + queryAudioCanonicalPath);
                //               mergeStatistics(allStats);
            }
        }
        if (givenHandle.isFile()) {
            if (Toolset.isSupportedAudioFile(givenHandle)) {
                //               tempStat = getBestLambda (new MusicURIQuery(givenHandle));
                //               if (tempStat!=null)
                //               {
                //                  //tempStat.printStatistics();
                //                  ArrayList allStats = new ArrayList();
                //                  allStats.add(tempStat);
                //                  mergeStatistics(allStats);
                //               }
                //               else 
                //                  System.out.println("Error in identification ");
            }
        }

    } //end if
    else {
        System.err.println("LambdaCalculator");
        System.err.println("Usage: java tester.LambdaCalculator {directory}");
    }

}

From source file:com.netflix.dyno.connectionpool.impl.lb.CircularListTest.java

private static double checkValues(List<Integer> values) {

    System.out.println("Values: " + values);
    SummaryStatistics ss = new SummaryStatistics();
    for (int i = 0; i < values.size(); i++) {
        ss.addValue(values.get(i));
    }/*w ww  .ja v a2s. c  o  m*/

    double mean = ss.getMean();
    double stddev = ss.getStandardDeviation();

    double p = ((stddev * 100) / mean);
    System.out.println("Percentage diff: " + p);

    Assert.assertTrue("" + p + " " + values, p < 0.1);
    return p;
}

From source file:it.univpm.deit.semedia.musicuri.utils.experimental.LambdaCalculator.java

public static void mergeStatistics(ArrayList allStats) {
    PerformanceStatistic tempStat;//from   w w  w.j  a  va2s .  c o m

    int truePositives = 0;
    int falsePositives = 0;
    int trueNegatives = 0;
    int falseNegatives = 0;

    SummaryStatistics TPBestMatchSummary = SummaryStatistics.newInstance();
    SummaryStatistics TPSecondBestSummary = SummaryStatistics.newInstance();

    SummaryStatistics FPBestMatchSummary = SummaryStatistics.newInstance();

    SummaryStatistics BothTP_FPBestMatchSummary = SummaryStatistics.newInstance();

    SummaryStatistics TNSummary = SummaryStatistics.newInstance();
    SummaryStatistics FNSummary = SummaryStatistics.newInstance();

    SummaryStatistics pruningSpeedSummary = SummaryStatistics.newInstance();
    SummaryStatistics matchingSpeedSummary = SummaryStatistics.newInstance();
    SummaryStatistics totalSpeedSummary = SummaryStatistics.newInstance();

    for (int i = 0; i < allStats.size(); i++) {
        tempStat = (PerformanceStatistic) allStats.get(i);

        if (tempStat.isTruePositive())
            truePositives++;
        if (tempStat.isFalsePositive())
            falsePositives++;
        if (tempStat.isTrueNegative())
            trueNegatives++;
        if (tempStat.isFalseNegative())
            falseNegatives++;

        // accurate results only
        //if (tempStat.isTruePositive() || tempStat.isTrueNegative())

        pruningSpeedSummary.addValue(tempStat.getPruningTime());
        matchingSpeedSummary.addValue(tempStat.getMatchingTime());
        totalSpeedSummary.addValue(tempStat.getPruningTime() + tempStat.getMatchingTime());

        if (tempStat.isTruePositive()) {
            TPBestMatchSummary.addValue(tempStat.getBestMatchDistance());
            TPSecondBestSummary.addValue(tempStat.getSecondBestMatchDistance());
        }

        if (tempStat.isFalsePositive()) {
            FPBestMatchSummary.addValue(tempStat.getBestMatchDistance());
        }

        BothTP_FPBestMatchSummary.addValue(tempStat.getBestMatchDistance());

    }

    System.out.println("---------------------------------------------------------");

    System.out.println("\nTrue Positives      : " + truePositives + "/" + allStats.size());
    System.out.println("False Positives     : " + falsePositives + "/" + allStats.size());
    System.out.println("True Negatives      : " + trueNegatives + "/" + allStats.size());
    System.out.println("False Negatives     : " + falseNegatives + "/" + allStats.size());

    System.out.println("\nTrue Positive Best Match Statistics");
    System.out.println("Distance Min        : " + TPBestMatchSummary.getMin());
    System.out.println("Distance Max        : " + TPBestMatchSummary.getMax());
    System.out.println("Distance Mean       : " + TPBestMatchSummary.getMean());
    System.out.println("Distance Variance   : " + TPBestMatchSummary.getVariance());
    System.out.println("Distance StdDev     : " + TPBestMatchSummary.getStandardDeviation());
    System.out.println("Confidence Mean     : " + (100 - (100 * (TPBestMatchSummary.getMean()))) + " %");

    System.out.println("\nTrue Positive Second Best Statistics");
    System.out.println("Distance Min        : " + TPSecondBestSummary.getMin());
    System.out.println("Distance Max        : " + TPSecondBestSummary.getMax());
    System.out.println("Distance Mean       : " + TPSecondBestSummary.getMean());
    System.out.println("Confidence Mean     : " + (100 - (100 * (TPSecondBestSummary.getMean()))) + " %");

    System.out.println("\nFalse Positive Best Match Statistics");
    System.out.println("Distance Min        : " + FPBestMatchSummary.getMin());
    System.out.println("Distance Max        : " + FPBestMatchSummary.getMax());
    System.out.println("Distance Mean       : " + FPBestMatchSummary.getMean());
    System.out.println("Distance Variance   : " + FPBestMatchSummary.getVariance());
    System.out.println("Distance StdDev     : " + FPBestMatchSummary.getStandardDeviation());
    System.out.println("Confidence Mean     : " + (100 - (100 * (FPBestMatchSummary.getMean()))) + " %");

    System.out.println("\nBest Match Statistics (Regardless being False or True Positive) ");
    System.out.println("Distance Min        : " + BothTP_FPBestMatchSummary.getMin());
    System.out.println("Distance Max        : " + BothTP_FPBestMatchSummary.getMax());
    System.out.println("Distance Mean       : " + BothTP_FPBestMatchSummary.getMean());
    System.out.println("Distance Variance   : " + BothTP_FPBestMatchSummary.getVariance());
    System.out.println("Distance StdDev     : " + BothTP_FPBestMatchSummary.getStandardDeviation());
    System.out.println("Confidence Mean     : " + (100 - (100 * (BothTP_FPBestMatchSummary.getMean()))) + " %");

    System.out.println("\n\nPruning Speed Statistics");
    System.out.println("Speed Min           : " + (pruningSpeedSummary.getMin() / 1000) + " sec");
    System.out.println("Speed Max           : " + (pruningSpeedSummary.getMax() / 1000) + " sec");
    System.out.println("Speed Mean          : " + (pruningSpeedSummary.getMean() / 1000) + " sec");

    System.out.println("\nMatching Speed Statistics");
    System.out.println("Speed Min           : " + (matchingSpeedSummary.getMin() / 1000) + " sec");
    System.out.println("Speed Max           : " + (matchingSpeedSummary.getMax() / 1000) + " sec");
    System.out.println("Speed Mean          : " + (matchingSpeedSummary.getMean() / 1000) + " sec");

    System.out.println("\nOverall Speed Statistics");
    System.out.println("Speed Min           : " + (totalSpeedSummary.getMin() / 1000) + " sec");
    System.out.println("Speed Max           : " + (totalSpeedSummary.getMax() / 1000) + " sec");
    System.out.println("Speed Mean          : " + (totalSpeedSummary.getMean() / 1000) + " sec");

}

From source file:com.userweave.module.methoden.rrt.page.report.MeanAndStdDeviation.java

public MeanAndStdDeviation(List<Double> values) {
    SummaryStatistics stats = new SummaryStatistics();
    for (Double value : values) {
        stats.addValue(value);
    }//from  w w  w  .  j  a v a 2 s  . c  o  m

    this.mean = stats.getMean();
    this.stdDeviation = stats.getStandardDeviation();
}

From source file:hmp.Read.java

private void addToHash(HashMap<String, SummaryStatistics> hash, String key, double value) {
    if (hash.containsKey(key)) {
        SummaryStatistics stat = hash.get(key);
        stat.addValue(value);
    } else {//from ww w  .  ja v a 2s  .  co  m
        SummaryStatistics stat = new SummaryStatistics();
        stat.addValue(value);
        hash.put(key, stat);
    }
}

From source file:de.escidoc.core.om.performance.Statistics.java

/**
 * @param key   the name of package.class.method
 * @param value the execution time of the method
 *//*from   ww w.  ja  v a  2  s  .  co  m*/
public void addValueToStatistics(final String key, final long value) {
    final SummaryStatistics statistics = getStatistics(key);
    statistics.addValue((double) value);
}

From source file:de.tudarmstadt.ukp.dkpro.core.decompounding.ranking.FrequencyGeometricMeanRanker.java

/**
 * Calculates the weight for a split/*from   www  . j a va 2s. c  o  m*/
 */
private double calcRank(DecompoundedWord aSplit) {
    SummaryStatistics stats = new SummaryStatistics();
    for (Fragment elem : aSplit.getSplits()) {
        stats.addValue(freq(elem).doubleValue());
    }
    return stats.getGeometricMean();
}

From source file:com.netflix.curator.x.discovery.TestStrategies.java

@Test
public void testRandom() throws Exception {
    final int QTY = 10;
    final int ITERATIONS = 1000;

    TestInstanceProvider instanceProvider = new TestInstanceProvider(QTY, 0);
    ProviderStrategy<Void> strategy = new RandomStrategy<Void>();

    long[] counts = new long[QTY];
    for (int i = 0; i < ITERATIONS; ++i) {
        ServiceInstance<Void> instance = strategy.getInstance(instanceProvider);
        int id = Integer.parseInt(instance.getId());
        counts[id]++;/*from   w w  w.j av a  2  s .  c o m*/
    }

    SummaryStatistics statistic = new SummaryStatistics();
    for (int i = 0; i < QTY; ++i) {
        statistic.addValue(counts[i]);
    }
    Assert.assertTrue(statistic.getStandardDeviation() <= (QTY * 2), "" + statistic.getStandardDeviation()); // meager check for even distribution
}

From source file:geogebra.kernel.AlgoNormalQuantilePlot.java

private GeoSegment getQQLineSegment() {

    SummaryStatistics stats = new SummaryStatistics();
    for (int i = 0; i < sortedData.length; i++) {
        stats.addValue(sortedData[i]);
    }/* w  w w  .j a va 2s  .co  m*/
    double sd = stats.getStandardDeviation();
    double mean = stats.getMean();
    double min = stats.getMin();
    double max = stats.getMax();

    // qq line: y = (1/sd)x - mean/sd 

    GeoPoint startPoint = new GeoPoint(cons);
    startPoint.setCoords(min, (min / sd) - mean / sd, 1.0);
    GeoPoint endPoint = new GeoPoint(cons);
    endPoint.setCoords(max, (max / sd) - mean / sd, 1.0);
    GeoSegment seg = new GeoSegment(cons, startPoint, endPoint);
    seg.calcLength();

    return seg;
}

From source file:geogebra.common.kernel.statistics.AlgoNormalQuantilePlot.java

private GeoSegment getQQLineSegment() {

    SummaryStatistics stats = new SummaryStatistics();
    for (int i = 0; i < sortedData.length; i++) {
        stats.addValue(sortedData[i]);
    }/* ww w  . j  av  a2s  .com*/
    double sd = stats.getStandardDeviation();
    double mean = stats.getMean();
    double min = stats.getMin();
    double max = stats.getMax();

    // qq line: y = (1/sd)x - mean/sd

    GeoPoint startPoint = new GeoPoint(cons);
    startPoint.setCoords(min, (min / sd) - mean / sd, 1.0);
    GeoPoint endPoint = new GeoPoint(cons);
    endPoint.setCoords(max, (max / sd) - mean / sd, 1.0);
    GeoSegment seg = new GeoSegment(cons, startPoint, endPoint);
    seg.calcLength();

    return seg;
}