Search in sources :

Example 6 with SummaryStatistics

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);
}
Also used : TDistributionImpl(org.apache.commons.math.distribution.TDistributionImpl) MathException(org.apache.commons.math.MathException) SummaryStatistics(org.apache.commons.math.stat.descriptive.SummaryStatistics)

Example 7 with SummaryStatistics

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());
}
Also used : SummaryStatistics(org.apache.commons.math.stat.descriptive.SummaryStatistics)

Example 8 with SummaryStatistics

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());
}
Also used : SummaryStatistics(org.apache.commons.math.stat.descriptive.SummaryStatistics)

Example 9 with SummaryStatistics

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) {
    }
}
Also used : TDistributionImpl(org.apache.commons.math.distribution.TDistributionImpl) MathException(org.apache.commons.math.MathException) SummaryStatistics(org.apache.commons.math.stat.descriptive.SummaryStatistics)

Aggregations

SummaryStatistics (org.apache.commons.math.stat.descriptive.SummaryStatistics)9 MathException (org.apache.commons.math.MathException)2 TDistributionImpl (org.apache.commons.math.distribution.TDistributionImpl)2 Test (org.junit.Test)2 ComponentStatistics (alma.acs.monitoring.DAO.ComponentStatistics)1 MonitorPointValue (alma.acs.monitoring.MonitorPointValue)1 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RequestData (org.apache.sling.engine.impl.request.RequestData)1 Expectations (org.jmock.Expectations)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1