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

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

Introduction

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

Prototype

public double getMax() 

Source Link

Document

Returns the maximum of the available values

Usage

From source file:mase.me.MEGenerationalStat.java

@Override
public void postBreedingStatistics(EvolutionState state) {
    super.postBreedingStatistics(state);
    MESubpopulation pop = (MESubpopulation) state.population.subpops[0];
    DescriptiveStatistics fit = new DescriptiveStatistics();
    for (Individual ind : pop.map.values()) {
        fit.addValue(((ExpandedFitness) ind.fitness).getFitnessScore());
    }/*from w  ww  .ja  va 2 s  .  c o  m*/
    state.output.println(state.generation + " " + pop.map.keySet().size() + " " + pop.map.size() + " "
            + fit.getMin() + " " + fit.getMean() + " " + fit.getMax() + " " + pop.newInRepo, log);
    state.output.message("Repertoire size: " + pop.map.keySet().size() + " | New: " + pop.newInRepo
            + " | Avg. fitness: " + new DecimalFormat("0.0000").format(fit.getMean()));
}

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:com.intuit.tank.persistence.databases.BucketDataItemTest.java

/**
 * Run the DescriptiveStatistics getStats() method test.
 * //from   ww w  .ja va2 s .  com
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/10/14 10:32 AM
 */
@Test
public void testGetStats_1() throws Exception {
    BucketDataItem fixture = new BucketDataItem(1, new Date(), new DescriptiveStatistics());

    DescriptiveStatistics result = fixture.getStats();

    assertNotNull(result);
    assertEquals(
            "DescriptiveStatistics:\nn: 0\nmin: NaN\nmax: NaN\nmean: NaN\nstd dev: NaN\nmedian: NaN\nskewness: NaN\nkurtosis: NaN\n",
            result.toString());
    assertEquals(Double.NaN, result.getMax(), 1.0);
    assertEquals(Double.NaN, result.getVariance(), 1.0);
    assertEquals(Double.NaN, result.getMean(), 1.0);
    assertEquals(-1, result.getWindowSize());
    assertEquals(0.0, result.getSumsq(), 1.0);
    assertEquals(Double.NaN, result.getKurtosis(), 1.0);
    assertEquals(0.0, result.getSum(), 1.0);
    assertEquals(Double.NaN, result.getSkewness(), 1.0);
    assertEquals(Double.NaN, result.getPopulationVariance(), 1.0);
    assertEquals(Double.NaN, result.getStandardDeviation(), 1.0);
    assertEquals(Double.NaN, result.getGeometricMean(), 1.0);
    assertEquals(0L, result.getN());
    assertEquals(Double.NaN, result.getMin(), 1.0);
}

From source file:mase.spec.SpecialisationStats.java

@Override
public void postPreBreedingExchangeStatistics(EvolutionState state) {
    super.postPreBreedingExchangeStatistics(state);
    SpecialisationExchanger exc = (SpecialisationExchanger) state.exchanger;
    state.output.print(state.generation + " " + exc.metaPops.size(), log);

    // metapop size (min, mean, max)
    DescriptiveStatistics ds = new DescriptiveStatistics();
    for (MetaPopulation mp : exc.metaPops) {
        ds.addValue(mp.populations.size());
    }/*w w w.j  a  v  a 2s . com*/
    state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);

    // metapop dispersion (min, mean, max)
    ds.clear();
    for (MetaPopulation mp : exc.metaPops) {
        double dispersion = 0;
        for (Integer i : mp.populations) {
            for (Integer j : mp.populations) {
                dispersion += exc.distanceMatrix[i][j];
            }
        }
        ds.addValue(dispersion / (mp.populations.size() * mp.populations.size()));
    }
    state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);

    // total number of merges and splits
    int count = 0;
    for (MetaPopulation mp : exc.metaPops) {
        count += mp.waitingIndividuals.size();
    }
    state.output.print(" " + count + " " + exc.splits, log);

    for (int i = 0; i < exc.prototypeSubs.length; i++) {
        // MetaPop to which they belong
        MetaPopulation pop = null;
        for (int m = 0; m < exc.metaPops.size(); m++) {
            if (exc.metaPops.get(m).populations.contains(i)) {
                pop = exc.metaPops.get(m);
                state.output.print(" " + m, log);
            }
        }

        // Population dispersion
        state.output.print(" " + exc.originalMatrix[i][i], log);

        // Normalised distance to internal pops -- include itself -- 1
        ds.clear();
        for (Integer p : pop.populations) {
            ds.addValue(exc.distanceMatrix[i][p]);
        }
        state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);

        // Normalised distance to external pops
        ds.clear();
        for (MetaPopulation mp : exc.metaPops) {
            if (mp != pop) {
                for (Integer p : mp.populations) {
                    ds.addValue(exc.distanceMatrix[i][p]);
                }
            }
        }
        if (ds.getN() == 0) {
            ds.addValue(1);
        }
        state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);
    }

    String str = "";
    for (MetaPopulation mp : exc.metaPops) {
        str += mp + " ; ";
    }
    state.output.message(str);

    /*for(double[] m : exc.distanceMatrix) {
     state.output.message(Arrays.toString(m));
     }*/
    // representatives
    /*MetaEvaluator me = (MetaEvaluator) state.evaluator;
     MultiPopCoevolutionaryEvaluator2 baseEval = (MultiPopCoevolutionaryEvaluator2) me.getBaseEvaluator();
     Individual[][] elites = baseEval.getEliteIndividuals();
     ds.clear();
     for(MetaPopulation mp : exc.metaPops) {
     HashSet<Individual> inds = new HashSet<Individual>();
     for(Integer p : mp.populations) {
     inds.add(elites[p][0]);
     }
     ds.addValue(inds.size() / (double) mp.populations.size());
     }
     state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);*/
    state.output.println("", log);
}

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));

    }// w w  w.j av  a2  s  .  co  m

    // 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));
    }

}

From source file:com.soulgalore.web.pagesavings.reporters.XMLReporter.java

public void report(Set<SiteResult> results, Map<String, DescriptiveStatistics> statistics) {

    Date reportDate = new Date();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    Element root = new Element("savings");
    root.setAttribute("date", "" + reportDate);

    Element resultsXML = new Element("results");
    root.addContent(resultsXML);//  ww w. j  a va 2s  .co m

    Double totalPw = 0D;
    Double totalUnique = 0D;
    for (SiteResult siteResult : results) {
        totalPw += siteResult.getTotalSavings() * siteResult.getSite().getPageViews();
        totalUnique += siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers();
        Element site = new Element("site");
        Element url = new Element("url");
        Element weight = new Element("total-page-weight");
        Element savingsPerPage = new Element("savings-per-page");
        Element savingsForPW = new Element("savings-for-page-view");
        Element savingsForUnique = new Element("savings-for-unique-browsers");
        Element savingsPercentage = new Element("savings-percentage");

        url.addContent(new CDATA(siteResult.getSite().getUrl()));

        savingsPerPage.setAttribute(READABLE,
                humanReadableByteCount(Math.round(siteResult.getTotalSavings()), true));
        savingsPerPage.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings()));

        savingsForPW.setAttribute(READABLE, humanReadableByteCount(
                Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews()), true));
        savingsForPW.setAttribute(KB,
                "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews()));

        savingsForUnique.setAttribute(READABLE, humanReadableByteCount(
                Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers()), true));
        savingsForUnique.setAttribute(KB,
                "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers()));

        savingsPercentage.addContent("" + Math.round(siteResult.getSavingsPercentage() * 100) / 100.0d);

        weight.setAttribute(READABLE, humanReadableByteCount(siteResult.getTotalSizeBytes() / 1000, true));
        weight.setAttribute(KB, "" + siteResult.getTotalSizeBytes() / 1000);

        Element rulesSavings = new Element("rule-savings");
        for (RuleResult ruleResult : siteResult.getResults()) {
            Element rule = new Element(ruleResult.getRule());
            rule.addContent("" + ruleResult.getSavings());
            rulesSavings.addContent(rule);
        }

        site.addContent(url);
        site.addContent(weight);
        site.addContent(savingsPerPage);
        site.addContent(savingsForPW);
        site.addContent(savingsForUnique);
        site.addContent(savingsPercentage);
        site.addContent(rulesSavings);
        resultsXML.addContent(site);
    }

    Element summary = new Element("summary");
    summary.setAttribute("nrofsites", "" + results.size());
    Element totalPW = new Element("total-pw");
    Element totalUniqueSummary = new Element("total-unique");
    totalPW.setAttribute(READABLE, humanReadableByteCount(Math.round(totalPw), true));
    totalPW.setAttribute(KB, "" + Math.round(totalPw));
    totalUniqueSummary.setAttribute(READABLE, humanReadableByteCount(Math.round(totalUnique), true));
    totalUniqueSummary.setAttribute(KB, "" + Math.round(totalUnique));
    summary.addContent(totalPW);
    summary.addContent(totalUniqueSummary);

    for (String rule : statistics.keySet()) {
        DescriptiveStatistics stats = statistics.get(rule);
        Element ruleElement = new Element(rule);
        Element max = new Element("max");
        Element median = new Element("median");
        max.addContent("" + stats.getMax());
        median.addContent("" + stats.getPercentile(50));
        ruleElement.addContent(max);
        ruleElement.addContent(median);
        summary.addContent(ruleElement);
    }

    resultsXML.addContent(summary);

    Document doc = new Document(root);
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());

    try {
        FileWriter writer = new FileWriter("report-" + df.format(reportDate) + ".xml");
        outputter.output(doc, writer);
    } catch (Exception e) {
    }
}

From source file:mase.spec.HybridStat.java

@Override
public void postPreBreedingExchangeStatistics(EvolutionState state) {
    super.postPreBreedingExchangeStatistics(state);
    AbstractHybridExchanger exc = (AbstractHybridExchanger) state.exchanger;
    // generation, evaluations, and number of metapops
    state.output.print(state.generation + " " + ((MaseProblem) state.evaluator.p_problem).getTotalEvaluations()
            + " " + exc.metaPops.size(), log);

    DescriptiveStatistics ds = new DescriptiveStatistics();
    for (MetaPopulation mp : exc.metaPops) {
        ds.addValue(mp.agents.size());/* ww  w.j a v  a  2  s.  c om*/
    }
    // metapop size (min, mean, max)
    state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);

    // metapop mean and max age
    ds.clear();
    for (MetaPopulation mp : exc.metaPops) {
        ds.addValue(mp.age);
    }
    state.output.print(" " + ds.getMean() + " " + ds.getMax(), log);

    // number of splits and merges in this generation + total number of splits and merges
    totalMerges += exc.merges;
    totalSplits += exc.splits;
    state.output.print(" " + exc.merges + " " + exc.splits + " " + totalMerges + " " + totalSplits, log);

    if (exc instanceof StochasticHybridExchanger) {
        StochasticHybridExchanger she = (StochasticHybridExchanger) exc;
        // metapop difference to others
        ds.clear();
        for (int i = 0; i < she.distanceMatrix.length; i++) {
            for (int j = i + 1; j < she.distanceMatrix.length; j++) {
                if (!Double.isInfinite(she.distanceMatrix[i][j]) && !Double.isNaN(she.distanceMatrix[i][j])) {
                    ds.addValue(she.distanceMatrix[i][j]);
                }
            }
        }
        if (ds.getN() > 0) {
            state.output.print(" " + ds.getN() + " " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(),
                    log);
        } else {
            state.output.print(" 0 0 0 0", log);
        }

        //printMatrix(she.distanceMatrix, state);
    }

    state.output.println("", log);

    /*for(MetaPopulation mp : exc.metaPops) {
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("%3d", mp.age)).append(" - ").append(mp.toString());
    if(!mp.foreigns.isEmpty()) {
        sb.append(" - Foreigns:");
    }
    for(Foreign f : mp.foreigns) {
        sb.append(" ").append(f.origin).append("(").append(f.age).append(")");
    }
    state.output.message(sb.toString());
    }*/

    /*for(MetaPopulation mp : exc.metaPops) {
    state.output.message(mp.age + "/" + mp.lockDown);
    }*/
}

From source file:com.datatorrent.netlet.benchmark.util.BenchmarkResults.java

private String getResults() {
    DescriptiveStatistics statistics = getDescriptiveStatistics();
    final StringBuilder sb = new StringBuilder();
    sb.append("Iterations: ").append(statistics.getN());
    sb.append(" | Avg Time: ").append(fromNanoTime(statistics.getMean()));
    sb.append(" | Min Time: ").append(fromNanoTime(statistics.getMin()));
    sb.append(" | Max Time: ").append(fromNanoTime(statistics.getMax()));
    sb.append(" | 75% Time: ").append(fromNanoTime(statistics.getPercentile(75d)));
    sb.append(" | 90% Time: ").append(fromNanoTime(statistics.getPercentile(90d)));
    sb.append(" | 99% Time: ").append(fromNanoTime(statistics.getPercentile(99d)));
    sb.append(" | 99.9% Time: ").append(fromNanoTime(statistics.getPercentile(99.9d)));
    sb.append(" | 99.99% Time: ").append(fromNanoTime(statistics.getPercentile(99.99d)));
    sb.append(" | 99.999% Time: ").append(fromNanoTime(statistics.getPercentile(99.999d)));

    return sb.toString();

}

From source file:mase.stat.FitnessStat.java

/**
 * Prints out the statistics, but does not end with a println -- this lets
 * overriding methods print additional statistics on the same line
 */// ww w .j  av a 2 s  .  co m
@Override
public void postEvaluationStatistics(final EvolutionState state) {
    super.postEvaluationStatistics(state);

    int subpops = state.population.subpops.length; // number of supopulations
    DescriptiveStatistics[] fitness = new DescriptiveStatistics[subpops];
    for (int i = 0; i < subpops; i++) {
        fitness[i] = new DescriptiveStatistics();
    }
    int evals = state.evaluator.p_problem instanceof MaseProblem
            ? ((MaseProblem) state.evaluator.p_problem).getTotalEvaluations()
            : 0;

    // gather per-subpopulation statistics
    for (int x = 0; x < subpops; x++) {
        for (int y = 0; y < state.population.subpops[x].individuals.length; y++) {
            if (state.population.subpops[x].individuals[y].evaluated) {// he's got a valid fitness
                // update fitness
                double f = ((ExpandedFitness) state.population.subpops[x].individuals[y].fitness)
                        .getFitnessScore();
                bestSoFar[x] = Math.max(bestSoFar[x], f);
                absoluteBest = Math.max(absoluteBest, f);
                fitness[x].addValue(f);
            }
        }
        // print out fitness information
        if (doSubpops) {
            state.output.println(state.generation + " " + evals + " " + x + " " + fitness[x].getN() + " "
                    + fitness[x].getMin() + " " + fitness[x].getMean() + " " + fitness[x].getMax() + " "
                    + bestSoFar[x], statisticslog);
        }
    }

    // Now gather global statistics
    DescriptiveStatistics global = new DescriptiveStatistics();
    for (DescriptiveStatistics ds : fitness) {
        for (double v : ds.getValues()) {
            global.addValue(v);
        }
    }

    state.output.println(state.generation + " " + evals + " NA " + global.getN() + " " + global.getMin() + " "
            + global.getMean() + " " + global.getMax() + " " + absoluteBest, statisticslog);
}