List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getStandardDeviation
public double getStandardDeviation()
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 www.j a va 2 s. c om*/ 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); } }
From source file:Pooling.collectStatsTime.java
public static void main(String[] args) throws IOException { /* int maxN = 1000; double[] prob = {0.25,0.5,0.75,1.00}; int[] maxPoolSize = {35};//from ww w .j a v a 2 s .c om int nTests = 50; String folder = "randGraphsSimRes"; for (int t = 0; t < maxPoolSize.length; t++) { FileWriter fw = new FileWriter(folder + File.separator + "statsDesignTime" + maxPoolSize[t] + ".txt"); for (int n = 10; n <= maxN; n+=10) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 1; i <= nTests; i++) { String resfile = "testResults_" + n + "_" + maxPoolSize[t] + "_" + i + ".txt"; BufferedReader br = new BufferedReader(new FileReader(folder + File.separator + resfile)); System.out.println(resfile); String s = br.readLine(); StringTokenizer st = new StringTokenizer(s," "); st.nextToken(); int k = Integer.parseInt(st.nextToken()); stats.addValue(((double)k)/1000); } fw.write(n + " " + stats.getMean() + " " + (stats.getStandardDeviation()/Math.sqrt(nTests)) + "\n"); } fw.close(); } */ int[] ns = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150 }; int[] maxPoolSizes = { 15, 25, 35 }; int nTests = 10; for (int sz = 0; sz < maxPoolSizes.length; sz++) { FileWriter fw = new FileWriter("statisticsTime_" + maxPoolSizes[sz] + ".txt"); for (int in = 0; in < ns.length; in++) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int it = 0; it < nTests; it++) { String outdir = "Test_" + maxPoolSizes[sz] + "_" + ns[in] + "_" + it; String repFile = outdir + File.separator + "report.txt"; System.out.println(outdir); BufferedReader br = new BufferedReader(new FileReader(repFile)); String s = ""; for (int i = 0; i < 6; i++) s = br.readLine(); StringTokenizer st = new StringTokenizer(s, ":"); st.nextToken(); double tm = Double.parseDouble(st.nextToken()); stats.addValue(tm); } double maxtime = stats.getMax(); DescriptiveStatistics stats1 = new DescriptiveStatistics(); for (int i = 0; i < nTests; i++) if (stats.getElement(i) != maxtime) stats1.addValue(stats.getElement(i)); fw.write(ns[in] + " " + stats1.getMean() + " " + (stats1.getStandardDeviation() / Math.sqrt((nTests - 1))) + "\n"); } fw.close(); } }
From source file:reflex.module.ReflexStatistics.java
public ReflexValue statistics(List<ReflexValue> params) { if (params.size() != 1) { throw new ReflexException(-1, "statistics needs one list parameter"); }/*from w w w .j a v a2 s.c o m*/ if (!params.get(0).isList()) { throw new ReflexException(-1, "statistics needs one list parameter"); } DescriptiveStatistics stats = new DescriptiveStatistics(); List<ReflexValue> values = params.get(0).asList(); for (ReflexValue v : values) { stats.addValue(v.asDouble()); } Map<String, ReflexValue> ret = new HashMap<String, ReflexValue>(); ret.put("mean", new ReflexValue(stats.getMean())); ret.put("std", new ReflexValue(stats.getStandardDeviation())); ret.put("median", new ReflexValue(stats.getPercentile(50))); return new ReflexValue(ret); }
From source file:saffranexperiment.Main.java
/** * @param simulationData A 5D {@link java.util.Arrays Array} with the * following structure://from w w w . j a v a 2 s. c om * * <ul> * <li>First dimension: participant types</li> * <li>Second dimension: repeats</li> * <li>Third dimension: experiments</li> * <li>Fourth dimension: participants</li> * <li>Fifth dimension:</li> * <ol type="1"> * <li>Familiar word 1 presentation time</li> * <li>Familiar word 2 presentation time</li> * <li>Novel word 1 presentation time</li> * <li>Novel word 2 presentation time</li> * </ol> * </ul> * * For example, simulationData[7][8][1][17][2] should return the presentation * time for the first novel word achieved by participant 18 in the 9th repeat * of experiment 2 when participant type is set to 8. * * @return A 4D {@link java.util.Arrays Array} with the following structure: * * <ul> * <li>First dimension: participant types</li> * <li>Second dimension: repeats</li> * <li>Third dimension: experiments</li> * <li>Fourth dimension:</li> * <ol type="1"> * <li>Familiar word presentation time mean</li> * <li>Familiar word presentation time standard deviation</li> * <li>Novel word presentation time mean</li> * <li>Novel word presentation time standard deviation</li> * <li>t value for familiar/novel word presentation time means</li> * <li>p value for familiar/novel word presentation time means</li> * </ol> * </ul> * * For example, assigning the result to a variable j and invoking * j[5][3][1][4] would return the t-value associated with the second * experiment of the fourth repeat for participant type 6. */ private static double[][][][] calculateMeanSdTAndPValuesForEachExperimentRepeat( double[][][][][] simulationData) { double[][][][] values = new double[_totalParticipantTypes][_totalRepeats][2][6]; for (int participantType = 0; participantType < _totalParticipantTypes; participantType++) { for (int repeat = 0; repeat < _totalRepeats; repeat++) { for (int experiment = 0; experiment < 2; experiment++) { List<Double> familWordPresentationTimes = new ArrayList(); List<Double> novelWordPresentationTimes = new ArrayList(); for (int participant = 0; participant < _totalParticipants; participant++) { familWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][0]); familWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][1]); novelWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][2]); novelWordPresentationTimes .add(simulationData[participantType][repeat][experiment][participant][3]); } //Calculate familiar word presentation time mean for experiment. DescriptiveStatistics familWordDescStat = new DescriptiveStatistics(); familWordPresentationTimes.forEach((value) -> familWordDescStat.addValue(value)); values[participantType][repeat][experiment][0] = familWordDescStat.getMean(); values[participantType][repeat][experiment][1] = familWordDescStat.getStandardDeviation(); //Calculate novel word presentation time mean for experiment. DescriptiveStatistics novelWordDescStat = new DescriptiveStatistics(); novelWordPresentationTimes.forEach((value) -> novelWordDescStat.addValue(value)); values[participantType][repeat][experiment][2] = novelWordDescStat.getMean(); values[participantType][repeat][experiment][3] = novelWordDescStat.getStandardDeviation(); //Convert lists containing familiar and novel presentation times to //arrays so we can use the Apache stats library functions for //calculating t and p values. double[] familWordPresentationTimesArr = convertDoubleListToDoubleArray( familWordPresentationTimes); double[] novelWordPresentationTimesArr = convertDoubleListToDoubleArray( novelWordPresentationTimes); //Calculate t value between familiar and novel word presentation times. values[participantType][repeat][0][4] = Math .abs(TestUtils.pairedT(familWordPresentationTimesArr, novelWordPresentationTimesArr)); //Calculate p value between familiar and novel word presentation times. values[participantType][repeat][0][5] = TestUtils.pairedTTest(familWordPresentationTimesArr, novelWordPresentationTimesArr); } } } return values; }
From source file:saffranexperiment.Main.java
/** * @param data A 4D {@link java.util.Arrays Array} with the following * structure (can be obtained from {@link * #calculateMeanSdTAndPValuesForEachExperimentRepeat(double[][][][][])}: * /* www.j a va2 s.c om*/ * <ul> * <li>First dimension: participant types</li> * <li>Second dimension: repeats</li> * <li>Third dimension: experiments</li> * <li>Fourth dimension:</li> * <ol type="1"> * <li>Familiar word presentation time mean</li> * <li>Familiar word presentation time standard deviation</li> * <li>Novel word presentation time mean</li> * <li>Novel word presentation time standard deviation</li> * <li>t value for familiar/novel word presentation time means</li> * <li>p value for familiar/novel word presentation time means</li> * </ol> * </ul> * * For example, invoking data[5][3][1][4] would return the t-value associated * with the second experiment of the fourth repeat for participant type 6. * * @return A 3D {@link java.util.Arrays Array}: * <ul> * <li>1st dimension: participant types</li> * <li>2nd dimension: experiments</li> * <li>3rd dimension</li> * <ol type="1"> * <li>Mean of familiar word presentation time repeat means</li> * <li>Standard error of familiar word presentation time repeat means</li> * <li>Mean of novel word presentation time repeat means</li> * <li>Standard error of novel word presentation time repeat means</li> * </ol> * </ul> * * For example, assigning the result to a variable j and invoking j[5][0][1] * would return the standard error of familiar word presentation time repeat * means associated with the repeats of experiment 1 for participant type 6. */ private static double[][][] calculateMeanAndStandardErrorOfMeanFamiliarAndNovelWordPresentationTimesForEachExperiment( double[][][][] data) { double[][][] participantTypeExperimentAverageFamiliarNovelValues = new double[_totalParticipantTypes][2][4]; for (int participantType = 0; participantType < _totalParticipantTypes; participantType++) { DescriptiveStatistics expt1FamiliarWordValues = new DescriptiveStatistics(); DescriptiveStatistics expt1NovelWordValues = new DescriptiveStatistics(); DescriptiveStatistics expt2FamiliarWordValues = new DescriptiveStatistics(); DescriptiveStatistics expt2NovelWordValues = new DescriptiveStatistics(); for (int repeat = 0; repeat < _totalRepeats; repeat++) { expt1FamiliarWordValues.addValue(data[participantType][repeat][0][0]); expt1NovelWordValues.addValue(data[participantType][repeat][0][2]); expt2FamiliarWordValues.addValue(data[participantType][repeat][1][0]); expt2NovelWordValues.addValue(data[participantType][repeat][1][2]); } participantTypeExperimentAverageFamiliarNovelValues[participantType][0][0] = expt1FamiliarWordValues .getMean(); participantTypeExperimentAverageFamiliarNovelValues[participantType][0][1] = expt1FamiliarWordValues .getStandardDeviation() / (Math.sqrt(_totalRepeats)); participantTypeExperimentAverageFamiliarNovelValues[participantType][0][2] = expt1NovelWordValues .getMean(); participantTypeExperimentAverageFamiliarNovelValues[participantType][0][3] = expt1NovelWordValues .getStandardDeviation() / (Math.sqrt(_totalRepeats)); participantTypeExperimentAverageFamiliarNovelValues[participantType][1][0] = expt2FamiliarWordValues .getMean(); participantTypeExperimentAverageFamiliarNovelValues[participantType][1][1] = expt2FamiliarWordValues .getStandardDeviation() / (Math.sqrt(_totalRepeats)); participantTypeExperimentAverageFamiliarNovelValues[participantType][1][2] = expt2NovelWordValues .getMean(); participantTypeExperimentAverageFamiliarNovelValues[participantType][1][3] = expt2NovelWordValues .getStandardDeviation() / (Math.sqrt(_totalRepeats)); } return participantTypeExperimentAverageFamiliarNovelValues; }
From source file:sax.data.transform.SaxRepresentationImpl.java
@Override public void doStatistics() { final DescriptiveStatistics stats = new DescriptiveStatistics(); final List<TimeSeriesEntry> entries = series.getSeries(); for (TimeSeriesEntry entry : entries) { double value = entry.getValue(); stats.addValue(value);/*w w w .j av a 2 s . c o m*/ } this.mean = stats.getMean(); this.standardDeviation = stats.getStandardDeviation(); System.out.printf("Mean: %s, sd: %s\n", mean, standardDeviation); }
From source file:streaming.core.WindowOperation.java
@Override public Object[][] process(Object[] event) { long day = (Long) event[0]; String word = (String) event[1]; long freqs = (Long) event[2]; TreeMap<Long, Long> sortedFreq = map.get(word); if (sortedFreq == null) { sortedFreq = new TreeMap<Long, Long>(); map.put(word, sortedFreq);/*from w w w . j a v a 2 s . c om*/ } Long t = sortedFreq.get(day); if (t != null) { freqs = freqs + t; } sortedFreq.put(day, freqs); Iterator<Entry<Long, Long>> iterator = sortedFreq.headMap(1 + day - numberOfDays).entrySet().iterator(); while (iterator.hasNext()) { iterator.next(); iterator.remove(); } DescriptiveStatistics stats = new DescriptiveStatistics(); long dayIndex = 1 + day - numberOfDays; for (Entry<Long, Long> e : sortedFreq.entrySet()) { while (e.getKey() > dayIndex) { dayIndex++; stats.addValue(0); } stats.addValue(e.getValue()); } if (sortedFreq.size() > numberOfDays) { System.out.println(day + " size=" + sortedFreq.size() + " " + sortedFreq); } double mean = stats.getMean(); double meadian = stats.getPercentile(50); mean = (mean == 0) ? 1 : mean; meadian = (meadian == 0) ? 1 : meadian; double stddev = stats.getStandardDeviation(); stddev = (stddev == 0) ? 1 : stddev; double cov = stddev / mean; //double swna = Math.log(freqs)*freqs/stats.getMean(); double swna1 = Math.log(meadian) * Math.abs(freqs - meadian) / stddev; if (Double.isNaN(swna1)) { System.out.println(); } double swna2 = Math.abs(freqs - meadian) / stddev; double swna3 = freqs / (meadian * cov); Gaussian gaussian = new Gaussian(100, 50); double swna4 = (0.1 + 100 * gaussian.value(meadian)) * freqs / (meadian * cov); int percentageAvialableValues = Math.round(100 * sortedFreq.size() / numberOfDays); //System.out.println("#"+ word + " " + freqs + " "+ stats.getMean() + Arrays.toString(stats.getValues())); return new Object[][] { { day, word, swna1, freqs, stats.getMean(), meadian, stddev, swna2, swna3, swna4, cov, percentageAvialableValues } }; // if(freqs > 3 && swna> 5){ // return new Object[][]{{day, word, swna}}; // }else{ // return null; // } }
From source file:tools.descartes.bungee.utils.DiffUtil.java
public static <T> Stats statisticsForDiffs(List<T> objects) { DescriptiveStatistics statistics = createDescriptiveStatistics(objects); Stats stats = new Stats(); // Compute some statistics stats.mean = statistics.getMean();// w w w. j a v a2 s .com stats.std = statistics.getStandardDeviation(); stats.max = Math.max(statistics.getMax(), -statistics.getMin()); return stats; }
From source file:tools.descartes.bungee.utils.DiffUtil.java
public static <T> StatsPercentile statisticsForDiffs(List<T> objects, double percent) { // Get a DescriptiveStatistics instance DescriptiveStatistics statistics = new DescriptiveStatistics(); // Add the data from the array for (T object : objects) { if (object instanceof Long) { statistics.addValue((Long) object); } else if (object instanceof Double) { statistics.addValue((Double) object); } else if (object instanceof AbstractResponse) { statistics.addValue(((AbstractResponse) object).getResponseTime()); }// w ww. j a v a2 s. c o m } StatsPercentile stats = new StatsPercentile(); // Compute some statistics stats.mean = statistics.getMean(); stats.std = statistics.getStandardDeviation(); stats.max = Math.max(statistics.getMax(), -statistics.getMin()); stats.percent = percent; stats.percentile = statistics.getPercentile(percent); return stats; }
From source file:tools.descartes.bungee.viewer.RunResultView.java
private void update() { if (runResult != null) { sanityCheckValue.setSelection(runResult.passedSanityCheck()); scheduleCheckValue.setSelection(runResult.passedScheduleCheck()); completedCheckValue.setSelection(runResult.isRunCompleted()); successCheckValue.setSelection(runResult.isRunSuccessful()); DescriptiveStatistics timingStats = runResult.getTimingStats(); if (timingStats.getN() > 0) { timingMeanValue.setText(String.format("%.3f", timingStats.getMean())); timingStdValue.setText(String.format("%.3f", timingStats.getStandardDeviation())); } else {/*from w w w. j ava2s . c om*/ timingMeanValue.setText("-"); timingStdValue.setText("-"); } DescriptiveStatistics responseStats = runResult.getResponseTimeStats(); if (responseStats.getN() > 0) { responseTimeMeanValue.setText(String.format("%.3f", responseStats.getMean())); responseTimeStdValue.setText(String.format("%.3f", responseStats.getStandardDeviation())); } else { responseTimeMeanValue.setText("-"); responseTimeStdValue.setText("-"); } } }