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

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

Introduction

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

Prototype

public double getVariance() 

Source Link

Document

Returns the (sample) variance of the available values.

Usage

From source file:performancestatisticsasset.DistributionSet.java

public void setDistributionSet(String targetTask, String targetMeasure, RecordList dataSet) {
    //Determine the number of trials selected by task
    int trials = 0;
    int len = dataSet.records.size();
    for (int i = 0; i < len; i++) {
        if (dataSet.records.get(i).getTrialNumber() > trials)
            trials = dataSet.records.get(i).getTrialNumber();
    }//from  ww w.j  a v a2s.c  o m

    Distribution tempDist;
    DescriptiveStatistics tempStat;
    //For each trial of the set do
    for (int i = 0; i < trials; i++) {
        tempDist = new Distribution();
        tempStat = new DescriptiveStatistics();
        //Select data
        for (int j = 0; j < len; j++) {
            //If the current record is of the correct trial
            if ((dataSet.records.get(j).getTrialNumber() == i + 1)
                    && (targetTask.equals(dataSet.records.get(j).getTaskID()))) {
                //Fill distribution
                switch (targetMeasure) {
                case "time":
                    tempStat.addValue(dataSet.records.get(j).getTimeToComplete());
                    break;
                case "perf":
                    tempStat.addValue(dataSet.records.get(j).getPerformance());
                    break;
                }
            }
        }
        //Transfer the computed statistics to tempDist
        tempDist.max = tempStat.getMax();
        tempDist.min = tempStat.getMin();
        tempDist.sum = tempStat.getSum();
        tempDist.variance = tempStat.getVariance();
        tempDist.mean = tempStat.getMean();
        tempDist.stdDev = tempStat.getStandardDeviation();
        tempDist.skewness = tempStat.getSkewness();
        tempDist.kurtosis = tempStat.getKurtosis();
        tempDist.n = tempStat.getN();

        //Add tempDist to distributionSet
        distributionSet.add(tempDist);
    }
}