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

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

Introduction

In this page you can find the example usage for org.apache.commons.math3.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.calrissian.accumulorecipes.metricsstore.ext.stats.impl.AccumuloStatsMetricStoreTest.java

@Test
public void testStatisticAccuracy() throws Exception {
    AccumuloStatsMetricStore metricStore = new AccumuloStatsMetricStore(getConnector());

    Random random = new Random();

    List<Long> sampleData = asList((long) random.nextInt(10000), (long) random.nextInt(10000),
            (long) random.nextInt(10000), (long) random.nextInt(10000), (long) random.nextInt(10000));

    //use commons math as a
    SummaryStatistics sumStats = new SummaryStatistics();
    for (long num : sampleData)
        sumStats.addValue(num);/*from  w ww.ja  va  2 s . c o  m*/

    final long timestamp = System.currentTimeMillis();
    Iterable<Metric> testData = transform(sampleData, new Function<Long, Metric>() {
        @Override
        public Metric apply(Long num) {
            return new Metric(timestamp, "group", "type", "name", "", num);
        }
    });

    metricStore.save(testData);

    List<Stats> stats = newArrayList(metricStore.queryStats(new Date(0), new Date(), "group", "type", "name",
            MetricTimeUnit.MINUTES, new Auths()));

    assertEquals(1, stats.size());
    Stats stat = stats.get(0);

    assertEquals(sumStats.getMin(), stat.getMin(), Double.MIN_NORMAL);
    assertEquals(sumStats.getMax(), stat.getMax(), Double.MIN_NORMAL);
    assertEquals(sumStats.getSum(), stat.getSum(), Double.MIN_NORMAL);
    assertEquals(sumStats.getN(), stat.getCount(), Double.MIN_NORMAL);
    assertEquals(sumStats.getMean(), stat.getMean(), Double.MIN_NORMAL);
    assertEquals(sumStats.getPopulationVariance(), stat.getVariance(), 0.00000001);
    assertEquals(sumStats.getVariance(), stat.getVariance(true), 0.00000001);
    assertEquals(sqrt(sumStats.getPopulationVariance()), stat.getStdDev(), 0.00000001);
    assertEquals(sumStats.getStandardDeviation(), stat.getStdDev(true), 0.00000001);
}

From source file:org.cloudsimplus.migration.VmMigrationWhenCpuMetricIsViolatedExampleWithSelectedVm.java

/**
 * Computes the response time average for all finished Cloudlets on this
 * experiment./* w w w .  j  a  v  a  2 s . c o  m*/
 *
 * @return the response time average
 */
double getCloudletsResponseTimeAverage(DatacenterBroker broker) {
    SummaryStatistics cloudletResponseTime = new SummaryStatistics();

    broker.getCloudletsFinishedList().stream().map(c -> c.getFinishTime() - c.getLastDatacenterArrivalTime())
            .forEach(cloudletResponseTime::addValue);

    Log.printFormattedLine("\t\t\n Response Time simulation: %.2f \n Response Time contrato SLA: %.2f \n",
            cloudletResponseTime.getMean(), responseTimeSlaContract);
    return cloudletResponseTime.getMean();
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeMinimizationExperiment.java

/**
 * Computes the response time average for all finished Cloudlets
 * on this experiment.//from www .ja va  2s  .c  om
 * @return the response time average
 */
double getCloudletsResponseTimeAverage() {
    SummaryStatistics cloudletResponseTime = new SummaryStatistics();
    DatacenterBroker broker = getBrokerList().stream().findFirst().orElse(DatacenterBroker.NULL);
    broker.getCloudletsFinishedList().stream().map(c -> c.getFinishTime() - c.getLastDatacenterArrivalTime())
            .forEach(cloudletResponseTime::addValue);

    Log.printFormattedLine("\t\t\n Response Time simulation: %.2f \n Response Time contrato SLA: %.2f \n",
            cloudletResponseTime.getMean(), responseTimeSlaContract);
    return cloudletResponseTime.getMean();
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeMinimizationRunner.java

private void showConfidenceInterval(SummaryStatistics stats) {
    // Calculate 95% confidence interval
    double intervalSize = computeConfidenceErrorMargin(stats, 0.95);
    double lower = stats.getMean() - intervalSize;
    double upper = stats.getMean() + intervalSize;
    System.out.printf("\tResponse time mean 95%% Confidence Interval: %.2f  %.2f, that is [%.2f to %.2f]\n",
            stats.getMean(), intervalSize, lower, upper);
    System.out.printf("\tStandard Deviation: %.2f \n", stats.getStandardDeviation());
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeWorkLoadExperimet.java

/**
 * Computes the response time average for all finished Cloudlets on this
 * experiment./*  w  w  w .  ja  v  a  2  s . c  om*/
 *
 * @return the response time average
 */
double getCloudletsResponseTimeAverage() {
    SummaryStatistics cloudletResponseTime = new SummaryStatistics();
    DatacenterBroker broker = getBrokerList().stream().findFirst().orElse(DatacenterBroker.NULL);
    broker.getCloudletsFinishedList().stream().map(c -> c.getFinishTime() - c.getLastDatacenterArrivalTime())
            .forEach(cloudletResponseTime::addValue);

    /* Log.printFormattedLine(
        "\t\t\n Response Time simulation: %.2f \n Response Time contrato SLA: %.2f \n",
        cloudletResponseTime.getMean(), responseTimeSlaContract);*/
    return cloudletResponseTime.getMean();
}

From source file:org.cloudsimplus.testbeds.heuristics.DatacenterBrokerHeuristicRunner.java

@Override
protected void printFinalResults(String metricName, SummaryStatistics stats) {
    System.out.printf("\n# %s for %d simulation runs\n", metricName, getNumberOfSimulationRuns());

    if (!simulationRunsAndNumberOfBatchesAreCompatible()) {
        System.out.println(/*  w w w.  ja v  a  2  s.co m*/
                "\tBatch means method was not be applied because the number of simulation runs is not greater than the number of batches.");
    }
    System.out.printf("\tRound-robin solution used by DatacenterBrokerSimple - Cost: %.2f\n",
            roundRobinSolution.getCost());

    if (getNumberOfSimulationRuns() > 1) {
        System.out.printf("\tHeuristic solutions - Mean cost: %.2f Std. Dev.: %.2f\n", stats.getMean(),
                stats.getStandardDeviation());
        showConfidenceInterval(stats);
        System.out.printf(
                "\n\tThe mean cost of heuristic solutions represent %.2f%% of the Round-robin mapping used by the DatacenterBrokerSimple\n",
                heuristicSolutionCostPercentageOfRoundRobinSolution(stats.getMean()));
        System.out.printf("Experiment execution mean time: %.2f seconds\n", runtimeStats.getMean());
    }
}

From source file:org.cloudsimplus.testbeds.heuristics.DatacenterBrokerHeuristicRunner.java

private void showConfidenceInterval(SummaryStatistics stats) {
    // Calculate 95% confidence interval
    double intervalSize = computeConfidenceErrorMargin(stats, 0.95);
    double lower = stats.getMean() - intervalSize;
    double upper = stats.getMean() + intervalSize;
    System.out.printf("\tSolution cost mean 95%% Confidence Interval: %.2f  %.2f, that is [%.2f to %.2f]\n",
            stats.getMean(), intervalSize, lower, upper);
}

From source file:org.cloudsimplus.testbeds.linuxscheduler.CloudletSchedulerRunner.java

@Override
protected void printFinalResults(String metricName, SummaryStatistics stats) {
    System.out.printf("Results for metric %s\n", metricName);
    System.out.printf("  Mean Number of Cloudlets:         %.2f\n",
            cloudletsNumber.stream().mapToDouble(n -> n).average().orElse(0.0));
    System.out.printf("  Cloudlet Completion Time Avg:     %.2f | Std dev:      %.2f\n", stats.getMean(),
            stats.getStandardDeviation());
    System.out.printf("  Cloudlet Completion Min Avg Time: %.2f | Max avg time: %.2f\n", stats.getMin(),
            stats.getMax());//from   w w w  . ja v  a  2  s . c  o m
    System.out.println();
}

From source file:org.eclipse.dataset.AbstractCompoundDataset.java

@Override
public Number rootMeanSquare() {
    final String n = storeName(false, STORE_STATS_ITEM_NAME);
    if (isize < 1)
        return Double.NaN;
    if (getStoredValue(n + 0) == null) {
        calculateSummaryStats(false, false, n);
    }//from ww  w .ja  va 2 s  .c  om

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

From source file:org.eclipse.dataset.AbstractDataset.java

/**
 * Calculate summary statistics for a dataset along an axis
 * @param ignoreNaNs if true, ignore NaNs
 * @param ignoreInfs if true, ignore infinities
 * @param axis/*from  w w  w  .ja  v  a2 s .  c om*/
 */
protected void calculateSummaryStats(final boolean ignoreNaNs, final boolean ignoreInfs, 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);
    Dataset max = DatasetFactory.zeros(nshape, dtype);
    Dataset min = DatasetFactory.zeros(nshape, dtype);
    IntegerDataset maxIndex = new IntegerDataset(nshape);
    IntegerDataset minIndex = new IntegerDataset(nshape);
    Dataset sum = DatasetFactory.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();
        double amax = Double.NEGATIVE_INFINITY;
        double amin = Double.POSITIVE_INFINITY;
        boolean hasNaNs = false;
        if (ignoreNaNs) {
            for (int j = 0; j < alen; j++) {
                spos[axis] = j;
                final double val = getDouble(spos);

                if (Double.isNaN(val)) {
                    hasNaNs = true;
                    continue;
                } else if (ignoreInfs && Double.isInfinite(val)) {
                    continue;
                }

                if (val > amax) {
                    amax = val;
                }
                if (val < amin) {
                    amin = val;
                }

                stats.addValue(val);
            }
        } else {
            for (int j = 0; j < alen; j++) {
                spos[axis] = j;
                final double val = getDouble(spos);

                if (hasNaNs) {
                    if (!Double.isNaN(val))
                        stats.addValue(0);
                    continue;
                }

                if (Double.isNaN(val)) {
                    amax = Double.NaN;
                    amin = Double.NaN;
                    hasNaNs = true;
                } else if (ignoreInfs && Double.isInfinite(val)) {
                    continue;
                } else {
                    if (val > amax) {
                        amax = val;
                    }
                    if (val < amin) {
                        amin = val;
                    }
                }
                stats.addValue(val);
            }
        }

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

        max.setObjectAbs(qiter.index, amax);
        min.setObjectAbs(qiter.index, amin);
        boolean fmax = false;
        boolean fmin = false;
        if (hasNaNs) {
            if (ignoreNaNs) {
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final double val = getDouble(spos);
                    if (Double.isNaN(val))
                        continue;

                    if (!fmax && val == amax) {
                        maxIndex.setAbs(qiter.index, j);
                        fmax = true;
                        if (fmin)
                            break;
                    }
                    if (!fmin && val == amin) {
                        minIndex.setAbs(qiter.index, j);
                        fmin = true;
                        if (fmax)
                            break;
                    }
                }
            } else {
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final double val = getDouble(spos);
                    if (Double.isNaN(val)) {
                        maxIndex.setAbs(qiter.index, j);
                        minIndex.setAbs(qiter.index, j);
                        break;
                    }
                }
            }
        } else {
            for (int j = 0; j < alen; j++) {
                spos[axis] = j;
                final double val = getDouble(spos);
                if (!fmax && val == amax) {
                    maxIndex.setAbs(qiter.index, j);
                    fmax = true;
                    if (fmin)
                        break;
                }
                if (!fmin && val == amin) {
                    minIndex.setAbs(qiter.index, j);
                    fmin = true;
                    if (fmax)
                        break;
                }
            }
        }
        sum.setObjectAbs(qiter.index, stats.getSum());
        mean.setAbs(qiter.index, stats.getMean());
        var.setAbs(qiter.index, stats.getVariance());
    }
    setStoredValue(storeName(ignoreNaNs, ignoreInfs, STORE_COUNT + "-" + axis), count);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MAX + "-" + axis), max);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MIN + "-" + axis), min);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_SUM + "-" + axis), sum);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MEAN + "-" + axis), mean);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_VAR + "-" + axis), var);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MAX + STORE_INDEX + "-" + axis), maxIndex);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MIN + STORE_INDEX + "-" + axis), minIndex);
}