long n = current.getN(); double min = current.getMin(); double sum = current.getSum(); double max = current.getMax(); double var = current.getVariance(); double m2 = var * (n - 1d); 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; final double curM2 = current.getVariance() * (curN - 1d); m2 = m2 + curM2 + meanDiff * meanDiff * oldN * curN / n;
/** * Computes the empirical distribution using values from the file * in <code>valuesFileURL</code> and <code>binCount</code> bins. * <p> * <code>valuesFileURL</code> must exist and be readable by this process * at runtime.</p> * <p> * This method must be called before using <code>getNext()</code> * with <code>mode = DIGEST_MODE</code></p> * * @param binCount the number of bins used in computing the empirical * distribution * @throws NullArgumentException if the {@code valuesFileURL} has not been set * @throws IOException if an error occurs reading the input file * @throws ZeroException if URL contains no data */ public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException { empiricalDistribution = new EmpiricalDistribution(binCount, randomData.getRandomGenerator()); empiricalDistribution.load(valuesFileURL); mu = empiricalDistribution.getSampleStats().getMean(); sigma = empiricalDistribution.getSampleStats().getStandardDeviation(); }
/** * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> * t statistic </a> to use in comparing the mean of the dataset described by * <code>sampleStats</code> to <code>mu</code>. * <p> * This statistic can be used to perform a one sample t-test for the mean. * </p><p> * <strong>Preconditions</strong>: <ul> * <li><code>observed.getN() ≥ 2</code>. * </li></ul></p> * * @param mu comparison constant * @param sampleStats DescriptiveStatistics holding sample summary statitstics * @return t statistic * @throws NullArgumentException if <code>sampleStats</code> is <code>null</code> * @throws NumberIsTooSmallException if the number of samples is < 2 */ public double t(final double mu, final StatisticalSummary sampleStats) throws NullArgumentException, NumberIsTooSmallException { checkSampleData(sampleStats); return t(sampleStats.getMean(), mu, sampleStats.getVariance(), sampleStats.getN()); }
long min = Math.round(statistics.getMin()); long max = Math.round(statistics.getMax()); double mean = statistics.getMean(); double sd = statistics.getStandardDeviation(); double sem = sd / Math.sqrt(statistics.getN());
private void addMeanMaxMeasurements(Map<String, double[]> loadedMetrics, List<Measurement> measurements, String metricName, String unit) { Optional<StatisticalSummary> statistics = getStats(loadedMetrics, metricName); if (statistics.isPresent()) { measurements.add(Measurement.measurement("cluster-" + metricName + "_max", unit, statistics.get().getMax())); measurements.add(Measurement.measurement("cluster-" + metricName + "_mean", unit, statistics.get().getMean())); } }
/** * Check sample data. * * @param stat Statistical summary. * @throws NullArgumentException if {@code data} is {@code null}. * @throws NumberIsTooSmallException if there is not enough sample data. */ private void checkSampleData(final StatisticalSummary stat) throws NullArgumentException, NumberIsTooSmallException { if (stat == null) { throw new NullArgumentException(); } if (stat.getN() < 2) { throw new NumberIsTooSmallException( LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC, stat.getN(), 2, true); } }
@Override public double getMax() { return delegate.getMax(); }
@Override public double getMean() { return delegate.getMean(); }
@Override public double getMin() { return delegate.getMin(); }
@Override public double getStandardDeviation() { return delegate.getStandardDeviation(); }
@Override public double getVariance() { return delegate.getVariance(); }
@Override public double getSum() { return delegate.getSum(); }
public static String describeDuration(StatisticalSummary duration, TimeUnit units) { double min = duration.getMin(); double max = duration.getMax(); if (min == max) { return describeDuration(max, units); } else { double mean = duration.getMean(); double sem = duration.getStandardDeviation() / Math.sqrt(duration.getN()); String meanDescription; if (sem == 0) { meanDescription = describeDuration(mean, units); } else { TimeUnit targetUnits = displayUnitFor(Math.round(mean), units); double scaledMean = convert(mean, units, targetUnits); double scaledSem = convert(sem, units, targetUnits); meanDescription = "(" + toThreeSigFig(scaledMean, 2000, scaledSem) + ") " + SHORT_TIMEUNIT_NAMES.get(targetUnits); } double sd = duration.getStandardDeviation(); return " min. " + describeDuration(min, units) + ", mean " + meanDescription + ", SD " + describeDuration(sd, units) + ", max. " + describeDuration(max, units); } }
return homoscedasticT(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(), sampleStats2.getVariance(), sampleStats1.getN(), sampleStats2.getN());
@Override public long getN() { return delegate.getN(); }
long min = Math.round(size.getMin()); long max = Math.round(size.getMax()); if (min == max) { return describeSize(max); } else { double mean = size.getMean(); double sem = size.getStandardDeviation() / Math.sqrt(size.getN()); String meanDescription; if (sem == 0) { long sd = Math.round(size.getStandardDeviation()); return "min. " + describeSize(min) + ", mean " + meanDescription
return t(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(), sampleStats2.getVariance(), sampleStats1.getN(), sampleStats2.getN());
/** * Computes the empirical distribution using values from the file * in <code>valuesFileURL</code> and <code>binCount</code> bins. * <p> * <code>valuesFileURL</code> must exist and be readable by this process * at runtime.</p> * <p> * This method must be called before using <code>getNext()</code> * with <code>mode = DIGEST_MODE</code></p> * * @param binCount the number of bins used in computing the empirical * distribution * @throws NullArgumentException if the {@code valuesFileURL} has not been set * @throws IOException if an error occurs reading the input file * @throws ZeroException if URL contains no data */ public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException { empiricalDistribution = new EmpiricalDistribution(binCount, randomData.getRandomGenerator()); empiricalDistribution.load(valuesFileURL); mu = empiricalDistribution.getSampleStats().getMean(); sigma = empiricalDistribution.getSampleStats().getStandardDeviation(); }
/** * Check sample data. * * @param stat Statistical summary. * @throws NullArgumentException if {@code data} is {@code null}. * @throws NumberIsTooSmallException if there is not enough sample data. */ private void checkSampleData(final StatisticalSummary stat) throws NullArgumentException, NumberIsTooSmallException { if (stat == null) { throw new NullArgumentException(); } if (stat.getN() < 2) { throw new NumberIsTooSmallException( LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC, stat.getN(), 2, true); } }