/** * {@inheritDoc} */ @Override public synchronized long getN() { return super.getN(); }
/** * Computes the timeout for the next request. * * @param type the message type * @return the computed timeout for the next request */ private long computeTimeoutMillis(String type) { DescriptiveStatistics samples = replySamples.get(type); if (samples == null || samples.getN() < MIN_SAMPLES) { return MAX_TIMEOUT_MILLIS; } return Math.min(Math.max((int) samples.getMax() * TIMEOUT_FACTOR, MIN_TIMEOUT_MILLIS), MAX_TIMEOUT_MILLIS); }
/** * Computes the phi value from the given samples. * <p> * The original phi value in Hayashibara's paper is calculated based on a normal distribution. * Here, we calculate it based on an exponential distribution. * * @param samples the samples from which to compute phi * @param lastHeartbeat the last heartbeat * @param currentTime the current time * @return phi */ private double computePhi(DescriptiveStatistics samples, long lastHeartbeat, long currentTime) { long size = samples.getN(); long t = currentTime - lastHeartbeat; return (size > 0) ? phiFactor * t / samples.getMean() : 100; }
/** * Returns the standard deviation of the available values. * @return The standard deviation, Double.NaN if no values have been added * or 0.0 for a single value set. */ public double getStandardDeviation() { double stdDev = Double.NaN; if (getN() > 0) { if (getN() > 1) { stdDev = FastMath.sqrt(getVariance()); } else { stdDev = 0.0; } } return stdDev; }
/** * Returns the quadratic mean, a.k.a. * <a href="http://mathworld.wolfram.com/Root-Mean-Square.html"> * root-mean-square</a> of the available values * @return The quadratic mean or {@code Double.NaN} if no values * have been added. */ public double getQuadraticMean() { final long n = getN(); return n > 0 ? FastMath.sqrt(getSumsq() / n) : Double.NaN; }
/** * Adds the value to the dataset. If the dataset is at the maximum size * (i.e., the number of stored elements equals the currently configured * windowSize), the first (oldest) element in the dataset is discarded * to make room for the new value. * * @param v the value to be added */ public void addValue(double v) { if (windowSize != INFINITE_WINDOW) { if (getN() == windowSize) { eDA.addElementRolling(v); } else if (getN() < windowSize) { eDA.addElement(v); } } else { eDA.addElement(v); } }
/** * Compute phi for the specified node id. * * @return phi value */ public double phi() { long latestHeartbeat = history.latestHeartbeatTime(); DescriptiveStatistics samples = history.samples(); if (samples.getN() < minSamples) { return 0.0; } return computePhi(samples, latestHeartbeat, System.currentTimeMillis()); }
/** * Generates a text report displaying univariate statistics from values * that have been added. Each statistic is displayed on a separate * line. * * @return String with line feeds displaying statistics */ @Override public String toString() { StringBuilder outBuffer = new StringBuilder(); String endl = "\n"; outBuffer.append("DescriptiveStatistics:").append(endl); outBuffer.append("n: ").append(getN()).append(endl); outBuffer.append("min: ").append(getMin()).append(endl); outBuffer.append("max: ").append(getMax()).append(endl); outBuffer.append("mean: ").append(getMean()).append(endl); outBuffer.append("std dev: ").append(getStandardDeviation()) .append(endl); try { // No catch for MIAE because actual parameter is valid below outBuffer.append("median: ").append(getPercentile(50)).append(endl); } catch (MathIllegalStateException ex) { outBuffer.append("median: unavailable").append(endl); } outBuffer.append("skewness: ").append(getSkewness()).append(endl); outBuffer.append("kurtosis: ").append(getKurtosis()).append(endl); return outBuffer.toString(); }
private void logStats(Set<?> set, double[] raw) { DescriptiveStatistics descStats = new DescriptiveStatistics(raw); Log.i( TAG, String.format( Locale.US, STAT_FORMAT, set.getClass().getSimpleName(), set.size(), descStats.getN(), Math.round(descStats.getMin()), Math.round(descStats.getMax()), Math.round(descStats.getMean()), descStats.getStandardDeviation(), descStats.getVariance() ) ); } }
@Override public long getCount() { return descStats.getN(); }
@Override public void run() { DescriptiveStatistics stats = limiter.getRateStatsSinceLastReport(); if (stats != null) { log.info(String.format("Requests rate stats: count: %d, min: %f, max: %f, mean: %f, std: %f, sum: %f", stats.getN(), stats.getMin(), stats.getMax(), stats.getMean(), stats.getStandardDeviation(), stats.getSum())); } stats = limiter.getUnusedPermitsSinceLastReport(); if (stats != null) { log.info(String.format("Unused permits rate stats: count: %d, min: %f, max: %f, mean: %f, std: %f, sum: %f", stats.getN(), stats.getMin(), stats.getMax(), stats.getMean(), stats.getStandardDeviation(), stats.getSum())); } if (this.policy instanceof QPSPolicy) { QPSPolicy qpsPolicy = (QPSPolicy) this.policy; DynamicTokenBucket dynamicTokenBucket = qpsPolicy.getTokenBucket(); TokenBucket tokenBucket = dynamicTokenBucket.getTokenBucket(); log.info("Stored tokens: " + tokenBucket.getStoredTokens()); } } }
public static String describe(DescriptiveStatistics stats, Double[] percentiles){ StringBuilder sb = new StringBuilder(); sb.append(String.format("round: mean of %dms [+-%d], measured %d rounds;\n", (long)stats.getMean(), (long)stats.getStandardDeviation(), stats.getN() )); sb.append("\tMin - " + (long)stats.getMin() + "\n"); for(double pctile : percentiles) { sb.append("\t" + pctile + " - " + stats.getPercentile(pctile) + "\n"); } sb.append("\tMax - " + (long)stats.getMax()); return sb.toString(); }
@Override public String toString() { MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this) .add("numResults", stats.getN()) .add("minTime", stats.getMin()) .add("meanTime", stats.getMean()) .add("maxTime", stats.getMax()) .add("25th", stats.getPercentile(25)) .add("50th", stats.getPercentile(50)) .add("75th", stats.getPercentile(75)) .add("90th", stats.getPercentile(90)) .add("95th", stats.getPercentile(95)) .add("99th", stats.getPercentile(99)) .add("99.9th", stats.getPercentile(99.9)) .add("99.99th", stats.getPercentile(99.99)) .add("traces", traces); return helper.toString(); } }
public void printResults() { printf("%-20s%20s%20s%20s\n", "Test Name", format.name + " Avg", "StdDev", "95% Interval"); for (int i = 0; i < numTests; i++) { double mean = stats[i].getMean() / format.divisor; double stddev = stats[i].getStandardDeviation() / format.divisor; double diff = 1.96 * stddev / MathUtils.sqrt(stats[i].getN()); printf("%-20s%20.3f%20.3f (%7.3f,%7.3f)\n", getTestName(i), mean, stddev, mean - diff, mean + diff); } }
private void emitStats(final StringBuilder builder, final long testTotalTime, final String label, final QueryInfo info) { emitStats(builder, testTotalTime, label, (int) info.time.getN(), info.numFailures, info.size, info.time); }
/** * Computes the timeout for the next request. * * @param type the message type * @return the computed timeout for the next request */ private long computeTimeoutMillis(String type) { DescriptiveStatistics samples = replySamples.get(type); if (samples == null || samples.getN() < MIN_SAMPLES) { return MAX_TIMEOUT_MILLIS; } return Math.min(Math.max((int) samples.getMax() * TIMEOUT_FACTOR, MIN_TIMEOUT_MILLIS), MAX_TIMEOUT_MILLIS); }
/** * Computes the current timeout. */ private void recomputeTimeoutMillis() { double nextTimeout = maxReplyTime.getAndSet(0) * TIMEOUT_MULTIPLIER; timeoutHistory.addValue( Math.min(Math.max(nextTimeout, MIN_TIMEOUT_MILLIS), MAX_TIMEOUT_MILLIS)); if (timeoutHistory.getN() == WINDOW_SIZE) { this.currentTimeout = (long) timeoutHistory.getMax(); } } }
/** * Returns the quadratic mean, a.k.a. * <a href="http://mathworld.wolfram.com/Root-Mean-Square.html"> * root-mean-square</a> of the available values * @return The quadratic mean or {@code Double.NaN} if no values * have been added. */ public double getQuadraticMean() { final long n = getN(); return n > 0 ? FastMath.sqrt(getSumsq() / n) : Double.NaN; }
public Huynh computeDecisionConsistency(){ Huynh huynh = new Huynh((int)this.numberOfItems(), (int)stats.getN(), cutScores.length, stats.getMean(), stats.getStandardDeviation(), cutScores ); return huynh; }
public Huynh computeDecisionConsistency(){ Huynh huynh = new Huynh((int)this.numberOfItems(), (int)stats.getN(), cutScores.length, stats.getMean(), stats.getStandardDeviation(), cutScores ); return huynh; }