public static void main(String[] args) { SummaryStatistics statObject = new SummaryStatistics(); SummaryStatistics statByte = new SummaryStatistics(); for (int i = 0; i < 10; i++) { statByte.addValue(testByte()); statObject.addValue(testObject()); } System.out.println("Time (ms) Object: " + statObject.getMean() + " | " + statObject.getStandardDeviation()); System.out.println("Time (ms) Byte: " + statByte.getMean() + " | " + statByte.getStandardDeviation()); }
/** * Returns true iff <code>object</code> is a * <code>SummaryStatistics</code> instance and all statistics have the * same values as this. * @param object the object to test equality against. * @return true if object equals this */ @Override public boolean equals(Object object) { if (object == this) { return true; } if (object instanceof SummaryStatistics == false) { return false; } SummaryStatistics stat = (SummaryStatistics)object; return MathUtils.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) && MathUtils.equalsIncludingNaN(stat.getMax(), getMax()) && MathUtils.equalsIncludingNaN(stat.getMean(), getMean()) && MathUtils.equalsIncludingNaN(stat.getMin(), getMin()) && MathUtils.equalsIncludingNaN(stat.getN(), getN()) && MathUtils.equalsIncludingNaN(stat.getSum(), getSum()) && MathUtils.equalsIncludingNaN(stat.getSumsq(), getSumsq()) && MathUtils.equalsIncludingNaN(stat.getVariance(), getVariance()); }
/** * Generates a text report displaying * summary statistics from values that * have been added. * @return String with line feeds displaying statistics * @since 1.2 */ public String toString() { StringBuffer outBuffer = new StringBuffer(); outBuffer.append("SummaryStatistics:\n"); outBuffer.append("n: " + getN() + "\n"); outBuffer.append("min: " + getMin() + "\n"); outBuffer.append("max: " + getMax() + "\n"); outBuffer.append("mean: " + getMean() + "\n"); outBuffer.append("geometric mean: " + getGeometricMean() + "\n"); outBuffer.append("variance: " + getVariance() + "\n"); outBuffer.append("sum of squares: " + getSumsq() + "\n"); outBuffer.append("standard deviation: " + getStandardDeviation() + "\n"); outBuffer.append("sum of logs: " + getSumOfLogs() + "\n"); return outBuffer.toString(); }
/** {@inheritDoc} */ @Override public void computeStats() throws IOException { sampleStats = new SummaryStatistics(); for (int i = 0; i < inputArray.length; i++) { sampleStats.addValue(inputArray[i]); } }
try { SummaryStatistics s = _statistics.get(_columns[i]); double lowestValue = s.getMin(); double highestValue = s.getMax(); MatrixValue[] matrixValues = mb.addColumn( _columns[i].getName(), nf.valueToString(highestValue), nf.valueToString(lowestValue), nf.valueToString(s .getSum()), nf.valueToString(s.getMean()), nf .valueToString(s.getGeometricMean()), nf .valueToString(s.getStandardDeviation()), nf .valueToString(s.getVariance()));
public String toString() { if (cachedStringRepresentation == null) { try { cachedStringRepresentation = "Min: " + (int) stats.getMin() + ", mean: " + (int) stats.getMean() + ", max: " + (int) stats.getMax() + ", stddev: " + (int) stats.getStandardDeviation() + ", score: " + (int) getScore(); } catch (IOException e) { throw new RuntimeException(e); } } return cachedStringRepresentation; } }
long n = current.getN(); double min = current.getMin(); double sum = current.getSum(); double max = current.getMax(); double m2 = current.getSecondMoment(); double mean = current.getMean(); while (iterator.hasNext()) { current = iterator.next(); if (current.getMin() < min || Double.isNaN(min)) { min = current.getMin(); if (current.getMax() > max || Double.isNaN(max)) { max = current.getMax(); sum += current.getSum(); final double oldN = n; final double curN = current.getN(); n += curN; final double meanDiff = current.getMean() - mean; mean = sum / n; m2 = m2 + current.getSecondMoment() + meanDiff * meanDiff * oldN * curN / n;
@Override public boolean calculate() { if (System.currentTimeMillis() > nextRecord) { ValueStat v = new ValueStat(); v.setKey(key); if (workingValues.isEmpty()) { v.setValue(0.0); } else { SummaryStatistics summary = new SummaryStatistics(); synchronized (workingValues) { for (ValueStat vs : workingValues) { summary.addValue(vs.getValue()); } } switch (operation) { case AVERAGE: v.setValue(summary.getMean()); break; case SUM: v.setValue(summary.getSum()); break; } } history.add(v); nextRecord = nextExtractionTime(); return true; } return false; }
/** * Pretty print a time * @param ss the stats defining the time * @return a string representing the time */ public static String format(SummaryStatistics ss) { if (ss.getN() == 1) { return formatTime(ss.getMean()); } return formatTime(ss.getMean(), ss.getStandardDeviation()); }
double getScore() throws IOException { return Math.max(1, stats.getMean() * stats.getMean() - stats.getStandardDeviation() * stats.getStandardDeviation()); }
/** * {@inheritDoc} */ @Override public synchronized double getStandardDeviation() { return super.getStandardDeviation(); }
/** * Initializes a new AggregateSummaryStatistics with default statistics * implementations. * */ public AggregateSummaryStatistics() { this(new SummaryStatistics()); }
/** * {@inheritDoc}. This version returns the minimum over all the aggregated * data. * * @see StatisticalSummary#getMin() */ public double getMin() { synchronized (statistics) { return statistics.getMin(); } }
/** * {@inheritDoc} */ @Override public synchronized double getMean() { return super.getMean(); }
/** * Returns a copy of this SummaryStatistics instance with the same internal state. * * @return a copy of this */ public SummaryStatistics copy() { SummaryStatistics result = new SummaryStatistics(); copy(this, result); return result; }
/** * @return the colourfulness value from the last image analysed */ public double getColorfulness() { final double var_rg = rgStats.getVariance(); final double var_yb = ybStats.getVariance(); final double mean_rg = rgStats.getMean(); final double mean_yb = ybStats.getMean(); final double stddev = Math.sqrt(var_rg + var_yb); final double mean = Math.sqrt(mean_rg * mean_rg + mean_yb * mean_yb); return stddev + 0.3 * mean; }
} else { final SummaryStatistics summaryStats = (SummaryStatistics) s; geometricMean = summaryStats.getGeometricMean(); secondMoment = summaryStats.getSecondMoment(); sumOfSquares = summaryStats.getSumsq();