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:se.sics.gvod.simulator.vod.VodSimulator.java

private void logStatistics() {
    //        snapshot.generateGraphVizReport();
    SummaryStatistics downloadTimeNotFree = new SummaryStatistics();
    SummaryStatistics downloadTime99NotFree = new SummaryStatistics();
    SummaryStatistics nbBufferingNotFree = new SummaryStatistics();
    SummaryStatistics nbNBufferingNotFree = new SummaryStatistics();
    SummaryStatistics statsWaitingNotFree = new SummaryStatistics();
    SummaryStatistics downloadTimeFree = new SummaryStatistics();
    SummaryStatistics downloadTime99Free = new SummaryStatistics();
    SummaryStatistics nbBufferingFree = new SummaryStatistics();
    SummaryStatistics nbNBufferingFree = new SummaryStatistics();
    SummaryStatistics statsWaitingFree = new SummaryStatistics();
    SummaryStatistics nbWaiting = new SummaryStatistics();
    SummaryStatistics nbMisConnect = new SummaryStatistics();

    Map<Long, SummaryStatistics> downloadNotFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> download99NotFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, ArrayList<Long>> list99NotFree = new HashMap<Long, ArrayList<Long>>();
    Map<Long, SummaryStatistics> totalUploadUse = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> waitingNotFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> bufferingNotFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> notBufferingNotFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> downloadFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> download99Free = new HashMap<Long, SummaryStatistics>();
    Map<Long, ArrayList<Long>> list99Free = new HashMap<Long, ArrayList<Long>>();
    Map<Long, SummaryStatistics> waitingFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> bufferingFree = new HashMap<Long, SummaryStatistics>();
    Map<Long, SummaryStatistics> notBufferingFree = new HashMap<Long, SummaryStatistics>();

    ArrayList<Long> temp = new ArrayList<Long>();
    long totalDownload = 0;
    long totalUpload = 0;
    for (Integer node : nodeDownloadTimeNotFree.keySet()) {
        downloadTimeNotFree.addValue(nodeDownloadTimeNotFree.get(node));
        temp.add(nodeDownloadTimeNotFree.get(node));
        if (!downloadNotFree.containsKey(downloadLink.get(node).getCapacity())) {
            downloadNotFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            download99NotFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            list99NotFree.put(downloadLink.get(node).getCapacity(), new ArrayList<Long>());
            totalUploadUse.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            waitingNotFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            bufferingNotFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            notBufferingNotFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
        }//from w w w  .  j a  va 2  s  . c  o  m
        downloadNotFree.get(downloadLink.get(node).getCapacity()).addValue(nodeDownloadTimeNotFree.get(node));
        list99NotFree.get(downloadLink.get(node).getCapacity()).add(nodeDownloadTimeNotFree.get(node));
        totalUploadUse.get(downloadLink.get(node).getCapacity())
                .addValue(uploadLink.get(node).getBwUsePs() / 1024);
        waitingNotFree.get(downloadLink.get(node).getCapacity()).addValue(nodeWaitingTimeNotFree.get(node));
        bufferingNotFree.get(downloadLink.get(node).getCapacity()).addValue(nodeNbBufferingNotFree.get(node));
        if (nodeNbBufferingNotFree.get(node) == 0) {
            notBufferingNotFree.get(downloadLink.get(node).getCapacity()).addValue(1);
        } else {
            notBufferingNotFree.get(downloadLink.get(node).getCapacity()).addValue(0);
        }
        totalDownload += downloadLink.get(node).getBwUse();
        totalUpload += uploadLink.get(node).getBwUse();
    }

    Collections.sort(temp);
    int i = temp.size() * 5 / 100;
    while (i > 0) {
        temp.remove(temp.size() - 1);
        i--;
    }
    for (Long val : temp) {
        downloadTime99NotFree.addValue(val);
    }

    for (Long key : list99NotFree.keySet()) {
        Collections.sort(list99NotFree.get(key));
        i = list99NotFree.get(key).size() / 100;
        while (i > 0) {
            long toRemove = list99NotFree.get(key).size() - 1;
            list99NotFree.get(key).remove(toRemove);
            i--;
        }
        for (Long val : list99NotFree.get(key)) {
            download99NotFree.get(key).addValue(val);
        }
    }

    if (downloadLink.get(seedId) != null) {
        totalDownload += downloadLink.get(seedId).getBwUse();
        totalUpload += uploadLink.get(seedId).getBwUse();

        if (totalUploadUse.get(downloadLink.get(seedId).getCapacity()) == null) {
            totalUploadUse.put(downloadLink.get(seedId).getCapacity(), new SummaryStatistics());
        }
        totalUploadUse.get(downloadLink.get(seedId).getCapacity())
                .addValue(uploadLink.get(seedId).getBwUsePs() / 1280);
    }
    for (int bufferingNb : nodeNbBufferingNotFree.values()) {
        nbBufferingNotFree.addValue(bufferingNb);
        if (bufferingNb == 0) {
            nbNBufferingNotFree.addValue(1);
        } else {
            nbNBufferingNotFree.addValue(0);
        }
    }
    for (int waitingTime : nodeNbWaiting.values()) {
        nbWaiting.addValue(waitingTime);
    }

    for (int misConnect : nodeNbMisConnect.values()) {
        nbMisConnect.addValue(misConnect);
    }

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

    temp = new ArrayList<Long>();
    for (Integer node : nodeDownloadTimeFree.keySet()) {
        downloadTimeFree.addValue(nodeDownloadTimeFree.get(node));
        temp.add(nodeDownloadTimeFree.get(node));
        if (!downloadFree.containsKey(downloadLink.get(node).getCapacity())) {
            downloadFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            download99Free.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            list99Free.put(downloadLink.get(node).getCapacity(), new ArrayList<Long>());
            totalUploadUse.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            waitingFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            bufferingFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
            notBufferingFree.put(downloadLink.get(node).getCapacity(), new SummaryStatistics());
        }
        downloadFree.get(downloadLink.get(node).getCapacity()).addValue(nodeDownloadTimeFree.get(node));
        list99Free.get(downloadLink.get(node).getCapacity()).add(nodeDownloadTimeFree.get(node));
        totalUploadUse.get(downloadLink.get(node).getCapacity())
                .addValue(uploadLink.get(node).getBwUsePs() / 1024);
        waitingFree.get(downloadLink.get(node).getCapacity()).addValue(nodeWaitingTimeFree.get(node));
        bufferingFree.get(downloadLink.get(node).getCapacity()).addValue(nodeNbBufferingFree.get(node));
        if (nodeNbBufferingFree.get(node) == 0) {
            notBufferingFree.get(downloadLink.get(node).getCapacity()).addValue(1);
        } else {
            notBufferingFree.get(downloadLink.get(node).getCapacity()).addValue(0);
        }
        totalDownload += downloadLink.get(node).getBwUse();
        totalUpload += uploadLink.get(node).getBwUse();
    }

    Collections.sort(temp);
    i = temp.size() * 5 / 100;
    while (i > 0) {
        temp.remove(temp.size() - 1);
        i--;
    }
    for (Long val : temp) {
        downloadTime99Free.addValue(val);
    }

    for (Long key : list99Free.keySet()) {
        Collections.sort(list99Free.get(key));
        i = list99Free.get(key).size() / 100;
        while (i > 0) {
            long toRemove = list99Free.get(key).size() - 1;
            list99Free.get(key).remove(toRemove);
            i--;
        }
        for (Long val : list99Free.get(key)) {
            download99Free.get(key).addValue(val);
        }
    }

    for (int bufferingNb : nodeNbBufferingFree.values()) {
        nbBufferingFree.addValue(bufferingNb);
        if (bufferingNb == 0) {
            nbNBufferingFree.addValue(1);
        } else {
            nbNBufferingFree.addValue(0);
        }
    }

    for (long waitingTime : nodeWaitingTimeFree.values()) {
        statsWaitingFree.addValue(waitingTime);
    }

    logger.info("=================================================");
    logger.info("Total Upload : {}", totalUpload);
    logger.info("Total Download : {}", totalDownload);
    logger.info("diff : {}", Math.abs(totalUpload - totalDownload));
    logger.info("=================================================");
    logger.info("NOT FREE");
    logger.info("Number of nodes: {}", downloadTimeNotFree.getN());
    logger.info("Min download time:  {} ms ({})", downloadTimeNotFree.getMin(),
            durationToString(Math.round(downloadTimeNotFree.getMin())));
    logger.info("Max download time:  {} ms ({})", downloadTimeNotFree.getMax(),
            durationToString(Math.round(downloadTimeNotFree.getMax())));
    logger.info("Avg download time:  {} ms ({})", downloadTimeNotFree.getMean(),
            durationToString(Math.round(downloadTimeNotFree.getMean())));
    logger.info("Std download time:  {} ms ({})", downloadTimeNotFree.getStandardDeviation(),
            durationToString(Math.round(downloadTimeNotFree.getStandardDeviation())));
    logger.info("=================================================");
    logger.info("FREE");
    logger.info("Number of nodes: {}", downloadTimeFree.getN());
    logger.info("Min download time:  {} ms ({})", downloadTimeFree.getMin(),
            durationToString(Math.round(downloadTimeFree.getMin())));
    logger.info("Max download time:  {} ms ({})", downloadTimeFree.getMax(),
            durationToString(Math.round(downloadTimeFree.getMax())));
    logger.info("Avg download time:  {} ms ({})", downloadTimeFree.getMean(),
            durationToString(Math.round(downloadTimeFree.getMean())));
    logger.info("Std download time:  {} ms ({})", downloadTimeFree.getStandardDeviation(),
            durationToString(Math.round(downloadTimeFree.getStandardDeviation())));

    int nbNodes = nodeDownloadTimeNotFree.size() + nodeDownloadTimeFree.size();
    try {
        FileWriter writer = new FileWriter("gvod" + VodConfig.PERCENTAGE_FREERIDERS // arg
                + "NotFree_superseed.out", true);
        String text = seed + "\t" + nbNodes + "\t" + downloadTimeNotFree.getMean() + "\t"
                + downloadTimeNotFree.getMax() + "\t" + downloadTimeNotFree.getMin() + "\t"
                + downloadTime99NotFree.getMax() + "\t" + statsWaitingNotFree.getMean() + "\t"
                + nbBufferingNotFree.getMean() + "\t" + nbNBufferingNotFree.getMean() + "\n";
        writer.write(text, 0, text.length());
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        FileWriter writer = new FileWriter("gvod" + VodConfig.PERCENTAGE_FREERIDERS + "Free_superseed.out",
                true);
        String text = seed + "\t" + nbNodes + "\t" + downloadTimeFree.getMean() + "\t"
                + downloadTimeFree.getMax() + "\t" + downloadTimeFree.getMin() + "\t"
                + downloadTime99Free.getMax() + "\t" + statsWaitingFree.getMean() + "\t"
                + nbBufferingFree.getMean() + "\t" + nbNBufferingFree.getMean() + "\n";
        writer.write(text, 0, text.length());
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    for (long bW : downloadNotFree.keySet()) {
        logger.info("=================================================");

        SummaryStatistics stats = downloadNotFree.get(bW);
        SummaryStatistics stats99 = download99NotFree.get(bW);
        SummaryStatistics statsUpTotal = totalUploadUse.get(bW);
        SummaryStatistics statsDown = downloadUse.get(bW);
        SummaryStatistics statsUp = uploadUse.get(bW);
        SummaryStatistics statsWait = waitingNotFree.get(bW);
        SummaryStatistics statsBuf = bufferingNotFree.get(bW);
        SummaryStatistics statsNBuf = notBufferingNotFree.get(bW);

        try {
            FileWriter writer = new FileWriter(
                    bW + "gvod" + VodConfig.PERCENTAGE_FREERIDERS + "NotFree_superseed.out", true);
            String text = nbNodes + "\t" + stats.getMean() + "\t" + stats.getMax() + "\t" + stats.getMin()
                    + "\t" + stats99.getMax() + "\t" + statsWait.getMean() + "\t" + statsBuf.getMean() + "\t"
                    + statsNBuf.getMean() + "\n";
            writer.write(text, 0, text.length());
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        Map<Integer, SummaryStatistics> map = utilitySetSize.get(bW);

        logger.info(
                "BandWith down {}KB/S, nb of nodes {} ("
                        + ((float) stats.getN() / downloadTimeNotFree.getN()) * 100 + "%)",
                bW / 1024, stats.getN());
        logger.info("Number of nodes: {}", stats.getN());
        logger.info("Min download time:  {} ms ({})", stats.getMin(),
                durationToString(Math.round(stats.getMin())));
        logger.info("Max download time:  {} ms ({})", stats.getMax(),
                durationToString(Math.round(stats.getMax())));
        logger.info("Avg download time:  {} ms ({})", stats.getMean(),
                durationToString(Math.round(stats.getMean())));
        logger.info("Std download time:  {} ms ({})", stats.getStandardDeviation(),
                durationToString(Math.round(stats.getStandardDeviation())));
        logger.info("Avg upload Use Total: {} KBytes/s", statsUpTotal.getMean());
        logger.info("Avg upload Use during download: {} KBytes/s", statsUp.getMean());
        logger.info("Max upload Use during download: {} KBytes/s", statsUp.getMax());
        logger.info("Avg download Use Total during downloag: {} KBytes/s", statsDown.getMean());
        logger.info("Min download Use Total during downloag: {} KBytes/s", statsDown.getMin());
        logger.info("-----------------------------------------------");
        logger.info("Avg buffering Time: {} ms ({})", statsWait.getMean(),
                durationToString(Math.round(statsWait.getMean())));
        logger.info("Avg number of buffering : {}", statsBuf.getMean());
    }

    for (long bW : downloadFree.keySet()) {
        logger.info("=================================================");

        SummaryStatistics stats = downloadFree.get(bW);
        SummaryStatistics stats99 = download99Free.get(bW);
        SummaryStatistics statsUpTotal = totalUploadUse.get(bW);
        SummaryStatistics statsDown = downloadUse.get(bW);
        SummaryStatistics statsUp = uploadUse.get(bW);
        SummaryStatistics statsWait = waitingFree.get(bW);
        SummaryStatistics statsBuf = bufferingFree.get(bW);
        SummaryStatistics statsNBuf = notBufferingFree.get(bW);

        try {
            FileWriter writer = new FileWriter(bW + "gvod" //                        + arg + "Free_superseed.out"
                    , true);
            String text = nbNodes
                    //                        + "\t" + gvodConfiguration.getArg()
                    + "\t" + stats.getMean() + "\t" + stats.getMax() + "\t" + stats.getMin() + "\t"
                    + stats99.getMax() + "\t" + statsWait.getMean() + "\t" + statsBuf.getMean() + "\t"
                    + statsNBuf.getMean() + "\n";
            writer.write(text, 0, text.length());
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        Map<Integer, SummaryStatistics> map = utilitySetSize.get(bW);

        //            logger.info("BandWith down {}KB/S, nb of nodes {} (" +
        //                    ((float) stats.getN() / downloadTimeNotFree.getN()) * 100 + "%)", bW / 1024, stats.getN());
        //            logger.info("Number of nodes: {}", stats.getN());
        //            logger.info("Min download time:  {} ms ({})", stats.getMin(),
        //                    durationToString(Math.round(stats.getMin())));
        //            logger.info("Max download time:  {} ms ({})", stats.getMax(),
        //                    durationToString(Math.round(stats.getMax())));
        //            logger.info("Avg download time:  {} ms ({})", stats.getMean(),
        //                    durationToString(Math.round(stats.getMean())));
        //            logger.info("Std download time:  {} ms ({})",
        //                    stats.getStandardDeviation(),
        //                    durationToString(Math.round(stats.getStandardDeviation())));
        //            logger.info("Avg upload Use Total: {} KBytes/s", statsUpTotal.getMean());
        //            logger.info("Avg upload Use during download: {} KBytes/s", statsUp.getMean());
        //            logger.info("Max upload Use during download: {} KBytes/s", statsUp.getMax());
        //            logger.info("Avg download Use Total during downloag: {} KBytes/s", statsDown.getMean());
        //            logger.info("Min download Use Total during downloag: {} KBytes/s", statsDown.getMin());
        //            logger.info("-----------------------------------------------");
        //            logger.info("Avg buffering Time: {} ms ({})", statsWait.getMean(),
        //                    durationToString(Math.round(statsWait.getMean())));
        //            logger.info("Avg number of buffering : {}", statsBuf.getMean());
        //            logger.info("do not buffer : {}%", donotbuffer * 100);
        //            for (int size : map.keySet()) {
        //                logger.info("UtilitySet of Size " + size + " during {}ms ({})", map.get(size).getMean(),
        //                        durationToString(Math.round(map.get(size).getMean())));
        //            }
    }

    logger.info("=================================================");
    logger.info("Min nb of buffering: {}", nbBufferingNotFree.getMin());
    logger.info("Max nb of buffering: {}", nbBufferingNotFree.getMax());
    logger.info("Avg nb of buffering:  {}", nbBufferingNotFree.getMean());
    logger.info("percent of nonbuffering:  {}", nbNBufferingNotFree.getMean());
    logger.info("Std nb of buffering:  {}", nbBufferingNotFree.getStandardDeviation());
    logger.info("=================================================");
    logger.info("Min waiting: {} ms ({})", statsWaitingNotFree.getMin(),
            durationToString(Math.round(statsWaitingNotFree.getMin())));
    logger.info("Max waiting: {} ms ({})", statsWaitingNotFree.getMax(),
            durationToString(Math.round(statsWaitingNotFree.getMax())));
    logger.info("Avg waiting:  {} ms ({})", statsWaitingNotFree.getMean(),
            durationToString(Math.round(statsWaitingNotFree.getMean())));
    logger.info("Avg waiting (free):  {} ms ({})", statsWaitingFree.getMean(),
            durationToString(Math.round(statsWaitingFree.getMean())));
    logger.info("Std of waiting:  {} ms ({})", statsWaitingNotFree.getStandardDeviation(),
            durationToString(Math.round(statsWaitingNotFree.getStandardDeviation())));
    logger.info("=================================================");
    logger.info("Min jumpTime : {} ms ({})", jumpForwardStats.getMin(),
            durationToString(Math.round(jumpForwardStats.getMin())));
    logger.info("Max jumpTime : {} ms ({})", jumpForwardStats.getMax(),
            durationToString(Math.round(jumpForwardStats.getMax())));
    logger.info("Avg jumpTime : {} ms ({})", jumpForwardStats.getMean(),
            durationToString(Math.round(jumpForwardStats.getMean())));
    //        logger.info("=================================================");
    //        logger.info("Min nb of waiting: {}", nbWaiting.getMin());
    //        logger.info("Max nb of waiting: {}", nbWaiting.getMax());
    //        logger.info("Avg nb of waiting:  {}", nbWaiting.getMean());
    //        logger.info("Std nb of waiting:  {}",
    //                nbWaiting.getStandardDeviation());
    //        logger.info("=================================================");
    //        logger.info("Min nb of MisConnect: {}", nbMisConnect.getMin());
    //        logger.info("Max nb of MisConnect: {}", nbMisConnect.getMax());
    //        logger.info("Avg nb of MisConnect:  {}", nbMisConnect.getMean());
    //        logger.info("Std nb of MisConnect:  {}",
    //                nbMisConnect.getStandardDeviation());
    //        logger.info("Total nb of MisConnect:  {}",
    //                nbMisConnect.getN());
    logger.info("=================================================");
    logger.info("Total number of messages: {}", messages);
    logger.info("Total amount of traffic:  {} bytes", traffic);
    for (Map.Entry<Class<? extends RewriteableMsg>, ReceivedMessage> entry : messageHistogram.entrySet()) {
        logger.info("{}: #={}  \t bytes={}", new Object[] { String.format("%22s", entry.getKey().getName()),
                entry.getValue().getTotalCount(), entry.getValue().getTotalSize() });
    }
    logger.info("=================================================");

}

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  w  w  .  j ava  2 s .c  o  m

    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
 *///  w w w.  j  a v  a2 s . c  o  m
protected void calculateSummaryStats() {
    final IndexIterator iter = getIterator();
    final SummaryStatistics stats = new SummaryStatistics();

    while (iter.hasNext()) {
        final double val = getElementDoubleAbs(iter.index);
        if (Double.isInfinite(val) || Double.isNaN(val)) {
            continue;
        }

        stats.addValue(val);
    }

    // now all the calculations are done, add the values into store
    setStoredValue("stats", stats);
}

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

/**
 * Calculate summary statistics for a dataset along an axis
 *//* w ww. j  a v a2s .  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);
}

From source file:uk.ac.ebi.apps.benchmark.ChemicalNameSearch.java

private SummaryStatistics getHitIndices(Multimap<String, Set<String>> results, FingerprintEncoder encoder) {

    SummaryStatistics summaryStatistics = new SummaryStatistics();

    QUERY: for (String name : results.keySet()) {

        String normName = encoder.encode(name);

        StringBuffer buffer = new StringBuffer();

        List<Set<String>> hits = new ArrayList<Set<String>>(results.get(name));

        for (int i = 0; i < hits.size(); i++) {

            Set<String> hitNames = hits.get(i);

            for (String hit : hitNames) {

                String normHit = encoder.encode(hit);

                buffer.append("\t").append(hit);
                buffer.append("\t").append(normHit);
                buffer.append("\t").append(StringUtils.getLevenshteinDistance(normName, normHit));
                buffer.append("\n");

                if (normName.equals(normHit)) {
                    summaryStatistics.addValue(i + 1);
                    continue QUERY;
                }//from  w  w  w.  j  a  v a 2  s . c o  m

            }

        }

    }

    return summaryStatistics;

}