Example usage for org.apache.commons.math.stat.descriptive SummaryStatistics addValue

List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics addValue

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive SummaryStatistics addValue.

Prototype

public void addValue(double value) 

Source Link

Document

Add a value to the data

Usage

From source file:boa.aggregators.ConfidenceIntervalAggregator.java

/** {@inheritDoc} */
@Override//from  ww w  .j  av  a 2  s  .c o m
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) {
    }
}

From source file:boa.aggregators.StDevAggregator.java

/** {@inheritDoc} */
@Override/*from  w w w  .j  av  a  2s . c o m*/
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.getStandardDeviation());
}

From source file:boa.aggregators.VarianceAggregator.java

/** {@inheritDoc} */
@Override/* w  ww .ja v a2  s  . c om*/
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());
}

From source file:alma.acs.monitoring.blobber.BlobData.java

/**
 * Calculates the statistics and stores it in {@link #statistics}
 * if our monitor point data is represented as Number objects;
 * otherwise this call is ignored./* ww  w . j a  v  a  2s . com*/
 * 
 * @param inDataList
 */
void calculateStatistics() {
    if (getDataSize() > 0) {

        // We trust that the data is homogeneous and check only the first MonitorPointValue

        MonitorPointValue sampleMonitorPointValue = mpTs.getDataList().get(0);

        if (sampleMonitorPointValue.getData().isEmpty()) {
            logger.finer(
                    "Ignoring calculateStatistics() call for a time series of MonitorPointValue objects that hold no data.");
            return;
        }

        // TODO: Should we also compute statistics for multi-valued properties?
        // This was not done in the original (= pre-ACS 12.0) implementation of BlobberWorker#calculateStatistics
        // and so far we keep this behavior. 
        if (sampleMonitorPointValue.isMultiValued()) {
            logger.finer(
                    "Ignoring calculateStatistics() call for a time series of multi-valued MonitorPointValue objects.");
            return;
        }

        // After the above checks, there should be a single data item in our sampleMonitorPointValue
        // We now verify that it has one of the expected numeric types.
        Object sampleData = sampleMonitorPointValue.getData().get(0);
        if (!(sampleData instanceof Integer || sampleData instanceof Long || sampleData instanceof Float
                || sampleData instanceof Double)) {
            logger.finer(
                    "Ignoring calculateStatistics() call for data type " + sampleData.getClass().getName());
            return;
        }

        // Now we calculate the statistics, 
        // using apache math lib that works only with 'double' type

        SummaryStatistics stat = new SummaryStatistics();
        for (MonitorPointValue blobData : mpTs.getDataList()) {
            Number value = (Number) blobData.getData().get(0);
            stat.addValue(value.doubleValue());
        }

        statistics = new ComponentStatistics();

        // We store the results in a ComponentStatistics object, 
        // converting to original data types where it makes sense
        if (sampleData instanceof Integer) {
            statistics.min = new Integer((int) Math.round(stat.getMin()));
            statistics.max = new Integer((int) Math.round(stat.getMax()));
            statistics.mean = new Double(stat.getMean()); // or Float, to indicate lower precision?
            statistics.stdDev = new Double(stat.getStandardDeviation()); // or Float, to indicate lower precision?
        } else if (sampleData instanceof Long) {
            statistics.min = new Long(Math.round(stat.getMin()));
            statistics.max = new Long(Math.round(stat.getMax()));
            statistics.mean = new Double(stat.getMean());
            statistics.stdDev = new Double(stat.getStandardDeviation());
        } else if (sampleData instanceof Float) {
            statistics.min = new Float(stat.getMin());
            statistics.max = new Float(stat.getMax());
            statistics.mean = new Float(stat.getMean());
            statistics.stdDev = new Float(stat.getStandardDeviation());
        } else if (sampleData instanceof Double) {
            statistics.min = new Double(stat.getMin());
            statistics.max = new Double(stat.getMax());
            statistics.mean = new Double(stat.getMean());
            statistics.stdDev = new Double(stat.getStandardDeviation());
        }
    }
}

From source file:com.vmware.upgrade.progress.impl.SimpleAggregatingProgressReporter.java

private int calculateProgress() {
    final SummaryStatistics childProgress = new SummaryStatistics();
    for (final PropagatingListener listener : childListeners) {
        childProgress.addValue(listener.getCurrentProgressReport().getProgress());
    }// w w w  . j av a  2 s  .c o  m

    final int roundedProgress = (int) Math.round(childProgress.getMean());
    return roundedProgress;
}

From source file:com.userweave.module.methoden.iconunderstandability.service.IconMatchingStatistics.java

private double getMeanReactionTimeForValues(List<Double> values) {
    SummaryStatistics stats = SummaryStatistics.newInstance();
    for (Double value : values) {
        if (value != null && isValid(value)) {
            stats.addValue(value);
        }//w  w w . ja v a2  s .com
    }
    return stats.getMean();
}

From source file:edu.scripps.fl.curves.plot.CurvePlot.java

protected YIntervalSeries getSeries(Map<Double, Collection<Double>> map, String description) {
    YIntervalSeries series = new YIntervalSeries(description);
    series.setDescription(description);/*from   w  w  w.  j  ava 2 s .c  o  m*/
    for (Object o : map.keySet()) {
        SummaryStatistics stats = new SummaryStatistics();
        Collection<Double> values = (Collection<Double>) map.get(o);
        for (Double d : values)
            stats.addValue(d);
        double avg = stats.getMean();
        double stddev = stats.getStandardDeviation();
        //         System.out.println(String.format("Adding %e\t%.2f\t%.2f",o, avg, stddev));
        series.add((Double) o, avg, avg - stddev, avg + stddev);
    }
    return series;
}

From source file:edu.cornell.med.icb.geo.BinaryArrayProbesetMinNormalizer.java

public void preSeries(final GEOPlatformIndexed platform) {
    if (options.tpr != null) {
        LOGGER.info(String.format("Platform maps to %d transcripts.", options.tpr.getTranscripts().size()));
    } else {//from  w  w w  .j  a  v  a 2s.c o  m
        // install default mapping from probsetId -> probesetId/asTranscriptId

        final IndexedIdentifier transcriptIndices = new IndexedIdentifier();
        options.tpr = new TranscriptProbesetRelationship(transcriptIndices);
        final IndexedIdentifier indexOfProbesets = platform.getProbeIds();
        for (final MutableString probesetId : indexOfProbesets.keySet()) {
            options.tpr.addRelationship(probesetId, indexOfProbesets.get(probesetId));
        }
    }
    projectTo = "tissue";
    final double[] sumSignalBySample = sumSignal(platform);

    final SummaryStatistics statHelper = new SummaryStatistics();
    for (final double sumForOneSample : sumSignalBySample) {
        statHelper.addValue(sumForOneSample);
    }
    final double averageSumForSamples = statHelper.getMean();
    final float[] minValuesPerProbesets = estimateMinValueForProbesets(sumSignalBySample, platform, 10,
            averageSumForSamples);

    writeNormalize(averageSumForSamples, sumSignalBySample, minValuesPerProbesets, platform);
    System.exit(0);
}

From source file:boa.aggregators.StatisticsAggregator.java

/** {@inheritDoc} */
@Override//from ww w .j  ava2s  .c  o  m
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);
}

From source file:com.netflix.curator.framework.recipes.queue.TestQueueSharder.java

@Test
public void testDistribution() throws Exception {
    final int threshold = 100;
    final int factor = 10;

    Timing timing = new Timing();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(),
            timing.connection(), new RetryOneTime(1));
    QueueSharder<String, DistributedQueue<String>> sharder = null;
    try {/*from  w  w w.  ja  va  2 s.c o m*/
        client.start();

        final CountDownLatch latch = new CountDownLatch(1);
        QueueConsumer<String> consumer = new QueueConsumer<String>() {
            @Override
            public void consumeMessage(String message) throws Exception {
                latch.await();
            }

            @Override
            public void stateChanged(CuratorFramework client, ConnectionState newState) {
            }
        };
        QueueAllocator<String, DistributedQueue<String>> distributedQueueAllocator = makeAllocator(consumer);
        QueueSharderPolicies policies = QueueSharderPolicies.builder().newQueueThreshold(threshold)
                .thresholdCheckMs(1).build();
        sharder = new QueueSharder<String, DistributedQueue<String>>(client, distributedQueueAllocator,
                "/queues", "/leader", policies);
        sharder.start();

        for (int i = 0; i < (factor * threshold); ++i) {
            sharder.getQueue().put(Integer.toString(i));
            Thread.sleep(5);
        }
        timing.forWaiting().sleepABit();

        SummaryStatistics statistics = new SummaryStatistics();
        for (String path : sharder.getQueuePaths()) {
            int numChildren = client.checkExists().forPath(path).getNumChildren();
            Assert.assertTrue(numChildren > 0);
            Assert.assertTrue(numChildren >= (threshold * .1));
            statistics.addValue(numChildren);
        }
        latch.countDown();

        Assert.assertTrue(statistics.getMean() >= (threshold * .9));
    } finally {
        timing.sleepABit(); // let queue clear
        Closeables.closeQuietly(sharder);
        Closeables.closeQuietly(client);
    }
}