List of usage examples for org.apache.commons.math.stat.descriptive DescriptiveStatistics getMean
public double getMean()
From source file:gov.nih.nci.caintegrator.analysis.messaging.DataPointVector.java
/** * Compute the mean of the values in the list * @param values/*w ww . j a v a2s .co m*/ * @return */ private Double computeMean(List<Double> values) { DescriptiveStatistics stats = DescriptiveStatistics.newInstance(); // Add the data from the array for (Double value : values) { stats.addValue(value); } double mean = stats.getMean(); return new Double(mean); }
From source file:com.userweave.module.methoden.iconunderstandability.service.ComputeIconTestStatisticsImpl.java
private void setMeanReactionTime(final OverallStatistics overallStatistics, int iconCount, IconTestReactionTimeStatistics statisticsEntity) { final DescriptiveStatistics statisticsForIconCount = overallStatistics.getIconCount2Statistics() .get(new Integer(iconCount)); if (statisticsForIconCount != null) { statisticsEntity.setMeanReactionTime(statisticsForIconCount.getMean()); } else {// ww w . j av a 2 s . c o m statisticsEntity.setMeanReactionTime(-1); } }
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); }//from w w w. j a v a2 s .com 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>()); }// ww w . ja va2s . c o m 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:com.google.caliper.runner.ConsoleResultProcessor.java
@Override public void processTrial(Trial trial) { ImmutableListMultimap<String, Measurement> measurementsIndex = new ImmutableListMultimap.Builder<String, Measurement>() .orderKeysBy(Ordering.natural()) .putAll(Multimaps.index(trial.measurements(), new Function<Measurement, String>() { @Override//from w ww . ja v a2 s . c om public String apply(Measurement input) { return input.description(); } })).build(); for (Entry<String, Collection<Measurement>> entry : measurementsIndex.asMap().entrySet()) { Collection<Measurement> measurements = entry.getValue(); ImmutableSet<String> units = FluentIterable.from(measurements) .transform(new Function<Measurement, String>() { @Override public String apply(Measurement input) { return input.value().unit(); } }).toSet(); double[] weightedValues = new double[measurements.size()]; int i = 0; for (Measurement measurement : measurements) { weightedValues[i] = measurement.value().magnitude() / measurement.weight(); i++; } Percentile percentile = new Percentile(); percentile.setData(weightedValues); DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(weightedValues); String unit = Iterables.getOnlyElement(units); stdout.printf(" %s%s: min=%.2f, 1st qu.=%.2f, median=%.2f, mean=%.2f, 3rd qu.=%.2f, max=%.2f%n", entry.getKey(), unit.isEmpty() ? "" : "(" + unit + ")", descriptiveStatistics.getMin(), percentile.evaluate(25), percentile.evaluate(50), descriptiveStatistics.getMean(), percentile.evaluate(75), descriptiveStatistics.getMax()); } instrumentSpecs.add(trial.instrumentSpec()); Scenario scenario = trial.scenario(); vmSpecs.add(scenario.vmSpec()); benchmarkSpecs.add(scenario.benchmarkSpec()); numMeasurements += trial.measurements().size(); }
From source file:com.google.caliper.runner.ConsoleOutput.java
/** * Prints a summary of a successful trial result. *///from w w w .j av a 2s. c o m void processTrial(TrialResult result) { trialsCompleted++; stdout.printf("Trial Report (%d of %d):%n Experiment %s%n", trialsCompleted, numberOfTrials, result.getExperiment()); if (!result.getTrialMessages().isEmpty()) { stdout.println(" Messages:"); for (String message : result.getTrialMessages()) { stdout.print(" "); stdout.println(message); } } Trial trial = result.getTrial(); ImmutableListMultimap<String, Measurement> measurementsIndex = new ImmutableListMultimap.Builder<String, Measurement>() .orderKeysBy(Ordering.natural()) .putAll(Multimaps.index(trial.measurements(), new Function<Measurement, String>() { @Override public String apply(Measurement input) { return input.description(); } })).build(); stdout.println(" Results:"); for (Entry<String, Collection<Measurement>> entry : measurementsIndex.asMap().entrySet()) { Collection<Measurement> measurements = entry.getValue(); ImmutableSet<String> units = FluentIterable.from(measurements) .transform(new Function<Measurement, String>() { @Override public String apply(Measurement input) { return input.value().unit(); } }).toSet(); double[] weightedValues = new double[measurements.size()]; int i = 0; for (Measurement measurement : measurements) { weightedValues[i] = measurement.value().magnitude() / measurement.weight(); i++; } Percentile percentile = new Percentile(); percentile.setData(weightedValues); DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(weightedValues); String unit = Iterables.getOnlyElement(units); stdout.printf(" %s%s: min=%.2f, 1st qu.=%.2f, median=%.2f, mean=%.2f, 3rd qu.=%.2f, max=%.2f%n", entry.getKey(), unit.isEmpty() ? "" : "(" + unit + ")", descriptiveStatistics.getMin(), percentile.evaluate(25), percentile.evaluate(50), descriptiveStatistics.getMean(), percentile.evaluate(75), descriptiveStatistics.getMax()); } instrumentSpecs.add(trial.instrumentSpec()); Scenario scenario = trial.scenario(); vmSpecs.add(scenario.vmSpec()); benchmarkSpecs.add(scenario.benchmarkSpec()); numMeasurements += trial.measurements().size(); }
From source file:dk.ilios.spanner.internal.ConsoleOutput.java
/** * Prints a summary of a successful trial result. *//*from ww w . j a v a2 s .c om*/ void processTrial(Trial.Result result) { Trial baseline = result.getExperiment().getBaseline(); trialsCompleted++; stdout.printf("Trial Report (%d of %d):%n Experiment %s%n", trialsCompleted, numberOfTrials, result.getExperiment()); if (!result.getTrialMessages().isEmpty()) { stdout.println(" Messages:"); for (String message : result.getTrialMessages()) { stdout.print(" "); stdout.println(message); } } Trial trial = result.getTrial(); // Group measurements by their description // TODO Why? All measurements for a single trial should have the same description ImmutableListMultimap<String, Measurement> measurementsIndex = new ImmutableListMultimap.Builder<String, Measurement>() .orderKeysBy(Ordering.natural()) .putAll(Multimaps.index(trial.measurements(), new Function<Measurement, String>() { @Override public String apply(Measurement input) { return input.description(); } })).build(); stdout.println(" Results:"); for (Map.Entry<String, Collection<Measurement>> entry : measurementsIndex.asMap().entrySet()) { Collection<Measurement> measurements = entry.getValue(); String unit = measurements.iterator().next().value().unit(); double[] weightedValues = new double[measurements.size()]; int i = 0; for (Measurement measurement : measurements) { weightedValues[i] = measurement.value().magnitude() / measurement.weight(); i++; } Percentile percentile = new Percentile(); percentile.setData(weightedValues); DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(weightedValues); stdout.printf(" %s%s: min=%.2f, 1st qu.=%.2f, median=%.2f (%s), mean=%.2f, 3rd qu.=%.2f, max=%.2f%n", entry.getKey(), unit.isEmpty() ? "" : "(" + unit + ")", descriptiveStatistics.getMin(), percentile.evaluate(25), percentile.evaluate(50), calculateDiff(percentile.evaluate(50), baseline), descriptiveStatistics.getMean(), percentile.evaluate(75), descriptiveStatistics.getMax()); } instrumentSpecs.add(trial.instrumentSpec()); Scenario scenario = trial.scenario(); benchmarkSpecs.add(scenario.benchmarkSpec()); numMeasurements += trial.measurements().size(); }
From source file:com.gtwm.pb.model.manageData.WordCloud.java
/** * @param textLowerCase//from w w w. j a v a 2 s .com * Input text, must be lower case * @param minWeight * Minimum tag weight, e.g. a font size * @param maxWeight * Max. tag weight * @param maxTags * Maximum number of tags to return, -1 for all tags * @param additionalStopWords * Set of words to specifically exclude, in addition to the * standard set [and, not, after, yes, no, ...] */ public WordCloud(String textLowerCase, int minWeight, int maxWeight, int maxTags, Set<String> additionalStopWords) { String[] wordArray = textLowerCase.split("\\W"); Set<String> stopWords = new HashSet<String>(Arrays.asList(stopWordsArray)); for (String additionalStopWord : additionalStopWords) { stopWords.add(additionalStopWord.toLowerCase().trim()); } LancasterStemmer stemmer = new LancasterStemmer(); String wordStem; Frequency frequencies = new Frequency(); for (String wordString : wordArray) { if ((!stopWords.contains(wordString)) && (wordString.length() >= minWordLength)) { wordStem = stemmer.stripSuffixes(wordString); // Record the mapping of the stem to its origin so the most // common origin can be re-introduced when the cloud is // generated this.recordStemOrigin(wordString, wordStem); frequencies.addValue(wordStem); } } // Compute std. dev of frequencies so we can remove outliers DescriptiveStatistics stats = new DescriptiveStatistics(); Iterator freqIt = frequencies.valuesIterator(); long stemFreq; while (freqIt.hasNext()) { stemFreq = frequencies.getCount(freqIt.next()); stats.addValue(stemFreq); } double mean = stats.getMean(); double stdDev = stats.getStandardDeviation(); long minFreq = Long.MAX_VALUE; long maxFreq = 0; // Remove outliers freqIt = frequencies.valuesIterator(); int upperLimit = (int) (mean + (stdDev * 10)); int lowerLimit = (int) (mean - stdDev); if (lowerLimit < 2) { lowerLimit = 2; } int numWords = 0; int numRawWords = wordArray.length; boolean removeLowOutliers = (numRawWords > (maxTags * 10)); while (freqIt.hasNext()) { wordStem = (String) freqIt.next(); stemFreq = frequencies.getCount(wordStem); // For a large input set, remove high and low outliers. // For a smaller set, just high freq. outliers if ((stemFreq > upperLimit) || ((stemFreq < lowerLimit) && removeLowOutliers)) { freqIt.remove(); } else { numWords++; if (stemFreq > maxFreq) { maxFreq = stemFreq; } else if (stemFreq < minFreq) { minFreq = stemFreq; } } } // Cut down to exact required number of tags by removing smallest if (lowerLimit < minFreq) { lowerLimit = (int) minFreq; } if (numWords > maxTags) { while (numWords > maxTags) { freqIt = frequencies.valuesIterator(); SMALLREMOVAL: while (freqIt.hasNext()) { stemFreq = frequencies.getCount(freqIt.next()); if (stemFreq < lowerLimit) { freqIt.remove(); numWords--; if (numWords == maxTags) { break SMALLREMOVAL; } } } int step = (int) ((mean - lowerLimit) / 3); if (step < 1) { step = 1; } lowerLimit += step; } // The new min. freq. may have changed minFreq = Long.MAX_VALUE; freqIt = frequencies.valuesIterator(); while (freqIt.hasNext()) { stemFreq = frequencies.getCount(freqIt.next()); if (stemFreq < minFreq) { minFreq = stemFreq; } } } // Scale and create tag objects double scaleFactor; if (maxFreq == minFreq) { scaleFactor = (double) (maxWeight - minWeight) / 4; // TODO: a realistic // scale factor in this // case } else { scaleFactor = (double) (maxWeight - minWeight) / (maxFreq - minFreq); } freqIt = frequencies.valuesIterator(); int weight; while (freqIt.hasNext()) { wordStem = (String) freqIt.next(); stemFreq = frequencies.getCount(wordStem); // Might still be some left less than the min. threshold if (stemFreq <= minFreq) { weight = minWeight; } else { weight = (int) (Math.ceil((double) (stemFreq - minFreq) * scaleFactor) + minWeight); } SortedSet<WordInfo> origins = this.stemOriginMap.get(wordStem); String mostCommonOrigin = origins.last().getName(); Set<String> synonyms = new TreeSet<String>(); for (WordInfo origin : origins) { synonyms.add(origin.getName()); } WordInfo word = new Word(mostCommonOrigin, weight, synonyms); this.words.add(word); } }
From source file:guineu.modules.filter.Alignment.centering.mean.MeanCenteringTask.java
private void normalize(Dataset data) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (String nameExperiment : data.getAllColumnNames()) { for (PeakListRow row : data.getRows()) { Object value = row.getPeak(nameExperiment); if (value != null && value instanceof Double) { stats.addValue((Double) value); }// w w w . j av a 2s . com } for (PeakListRow row : data.getRows()) { Object value = row.getPeak(nameExperiment); if (value != null && value instanceof Double) { row.setPeak(nameExperiment, Math.abs((Double) value - stats.getMean())); } } stats.clear(); } }
From source file:guineu.modules.dataanalysis.variationCoefficient.VariationCoefficientTask.java
private double getvariationCoefficient(Dataset dataset) { DescriptiveStatistics superStats = new DescriptiveStatistics(); DescriptiveStatistics stats = new DescriptiveStatistics(); for (PeakListRow row : dataset.getRows()) { stats.clear();/*from w w w .j a va2 s . c o m*/ for (String experimentName : dataset.getAllColumnNames()) { Object value = row.getPeak(experimentName); if (value != null && value instanceof Double) { stats.addValue((Double) value); } else { try { stats.addValue(Double.valueOf((String) value)); } catch (Exception e) { } } } if (stats.getMean() > 0) { double value = stats.getStandardDeviation() / stats.getMean(); superStats.addValue(value); } } return superStats.getMean(); }