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

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

Introduction

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

Prototype

public long getN() 

Source Link

Document

Returns the number of available values

Usage

From source file:se.sics.kompics.p2p.experiment.bittorrent.BitTorrentSimulator.java

private void logStatistics() {
    SummaryStatistics downloadTime = new SummaryStatistics();
    for (long time : leecherDownloadTime.values()) {
        downloadTime.addValue(time);//from   w ww.  j ava 2s.  com
    }

    int messages = 0;
    long traffic = 0;
    for (ReceivedMessage rm : messageHistogram.values()) {
        messages += rm.getTotalCount();
        traffic += rm.getTotalSize();
    }

    long torrentSize = torrent.getPieceCount() * torrent.getPieceSize();

    logger.info("=================================================");
    logger.info("Content size: {} bytes", torrentSize);
    logger.info("Piece size:   {} bytes", torrent.getPieceSize());
    logger.info("Piece count:  {}", torrent.getPieceCount());
    logger.info("=================================================");
    logger.info("Number of leechers: {}", downloadTime.getN());
    logger.info("Min download time:  {} ms ({})", downloadTime.getMin(),
            durationToString(Math.round(downloadTime.getMin())));
    logger.info("Max download time:  {} ms ({})", downloadTime.getMax(),
            durationToString(Math.round(downloadTime.getMax())));
    logger.info("Avg download time:  {} ms ({})", downloadTime.getMean(),
            durationToString(Math.round(downloadTime.getMean())));
    logger.info("Std download time:  {} ms ({})", downloadTime.getStandardDeviation(),
            durationToString(Math.round(downloadTime.getStandardDeviation())));
    logger.info("Min download rate:  {} Bps", torrentSize / downloadTime.getMax() * 1000);
    logger.info("Max download rate:  {} Bps", torrentSize / downloadTime.getMin() * 1000);
    logger.info("Avg download rate:  {} Bps", torrentSize / downloadTime.getMean() * 1000);
    logger.info("=================================================");
    logger.info("Total number of messages: {}", messages);
    logger.info("Total amount of traffic:  {} bytes", traffic);
    for (Map.Entry<Class<? extends Message>, ReceivedMessage> entry : messageHistogram.entrySet()) {
        logger.info("{}: #={}  \t bytes={}",
                new Object[] { String.format("%22s", entry.getKey().getSimpleName()),
                        entry.getValue().getTotalCount(), entry.getValue().getTotalSize() });
    }
    logger.info("=================================================");
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java

/**
 * Calculate summary statistics for a dataset along an axis
 *//*from w  w  w  .  j a v  a2 s.c o  m*/
protected void calculateSummaryStats(final int axis) {
    int rank = getRank();

    int[] oshape = getShape();
    int alen = oshape[axis];
    oshape[axis] = 1;

    int[] nshape = new int[rank - 1];
    for (int i = 0; i < axis; i++) {
        nshape[i] = oshape[i];
    }
    for (int i = axis + 1; i < rank; i++) {
        nshape[i - 1] = oshape[i];
    }

    final int dtype = getDtype();
    IntegerDataset count = new IntegerDataset(nshape);
    AbstractDataset max = zeros(nshape, dtype);
    AbstractDataset min = zeros(nshape, dtype);
    IntegerDataset maxIndex = new IntegerDataset(nshape);
    IntegerDataset minIndex = new IntegerDataset(nshape);
    AbstractDataset sum = zeros(nshape, getLargestDType(dtype));
    DoubleDataset mean = new DoubleDataset(nshape);
    DoubleDataset var = new DoubleDataset(nshape);

    IndexIterator qiter = max.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos = oshape.clone();

    while (qiter.hasNext()) {
        int i = 0;
        for (; i < axis; i++) {
            spos[i] = qpos[i];
        }
        spos[i++] = 0;
        for (; i < rank; i++) {
            spos[i] = qpos[i - 1];
        }

        final SummaryStatistics stats = new SummaryStatistics();
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            final double val = getDouble(spos);
            if (Double.isInfinite(val) || Double.isNaN(val)) {
                continue;
            }

            stats.addValue(val);
        }

        count.setAbs(qiter.index, (int) stats.getN());

        final double amax = stats.getMax();
        max.setObjectAbs(qiter.index, amax);
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            final double val = getDouble(spos);
            if (val == amax) {
                maxIndex.setAbs(qiter.index, j);
                break;
            }
        }
        final double amin = stats.getMin();
        min.setObjectAbs(qiter.index, amax);
        for (int j = 0; j < alen; j++) {
            spos[axis] = j;
            final double val = getDouble(spos);
            if (val == amin) {
                minIndex.setAbs(qiter.index, j);
                break;
            }
        }
        sum.setObjectAbs(qiter.index, stats.getSum());
        mean.setAbs(qiter.index, stats.getMean());
        var.setAbs(qiter.index, stats.getVariance());
    }
    setStoredValue("count-" + axis, count);
    storedValues.put("max-" + axis, max);
    storedValues.put("min-" + axis, min);
    storedValues.put("sum-" + axis, sum);
    storedValues.put("mean-" + axis, mean);
    storedValues.put("var-" + axis, var);
    storedValues.put("maxIndex-" + axis, maxIndex);
    storedValues.put("minIndex-" + axis, minIndex);
}