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

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

Introduction

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

Prototype

public double getMean() 

Source Link

Document

Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm"> arithmetic mean </a> of the available values

Usage

From source file:io.hops.experiments.results.compiler.RawBMResultAggregator.java

public static RawBMResults processSlaveResponses(Collection<Object> responses,
        RawBenchmarkCommand.Request request, Configuration args) {
    DescriptiveStatistics successfulOps = new DescriptiveStatistics();
    DescriptiveStatistics failedOps = new DescriptiveStatistics();
    DescriptiveStatistics speed = new DescriptiveStatistics();
    DescriptiveStatistics duration = new DescriptiveStatistics();
    DescriptiveStatistics noOfAliveNNs = new DescriptiveStatistics();
    for (Object obj : responses) {
        if (!(obj instanceof RawBenchmarkCommand.Response) || (obj instanceof RawBenchmarkCommand.Response
                && ((RawBenchmarkCommand.Response) obj).getPhase() != request.getPhase())) {
            throw new IllegalStateException("Wrong response received from the client");
        } else {//from  w w  w. j av a 2  s  . c o  m
            RawBenchmarkCommand.Response response = (RawBenchmarkCommand.Response) obj;
            successfulOps.addValue(response.getTotalSuccessfulOps());
            failedOps.addValue(response.getTotalFailedOps());
            speed.addValue(response.getOpsPerSec());
            duration.addValue(response.getRunTime());
            noOfAliveNNs.addValue(response.getNnCount());
        }
    }

    RawBMResults result = new RawBMResults(args.getNamenodeCount(), (int) Math.floor(noOfAliveNNs.getMean()),
            args.getNdbNodesCount(), request.getPhase(),
            (successfulOps.getSum() / ((duration.getMean() / 1000))), (duration.getMean() / 1000),
            (successfulOps.getSum()), (failedOps.getSum()));
    return result;
}

From source file:azkaban.metric.inmemoryemitter.InMemoryMetricEmitter.java

/**
 * filter snapshots using statistically significant points only
 * @param selectedLists list of snapshots
 *///from   w w w.  j ava2 s. c om
private void statBasedSelectMetricHistory(final LinkedList<InMemoryHistoryNode> selectedLists)
        throws ClassCastException {
    logger.debug("selecting snapshots which are far away from mean value");
    DescriptiveStatistics descStats = getDescriptiveStatistics(selectedLists);
    Double mean = descStats.getMean();
    Double std = descStats.getStandardDeviation();

    Iterator<InMemoryHistoryNode> ite = selectedLists.iterator();
    while (ite.hasNext()) {
        InMemoryHistoryNode currentNode = ite.next();
        double value = ((Number) currentNode.getValue()).doubleValue();
        // remove all elements which lies in 95% value band
        if (value < mean + standardDeviationFactor * std && value > mean - standardDeviationFactor * std) {
            ite.remove();
        }
    }
}

From source file:io.atomix.cluster.impl.PhiAccrualFailureDetector.java

/**
 * Computes the phi value from the given samples.
 * <p>//from w w w.j  a va 2  s .  c om
 * The original phi value in Hayashibara's paper is calculated based on a normal distribution.
 * Here, we calculate it based on an exponential distribution.
 *
 * @param samples       the samples from which to compute phi
 * @param lastHeartbeat the last heartbeat
 * @param currentTime   the current time
 * @return phi
 */
private double computePhi(DescriptiveStatistics samples, long lastHeartbeat, long currentTime) {
    long size = samples.getN();
    long t = currentTime - lastHeartbeat;
    return (size > 0) ? phiFactor * t / samples.getMean() : 100;
}

From source file:cc.kave.commons.pointsto.evaluation.TimeEvaluation.java

public void exportResults(Path outputDir, ResultExporter exporter) throws IOException {
    Function<Double, String> format = number -> String.format(Locale.US, "%.3f", number);
    exporter.export(outputDir.resolve("TimeStatistics.txt"),
            analysisStatistics.entrySet().stream().map(entry -> {
                DescriptiveStatistics stats = entry.getValue();
                return new String[] { entry.getKey(), format.apply(stats.getMin()),
                        format.apply(stats.getStandardDeviation()), format.apply(stats.getMean()),
                        format.apply(stats.getMax()) };
            }));/*from   w w  w .j av a  2  s  . c  om*/
    exporter.export(outputDir.resolve("StmtCountTimes.txt"),
            analysisTimes.stream()
                    .map(entry -> new String[] { entry.analysisName, entry.contextType.getFullName(),
                            Integer.toString(entry.numStmts), format.apply(entry.time) }));
}

From source file:io.hops.experiments.stats.TransactionStatsCumulative.java

private void writeStats(BufferedWriter writer, String transaction, String[] columns, File depthDir, int key)
        throws IOException {

    writer.write(key + " ");

    for (String cache : RESOLVING_CACHES) {
        File cacheDir = new File(depthDir, cache);
        Map<String, DescriptiveStatistics> stats = null;
        Map<String, DescriptiveStatistics> statsResolving = null;
        if (cacheDir.exists()) {
            stats = TransactionStatsAggregator.aggregate(new File(cacheDir, HOPSSTATS), transaction);
        }//from www  . j  a  v  a2s.  c  o  m

        if (isResolvingCache(cache)) {
            statsResolving = TransactionStatsAggregator.aggregate(new File(cacheDir, RESOLVING_CACHE_STATS),
                    "GET");
        }

        if (stats != null) {
            for (String col : columns) {
                DescriptiveStatistics st = stats.get(col);
                writer.write(st.getMin() + " " + st.getMean() + " " + st.getMax() + " ");
            }
        }

        if (statsResolving != null) {
            for (String col : RESOLVING_CACHE_COLUMNS) {
                DescriptiveStatistics st = statsResolving.get(col);
                writer.write(st.getMin() + " " + st.getMean() + " " + st.getMax() + " ");
            }
        }
    }

    writer.newLine();
}

From source file:io.yields.math.framework.DomainTest.java

@Explore(name = "Test Variable Distribution", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class)
@Exploration(name = "Test Function", context = FunctionExplorerContext.class, group = "domain")
public void testVariableDistribution(Explorer<Double> explorer) {

    assertThat(explorer.all().count()).isEqualTo(explorer.valid().count());
    assertThat(explorer.valid().count()).isEqualTo(explorer.valid().count());
    assertThat(explorer.invalid().count()).isEqualTo(0);
    assertThat(explorer.propertyError().count()).isEqualTo(0);

    DescriptiveStatistics stats = new DescriptiveStatistics();
    explorer.all().forEach(result -> stats.addValue(result.getFunctionOutcome().orElse(0d)));

    assertThat(stats.getMean()).isEqualTo(0, delta(0.1));
    assertThat(stats.getMax()).isEqualTo(1, delta(0.1));
    assertThat(stats.getMin()).isEqualTo(-1, delta(0.1));
}

From source file:io.yields.math.framework.DomainTest.java

@Explore(name = "Test Variable Distribution with multiple properties", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class)
@Exploration(name = "Test Function", context = FunctionExplorerMultiplePropertiesContext.class, group = "domain")
public void testVariableDistributionMultipleProperties(Explorer<Double> explorer) {

    assertThat(explorer.all().count()).isEqualTo(explorer.valid().count());
    assertThat(explorer.valid().count()).isEqualTo(explorer.valid().count());
    assertThat(explorer.invalid().count()).isEqualTo(0);
    assertThat(explorer.propertyError().count()).isEqualTo(0);

    DescriptiveStatistics stats = new DescriptiveStatistics();
    explorer.all().forEach(result -> stats.addValue(result.getFunctionOutcome().orElse(0d)));

    assertThat(stats.getMean()).isEqualTo(0, delta(0.1));
    assertThat(stats.getMax()).isEqualTo(1, delta(0.1));
    assertThat(stats.getMin()).isEqualTo(-1, delta(0.1));
}

From source file:io.realm.datastorebenchmark.DataStoreTest.java

public void saveMeasurements(String filePrefix) {
    String tag = getTag();/* w ww .  j av  a  2  s.co m*/
    try {
        // one file per test with raw data
        for (String key : keys) {
            File file1 = new File(Environment.getExternalStorageDirectory() + "/datastorebenchmark",
                    tag + "_" + key + ".csv");
            FileOutputStream fileOutputStream1 = new FileOutputStream(file1, false);
            List<Long> measurement = measurements.get(key);
            for (int i = 0; i < measurement.size(); i++) {
                fileOutputStream1.write(String.format("%d\n", measurement.get(i).longValue()).getBytes());
            }
            fileOutputStream1.close();
        }

        // combined CSV file
        File file = new File(Environment.getExternalStorageDirectory() + "/datastorebenchmark",
                filePrefix + ".csv");
        FileOutputStream fileOutputStream = new FileOutputStream(file, true);
        fileOutputStream.write(String.format("%s;", tag).getBytes());
        for (String key : keys) {
            List<Long> measurement = measurements.get(key);
            double[] doubles = new double[measurement.size()];
            for (int i = 0; i < measurement.size(); i++) {
                doubles[i] = measurement.get(i).doubleValue();
            }
            Collections.sort(measurement);
            DescriptiveStatistics results = new DescriptiveStatistics(doubles);
            fileOutputStream.write(String
                    .format("%e;%e;%e;", results.getMin(), results.getMax(), results.getMean()).getBytes());
        }
        fileOutputStream.write("\n".getBytes());
        fileOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:mase.app.allocation.AllocationProblem.java

@Override
public EvaluationResult[] evaluateSolution(GroupController gc, long seed) {
    AgentController[] acs = gc.getAgentControllers(numAgents);
    RealMatrix distanceMatrix = new Array2DRowRealMatrix(numAgents, types.length);
    for (int i = 0; i < numAgents; i++) {
        AllocationAgent aa = (AllocationAgent) acs[i];
        for (int j = 0; j < types.length; j++) {
            distanceMatrix.setEntry(i, j, DIST.compute(aa.getLocation(), types[j]));
        }/*www.  ja  v  a  2 s  .  c  o  m*/
    }

    DescriptiveStatistics pd = pairDistances(distanceMatrix);

    // fitness
    FitnessResult fr = new FitnessResult(1 - pd.getMean() / FastMath.sqrt(dimensions));

    // individual characterisation -- distance to each type
    List<EvaluationResult> vbrs = new ArrayList<>();
    for (double[] dists : distanceMatrix.getData()) {
        vbrs.add(new VectorBehaviourResult(dists));
    }
    CompoundEvaluationResult ser = new CompoundEvaluationResult(vbrs);

    // aux characterisation -- min, mean, max, sd pair distances
    VectorBehaviourResult aux = new VectorBehaviourResult(pd.getMin(), pd.getMean(), pd.getMax(),
            pd.getStandardDeviation());

    return new EvaluationResult[] { fr, aux, ser };
}

From source file:io.yields.math.framework.DomainTest.java

@Explore(name = "Multiple Explorations", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class)
@Exploration(name = "Test Function", context = FunctionExplorerContext.class, group = "domain")
@Exploration(name = "Test Function 2", context = Function2ExplorerContext.class, group = "domain")
public void testMultipleExplorations(List<Explorer<Double>> explorers) {

    for (Explorer<Double> explorer : explorers) {

        assertThat(explorer.all().count()).isEqualTo(explorer.valid().count());
        assertThat(explorer.invalid().count()).isEqualTo(0);
        assertThat(explorer.propertyError().count()).isEqualTo(0);

        DescriptiveStatistics stats = new DescriptiveStatistics();
        explorer.all().forEach(result -> stats.addValue(result.getFunctionOutcome().orElse(0d)));

        assertThat(stats.getMean()).isEqualTo(0, delta(0.1));
        assertThat(stats.getMax()).isEqualTo(1, delta(0.1));
        assertThat(stats.getMin()).isEqualTo(-1, delta(0.1));

    }//from w  ww.j a  v a 2  s.  c om

    // compare 2 explorers
    Explorer<Double> firstExplorer = explorers.get(0);
    Explorer<Double> secondExplorer = explorers.get(1);

    List<PropertyVerifications<Double>> resultsOfFirstExplorer = firstExplorer.all()
            .collect(Collectors.toList());
    List<PropertyVerifications<Double>> resultsOfSecondExplorer = secondExplorer.all()
            .collect(Collectors.toList());

    for (int i = 0; i < resultsOfFirstExplorer.size(); i++) {
        assertThat(resultsOfFirstExplorer.get(i).getFunctionOutcome().orElse(0d))
                .isEqualTo(resultsOfSecondExplorer.get(i).getFunctionOutcome().orElse(0d), delta(2d));
    }

}