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

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

Introduction

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

Prototype

public double getStandardDeviation() 

Source Link

Document

Returns the standard deviation of the available values.

Usage

From source file:edu.usc.ee599.CommunityStats.java

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

    File dir = new File("results5");
    PrintWriter writer = new PrintWriter(new FileWriter("results5_stats.txt"));

    File[] files = dir.listFiles();

    DescriptiveStatistics statistics1 = new DescriptiveStatistics();
    DescriptiveStatistics statistics2 = new DescriptiveStatistics();
    for (File file : files) {

        BufferedReader reader = new BufferedReader(new FileReader(file));

        String line1 = reader.readLine();
        String line2 = reader.readLine();

        int balanced = Integer.parseInt(line1.split(",")[1]);
        int unbalanced = Integer.parseInt(line2.split(",")[1]);

        double bp = (double) balanced / (double) (balanced + unbalanced);
        double up = (double) unbalanced / (double) (balanced + unbalanced);

        statistics1.addValue(bp);/*from w w w.j  a  va 2s.com*/
        statistics2.addValue(up);

    }

    writer.println("AVG Balanced %: " + statistics1.getMean());
    writer.println("AVG Unbalanced %: " + statistics2.getMean());

    writer.println("STD Balanced %: " + statistics1.getStandardDeviation());
    writer.println("STD Unbalanced %: " + statistics2.getStandardDeviation());

    writer.flush();
    writer.close();

}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

public static void statistics3(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats3.csv")));
    pw.println("qID\tagreementMean\tagreementStdDev\tqueryText");

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        DescriptiveStatistics statistics = new DescriptiveStatistics();

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {
            Double observedAgreement = rankedResult.observedAgreement;

            if (observedAgreement != null) {
                statistics.addValue(observedAgreement);
            }/*from   www.j a  va  2  s. co  m*/
        }

        pw.printf(Locale.ENGLISH, "%s\t%.3f\t%.3f\t%s%n", queryResultContainer.qID, statistics.getMean(),
                statistics.getStandardDeviation(), queryResultContainer.query);
    }

    pw.close();
}

From source file:dr.evomodel.epidemiology.casetocase.periodpriors.OneOverStDevPeriodPriorDistribution.java

public double calculateLogLikelihood(double[] values) {

    DescriptiveStatistics stats = new DescriptiveStatistics(values);

    logL = -Math.log(stats.getStandardDeviation());

    return logL;/*w  ww  . java 2  s . c om*/

}

From source file:guineu.modules.dataanalysis.variationCoefficientRow.variationCoefficientRowFilterTask.java

public double CoefficientOfVariation(PeakListRow row) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (Object peak : row.getPeaks(null)) {
        if (peak != null) {
            stats.addValue((Double) peak);
        }//from   ww  w .ja va2s .  c  o  m
    }
    return stats.getStandardDeviation() / stats.getMean();
}

From source file:juicebox.tools.utils.juicer.apa.APARegionStatistics.java

public APARegionStatistics(RealMatrix data) {
    int max = data.getColumnDimension();
    int midPoint = max / 2;
    double centralVal = data.getEntry(midPoint, midPoint);

    int regionWidth = APA.regionWidth;

    /** NOTE - indices are inclusive in java, but in python the second index is not inclusive */

    peak2mean = centralVal / ((sum(data.getData()) - centralVal) / (data.getColumnDimension() - 1));

    double avgUL = mean(data.getSubMatrix(0, regionWidth - 1, 0, regionWidth - 1).getData());
    peak2UL = centralVal / avgUL;/*  w  ww  .  j  av  a 2s .co m*/

    double avgUR = mean(data.getSubMatrix(0, regionWidth - 1, max - regionWidth, max - 1).getData());
    peak2UR = centralVal / avgUR;

    double avgLL = mean(data.getSubMatrix(max - regionWidth, max - 1, 0, regionWidth - 1).getData());
    peak2LL = centralVal / avgLL;

    double avgLR = mean(data.getSubMatrix(max - regionWidth, max - 1, max - regionWidth, max - 1).getData());
    peak2LR = centralVal / avgLR;

    DescriptiveStatistics yStats = statistics(
            data.getSubMatrix(max - regionWidth, max - 1, 0, regionWidth - 1).getData());
    ZscoreLL = (centralVal - yStats.getMean()) / yStats.getStandardDeviation();
}

From source file:com.graphhopper.jsprit.analysis.toolbox.ConcurrentBenchmarker.java

private String getString(DescriptiveStatistics stats) {
    return "[best=" + round(stats.getMin(), 2) + "][avg=" + round(stats.getMean(), 2) + "][worst="
            + round(stats.getMax(), 2) + "][stdDev=" + round(stats.getStandardDeviation(), 2) + "]";
}

From source file:de.unidue.langtech.teaching.rp.uimatools.Stopwatch.java

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    super.collectionProcessComplete();

    if (isDownstreamTimer()) {
        getLogger().info("Results from Timer '" + timerName + "' after processing all documents.");

        DescriptiveStatistics statTimes = new DescriptiveStatistics();
        for (Long timeValue : times) {
            statTimes.addValue((double) timeValue / 1000);
        }/* ww  w . ja  v a 2 s  . c om*/
        double sum = statTimes.getSum();
        double mean = statTimes.getMean();
        double stddev = statTimes.getStandardDeviation();

        StringBuilder sb = new StringBuilder();
        sb.append("Estimate after processing " + times.size() + " documents.");
        sb.append("\n");

        Formatter formatter = new Formatter(sb, Locale.US);

        formatter.format("Aggregated time: %,.1fs\n", sum);
        formatter.format("Time / Document: %,.3fs (%,.3fs)\n", mean, stddev);

        formatter.close();

        getLogger().info(sb.toString());

        if (outputFile != null) {
            try {
                Properties props = new Properties();
                props.setProperty(KEY_SUM, "" + sum);
                props.setProperty(KEY_MEAN, "" + mean);
                props.setProperty(KEY_STDDEV, "" + stddev);
                OutputStream out = new FileOutputStream(outputFile);
                props.store(out, "timer " + timerName + " result file");
            } catch (FileNotFoundException e) {
                throw new AnalysisEngineProcessException(e);
            } catch (IOException e) {
                throw new AnalysisEngineProcessException(e);
            }
        }
    }
}

From source file:info.raack.appliancelabeler.machinelearning.appliancedetection.algorithms.HighConfidenceFSMPowerSpikeDetectionAlgorithm.java

private Map<Integer, Integer[]> computeTrainingInstanceSpikeLimits(
        List<double[]> trainingInstancesWithClassLabels) {
    Map<Integer, List<Double>> trainingSpikes = new HashMap<Integer, List<Double>>();

    // collect all spikes for each class
    for (double[] instance : trainingInstancesWithClassLabels) {
        double clazz = instance[instance.length - 1];
        if (clazz != missingValue) {
            double trainingSpike = instance[0];

            if (!trainingSpikes.containsKey((int) clazz)) {
                trainingSpikes.put((int) clazz, new ArrayList<Double>());
            }//from ww  w . j a v a  2s. c  om
            trainingSpikes.get((int) clazz).add(trainingSpike);
        }
    }

    Map<Integer, Integer[]> trainingInstanceLimits = new HashMap<Integer, Integer[]>();

    // calculate interval one standard deviation away from mean of labeled power spikes for each class
    for (Integer clazz : trainingSpikes.keySet()) {
        DescriptiveStatistics stats = new DescriptiveStatistics();
        for (Double spikeValue : trainingSpikes.get(clazz)) {
            stats.addValue(spikeValue);
        }
        trainingInstanceLimits.put(clazz,
                new Integer[] { (int) (stats.getMean() - stats.getStandardDeviation()),
                        (int) (stats.getMean() + stats.getStandardDeviation()) });
    }

    return trainingInstanceLimits;
}

From source file:gov.nih.nci.caintegrator.analysis.messaging.DataPointVector.java

private Double computeStdDeviation(List<Double> values) {
    DescriptiveStatistics stats = DescriptiveStatistics.newInstance();

    //       Add the data from the array
    for (Double value : values) {
        stats.addValue(value);//w w  w . jav  a 2s  .  com
    }

    //       Compute some statistics 
    //double mean = stats.getMean();
    //      double median = stats.getMedian();
    double std = stats.getStandardDeviation();
    return new Double(std);

}

From source file:com.netxforge.netxstudio.common.math.NativeFunctions.java

public double standardDeviation(double[] range) {
    assert range != null : new MathException("Range can't be empty");
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the array
    for (int i = 0; i < range.length; i++) {
        stats.addValue(range[i]);/*from ww  w.  j  a  v a2 s .com*/
    }
    return stats.getStandardDeviation();
}