List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
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 ww w. j a v a2 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)); } }
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()); }/*from ww w . j av a2 s . c o m*/ // 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:de.tudarmstadt.ukp.dkpro.core.performance.Stopwatch.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { super.collectionProcessComplete(); if (isDownstreamTimer()) { getLogger().info("Results from Timer '" + timerName + "' after processing all documents."); DescriptiveStatistics statTimes = new DescriptiveStatistics(); for (Long timeValue : times) { statTimes.addValue((double) timeValue / 1000); }/*w ww . j av a2s .c o m*/ double sum = statTimes.getSum(); double mean = statTimes.getMean(); double stddev = statTimes.getStandardDeviation(); StringBuilder sb = new StringBuilder(); sb.append("Estimate after processing " + times.size() + " documents."); sb.append("\n"); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Aggregated time: %,.1fs\n", sum); formatter.format("Time / Document: %,.3fs (%,.3fs)\n", mean, stddev); formatter.close(); getLogger().info(sb.toString()); if (outputFile != null) { try { Properties props = new Properties(); props.setProperty(KEY_SUM, "" + sum); props.setProperty(KEY_MEAN, "" + mean); props.setProperty(KEY_STDDEV, "" + stddev); OutputStream out = new FileOutputStream(outputFile); props.store(out, "timer " + timerName + " result file"); } catch (FileNotFoundException e) { throw new AnalysisEngineProcessException(e); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } }
From source file:algorithms.quality.JndRegionSize.java
@Override public double getQuality(Colormap2D colormap) { JndRegionComputer computer = new JndRegionComputer(colormap, sampling, 3.0); DescriptiveStatistics stats = new DescriptiveStatistics(); for (Point2D center : computer.getPoints()) { List<Point2D> poly = computer.getRegion(center); double area = computeArea(poly, center); stats.addValue(area); }// www. j ava 2 s . c om // TODO: find a better scaling factor return stats.getVariance() * 10000000.d; }
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 ww . j av a 2 s.c om 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:de.fhg.igd.iva.explorer.main.CompareViewPanel.java
private DescriptiveStatistics computeStats(ColormapQuality metric) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (Colormap cm : table.rowKeySet()) { double quality = table.get(cm, metric); stats.addValue(quality); }//from w w w . j a v a2s .c om return stats; }
From source file:com.caseystella.analytics.outlier.batch.rpca.RPCA.java
private double standardDeviation(double[][] x) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < x.length; i++) for (int j = 0; j < x[i].length; j++) stats.addValue(x[i][j]); return stats.getStandardDeviation(); }
From source file:com.caseystella.analytics.distribution.DistributionTest.java
@Test public void testQuantiles() { Random r = new Random(0); List<DataPoint> points = new ArrayList<>(); DescriptiveStatistics stats = new DescriptiveStatistics(); Distribution distribution = null;/*from w w w . j av a2 s . com*/ for (int i = 0; i < 100; ++i) { double val = r.nextDouble() * 1000; DataPoint dp = (new DataPoint(i, val, null, "foo")); points.add(dp); stats.addValue(val); if (distribution == null) { distribution = new Distribution(dp, ScalingFunctions.NONE, new GlobalStatistics()); } else { distribution.addDataPoint(dp, ScalingFunctions.NONE); } } double realMedian = stats.getPercentile(50); double approxMedian = distribution.getMedian(); System.out.println("mean and std dev: " + stats.getMean() + ", " + Math.sqrt(stats.getVariance())); System.out.println("Real : " + realMedian + ", approx: " + approxMedian); Assert.assertTrue(Math.abs(realMedian - approxMedian) < 5); }
From source file:com.tascape.reactor.report.SuiteResultView.java
private void processMetrics() { Map<String, Map<String, Object>> tm = new HashMap<>(); this.caseMetrics.forEach(row -> { String key = row.get(CaseResultMetric.METRIC_GROUP) + "." + row.get(CaseResultMetric.METRIC_NAME); Map<String, Object> r = tm.get(key); if (r == null) { tm.put(key, row);/*from w ww.j a v a2 s . c om*/ List<Double> values = new ArrayList<>(); values.add((double) row.get(CaseResultMetric.METRIC_VALUE)); row.put("values", values); } else { @SuppressWarnings("unchecked") List<Double> values = (List<Double>) r.get("values"); values.add((double) row.get(CaseResultMetric.METRIC_VALUE)); } }); tm.values().stream().forEach(row -> { @SuppressWarnings("unchecked") List<Double> values = (List<Double>) row.get("values"); if (values.size() > 1) { DescriptiveStatistics stats = new DescriptiveStatistics(); values.forEach(v -> stats.addValue(v)); row.put("max", stats.getMax()); row.put("min", stats.getMin()); row.put("mean", stats.getMean()); row.put("size", values.size()); } }); this.caseMetrics = new ArrayList<>(tm.values()); }
From source file:azkaban.metric.inmemoryemitter.InMemoryMetricEmitter.java
private DescriptiveStatistics getDescriptiveStatistics(final LinkedList<InMemoryHistoryNode> selectedLists) throws ClassCastException { DescriptiveStatistics descStats = new DescriptiveStatistics(); for (InMemoryHistoryNode node : selectedLists) { descStats.addValue(((Number) node.getValue()).doubleValue()); }//from w w w. ja v a 2s . c o m return descStats; }