use of org.apache.commons.math.stat.descriptive.SummaryStatistics in project compiler by boalang.
the class StatisticsAggregator method finish.
/** {@inheritDoc} */
@Override
public void finish() throws IOException, InterruptedException {
if (this.isCombining()) {
String s = "";
for (final Long key : map.keySet()) s += key + ":" + map.get(key) + ";";
this.collect(s, null);
return;
}
float median = 0;
long medianPos = count / 2L;
long curPos = 0;
long prevPos = 0;
long prevKey = 0;
for (final Long key : map.keySet()) {
curPos = prevPos + map.get(key);
if (prevPos <= medianPos && medianPos < curPos) {
if (curPos % 2 == 0 && prevPos == medianPos)
median = (float) (key + prevKey) / 2.0f;
else
median = key;
break;
}
prevKey = key;
prevPos = curPos;
}
double s1 = 0;
double s2 = 0;
double s3 = 0;
double s4 = 0;
final SummaryStatistics summaryStatistics = new SummaryStatistics();
for (final Long key : map.keySet()) {
s1 += key * map.get(key);
s2 += key * key * map.get(key);
s3 += key * key * key * map.get(key);
s4 += key * key * key * key * map.get(key);
for (int i = 0; i < map.get(key); i++) summaryStatistics.addValue(key);
}
final double mean = s1 / (double) count;
final double var = s2 / (double) (count - 1) - s1 * s1 / (double) (count * (count - 1));
final double stdev = Math.sqrt(var);
final double skewness = (s3 - 3 * s1 * s2 / (double) count + s1 * s1 * s1 * 2 / (count * count)) / (count * stdev * var);
final double kurtosis = (s4 - s3 * s1 * 4 / count + s2 * s1 * s1 * 6 / (double) (count * count) - s1 * s1 * s1 * s1 * 3 / (double) (count * count * count)) / (count * var * var);
double ci = 0.0;
try {
final TDistributionImpl tDist = new TDistributionImpl(summaryStatistics.getN() - 1);
final double a = tDist.inverseCumulativeProbability(1.0 - 0.025);
ci = a * summaryStatistics.getStandardDeviation() / Math.sqrt(summaryStatistics.getN());
} catch (final MathException e) {
}
this.collect(s1 + ", " + mean + ", " + median + ", " + stdev + ", " + var + ", " + kurtosis + ", " + skewness + ", " + ci);
}
use of org.apache.commons.math.stat.descriptive.SummaryStatistics in project titan by thinkaurelius.
the class TestByteBuffer method main.
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());
}
use of org.apache.commons.math.stat.descriptive.SummaryStatistics in project compiler by boalang.
the class VarianceAggregator method finish.
/** {@inheritDoc} */
@Override
public void finish() throws IOException, InterruptedException {
if (this.isCombining()) {
String s = "";
for (final Long key : map.keySet()) s += key + ":" + map.get(key) + ";";
this.collect(s, null);
return;
}
final SummaryStatistics summaryStatistics = new SummaryStatistics();
for (final Long key : map.keySet()) {
final long count = map.get(key);
for (long i = 0; i < count; i++) summaryStatistics.addValue(key);
}
this.collect(summaryStatistics.getVariance());
}
use of org.apache.commons.math.stat.descriptive.SummaryStatistics in project compiler by boalang.
the class ConfidenceIntervalAggregator method finish.
/** {@inheritDoc} */
@Override
public void finish() throws IOException, InterruptedException {
if (this.isCombining()) {
String s = "";
for (final Long key : map.keySet()) s += key + ":" + map.get(key) + ";";
this.collect(s, null);
return;
}
try {
final SummaryStatistics summaryStatistics = new SummaryStatistics();
for (final Long key : map.keySet()) for (int i = 0; i < map.get(key); i++) summaryStatistics.addValue(key);
final double a = new TDistributionImpl(summaryStatistics.getN() - 1).inverseCumulativeProbability(1.0 - n / 200.0);
this.collect(a * summaryStatistics.getStandardDeviation() / Math.sqrt(summaryStatistics.getN()));
} catch (final MathException e) {
}
}
Aggregations