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

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

Introduction

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

Prototype

public double getMean() 

Source Link

Document

Returns the mean of the values that have been added.

Usage

From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Add the calculated process time-metrics to the simulation model
 * @param logTraces ArrayList the process instances
 *//*from  w w w  .  j  a  va  2 s  .  c  o  m*/
private void fillProcessHighLevelPN(ArrayList logTraces) {
    try {
        replayResult.calculateMetrics(logTraces, advancedSettings[0]);
        // add the arrival rate to the HighLevelProcess model
        double arrivalRate = (double) replayResult.getArrivalRate() * (double) timeDivider;
        SummaryStatistics arrivalStats = replayResult.getArrivalStats();

        HLGeneralDistribution dist = new HLGeneralDistribution(arrivalStats.getMean() / (double) timeDivider,
                arrivalStats.getMean() / (double) timeDivider,
                arrivalStats.getVariance() / (double) timeDivider, arrivalStats.getMin() / (double) timeDivider,
                arrivalStats.getMax() / (double) timeDivider, arrivalRate,
                HLDistribution.DistributionEnum.EXPONENTIAL_DISTRIBUTION);

        highLevelPN.getHLProcess().getGlobalInfo().setCaseGenerationScheme(dist);
        // set the time unit of the HighLevelProcess model
        // different time strings: "milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "years"
        if (timeSort.equals("milliseconds")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.MILLISECONDS);
        } else if (timeSort.equals("seconds")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.SECONDS);
        } else if (timeSort.equals("minutes")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.MINUTES);
        } else if (timeSort.equals("hours")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.HOURS);
        } else if (timeSort.equals("days")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.DAYS);
        } else if (timeSort.equals("weeks")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.WEEKS);
        } else if (timeSort.equals("months")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.MONTHS);
        } else if (timeSort.equals("years")) {
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.YEARS);
        } else {
            // use default value
            highLevelPN.getHLProcess().getGlobalInfo().setTimeUnit(HLTypes.TimeUnit.HOURS);
        }
    } catch (Exception e) {
        Message.add("Program exception while calculating proces performance metrics for the "
                + "simulation model:\n" + e.toString(), 2);
        e.printStackTrace();

    }
}

From source file:rapture.stat.memory.ValueMemoryType.java

@Override
public boolean calculate() {
    if (System.currentTimeMillis() > nextRecord) {
        ValueStat v = new ValueStat();
        v.setKey(key);//from   w ww .  j av a 2  s. c  o m
        if (workingValues.isEmpty()) {
            v.setValue(0.0);
        } else {
            SummaryStatistics summary = new SummaryStatistics();
            synchronized (workingValues) {
                for (ValueStat vs : workingValues) {
                    summary.addValue(vs.getValue());
                }
            }
            switch (operation) {
            case AVERAGE:
                v.setValue(summary.getMean());
                break;
            case SUM:
                v.setValue(summary.getSum());
                break;
            }
        }
        history.add(v);
        nextRecord = nextExtractionTime();
        return true;
    }
    return false;
}

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   www  .j a va2  s  .  com*/
        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 www  .j  a  v  a2  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.AbstractCompoundDataset.java

@Override
public Number rootMeanSquare() {
    if (storedValues == null) {
        calculateSummaryStats();/*from w  w w.ja  v a  2s  .  c  o  m*/
    }

    double result = 0;
    for (int i = 0; i < isize; i++) {
        final SummaryStatistics stats = (SummaryStatistics) storedValues.get("stats-" + i);
        final double mean = stats.getMean();
        result += stats.getVariance() + mean * mean;
    }
    return Math.sqrt(result);
}

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  a 2s .  co 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.diamond.scisoft.analysis.dataset.AbstractDataset.java

/**
 * @return root mean square/*w  w  w  .  j ava2 s.  c o m*/
 */
public Number rootMeanSquare() {
    final SummaryStatistics stats = getStatistics();
    final double mean = stats.getMean();
    return Math.sqrt(stats.getVariance() + mean * mean);
}

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

@Override
public Object mean() {
    if (storedValues == null) {
        calculateSummaryStats();/*from w  ww.ja v a2  s . com*/
    }

    final SummaryStatistics rstats = (SummaryStatistics) storedValues.get("stats-0");
    final SummaryStatistics istats = (SummaryStatistics) storedValues.get("stats-1");
    return new Complex(rstats.getMean(), istats.getMean());
}

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

public void testMultiple() {

    System.out.println("Testing multiple");

    Map<Class, NameService> services = new LinkedHashMap<Class, NameService>();

    StringBuilder sb = new StringBuilder("Combined: ");
    for (String serviceName : getCommandLine().getOptionValues("service")) {
        sb.append(serviceName).append(", ");
        NameService service = getNameService(serviceName);
        service.startup();/*from   ww w .j a va  2s . c o m*/
        services.put(service.getIdentifier().getClass(), service);
    }

    boolean greedy = has("g");

    Multimap<String, Identifier> results = ArrayListMultimap.create();

    long searchStart = System.currentTimeMillis();
    for (String name : names) {
        boolean foundHit = false;
        for (NameService service : services.values()) {

            Collection hits = service.searchName(name, has("a"));
            results.putAll(name, hits);
            if (!hits.isEmpty()) {
                if (!foundHit) {
                    found++;
                    foundHit = true;
                }
                if (!greedy)
                    break;
            }

        }
    }
    long searchEnd = System.currentTimeMillis();

    Long searchTime = (searchEnd - searchStart);

    Multimap<String, Set<String>> nameResults = ArrayListMultimap.create();

    long resolveStart = System.currentTimeMillis();
    for (Map.Entry<String, Identifier> e : results.entries()) {
        Identifier id = e.getValue();
        nameResults.put(e.getKey(), new HashSet<String>(services.get(id.getClass()).getNames(id)));
    }
    long resolveEnd = System.currentTimeMillis();

    Long resolveTime = resolveEnd - resolveStart;

    int trueFound = getRealScore(nameResults, new ChemicalFingerprintEncoder(), null);

    SummaryStatistics statistics = getHitIndices(nameResults, new ChemicalFingerprintEncoder());

    String[] row = new String[] { sb.toString(), searchTime.toString(), resolveTime.toString(),
            Integer.toString(found), Integer.toString(trueFound), Double.toString(statistics.getMax()),
            Double.toString(statistics.getMean()), Double.toString(statistics.getStandardDeviation()) };

    System.out.println(Joiner.on("\t").join(row));

}

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

@Override
public void process() {

    loadNames();//from   w  ww  .  ja v  a  2s .c o m

    if (getCommandLine().getOptionValues("s").length > 1) {
        testMultiple();
        return;
    }

    final NameService<Identifier> service = (NameService<Identifier>) getNameService(get("service", "none"));
    if (!service.startup()) {
        LOGGER.error("Unable to start service");
    }
    service.setMaxResults(100);

    Multimap<String, Identifier> results = ArrayListMultimap.create();

    // doing the search
    long searchStart = System.currentTimeMillis();
    for (String name : names) {
        Collection<? extends Identifier> hits = service.searchName(name, has("a"));
        results.putAll(name, hits);
        found += hits.isEmpty() ? 0 : 1;
    }
    long searchEnd = System.currentTimeMillis();

    Long searchTime = (searchEnd - searchStart);

    Multimap<String, Set<String>> nameResults = ArrayListMultimap.create();

    // resolving

    System.out.println("Transforming for performance test");

    long resolveStart = System.currentTimeMillis();
    for (Map.Entry<String, Identifier> e : results.entries()) {
        Identifier id = e.getValue();
        nameResults.put(e.getKey(), new HashSet<String>(service.getNames(id)));
    }
    long resolveEnd = System.currentTimeMillis();

    Long resolveTime = (resolveEnd - resolveStart);

    int trueFound = getRealScore(nameResults, new ChemicalFingerprintEncoder(), null);

    SummaryStatistics statistics = getHitIndices(nameResults, new ChemicalFingerprintEncoder());

    String[] row = new String[] { get("service", "unknown"), searchTime.toString(), resolveTime.toString(),
            Integer.toString(found), Integer.toString(trueFound), Double.toString(statistics.getMax()),
            Double.toString(statistics.getMean()), Double.toString(statistics.getStandardDeviation()) };

    System.out.println(Joiner.on("\t").join(row));

}