List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics clear
public void clear()
From source file:gdsc.utils.HSB_Picker.java
private void clear() { for (SummaryStatistics s : stats) s.clear(); updateDisplayedStatistics(); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SimpleStatistics.java
@Override public void run(CommandLine commandLine) throws Exception { String mode = null;/* w w w .j av a 2s .com*/ PrintStream out = null; List<double[][]> entries = new ArrayList<double[][]>(); SummaryStatistics statistics = new SummaryStatistics(); OptionCompleter completer = new OptionCompleter("minimum", "maximum", "average", "stdev", "count"); //load data from all input files for (String filename : commandLine.getArgs()) { entries.add(load(new File(filename))); } //validate the inputs if (entries.isEmpty()) { throw new IllegalArgumentException("requires at least one file"); } int numberOfRows = -1; int numberOfColumns = -1; for (int i = 0; i < entries.size(); i++) { if (numberOfRows == -1) { numberOfRows = entries.get(i).length; if (numberOfRows == 0) { throw new IllegalArgumentException("empty file: " + commandLine.getArgs()[i]); } } else if (numberOfRows != entries.get(i).length) { throw new IllegalArgumentException("unbalanced rows: " + commandLine.getArgs()[i]); } if (numberOfColumns == -1) { numberOfColumns = entries.get(i)[0].length; } else if (numberOfColumns != entries.get(i)[0].length) { throw new IllegalArgumentException("unbalanced columns: " + commandLine.getArgs()[i]); } } //setup the mode if (commandLine.hasOption("mode")) { mode = completer.lookup(commandLine.getOptionValue("mode")); if (mode == null) { throw new IllegalArgumentException("invalid mode"); } } else { mode = "average"; } try { //instantiate the writer if (commandLine.hasOption("output")) { out = new PrintStream(commandLine.getOptionValue("output")); } else { out = System.out; } //compute the statistics for (int i = 0; i < numberOfRows; i++) { for (int j = 0; j < numberOfColumns; j++) { statistics.clear(); for (int k = 0; k < entries.size(); k++) { double value = entries.get(k)[i][j]; if (Double.isInfinite(value) && commandLine.hasOption("maximum")) { value = Double.parseDouble(commandLine.getOptionValue("maximum")); } if ((Double.isInfinite(value) || Double.isNaN(value)) && commandLine.hasOption("ignore")) { // ignore infinity or NaN values } else { statistics.addValue(value); } } if (j > 0) { out.print(' '); } if (mode.equals("minimum")) { out.print(statistics.getMin()); } else if (mode.equals("maximum")) { out.print(statistics.getMax()); } else if (mode.equals("average")) { out.print(statistics.getMean()); } else if (mode.equals("stdev")) { out.print(statistics.getStandardDeviation()); } else if (mode.equals("count")) { out.print(statistics.getN()); } else { throw new IllegalArgumentException("unknown mode: " + mode); } } out.println(); } } finally { if ((out != null) && (out != System.out)) { out.close(); } } }
From source file:org.eclipse.january.metadata.internal.StatisticsMetadataImpl.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 ww . j ava 2 s.co m*/ */ @SuppressWarnings("deprecation") private Dataset[] createAxisStats(final int axis, final boolean ignoreNaNs, final boolean ignoreInfs) { int rank = dataset.getRank(); int[] oshape = dataset.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]; } Dataset max; Dataset min; IntegerDataset maxIndex; IntegerDataset minIndex; LongDataset count = DatasetFactory.zeros(LongDataset.class, nshape); Dataset sum; Dataset mean; Dataset var; if (isize == 1) { max = DatasetFactory.zeros(nshape, dtype); min = DatasetFactory.zeros(nshape, dtype); maxIndex = DatasetFactory.zeros(IntegerDataset.class, nshape); minIndex = DatasetFactory.zeros(IntegerDataset.class, nshape); sum = DatasetFactory.zeros(nshape, DTypeUtils.getLargestDType(dtype)); mean = DatasetFactory.zeros(DoubleDataset.class, nshape); var = DatasetFactory.zeros(DoubleDataset.class, nshape); } else { max = null; min = null; maxIndex = null; minIndex = null; sum = DatasetFactory.zeros(isize, nshape, DTypeUtils.getLargestDType(dtype)); mean = DatasetFactory.zeros(isize, CompoundDoubleDataset.class, nshape); var = DatasetFactory.zeros(isize, CompoundDoubleDataset.class, nshape); } IndexIterator qiter = count.getIterator(true); int[] qpos = qiter.getPos(); int[] spos = oshape.clone(); if (isize == 1) { DoubleDataset lmean = (DoubleDataset) mean; DoubleDataset lvar = (DoubleDataset) var; final SummaryStatistics stats = new SummaryStatistics(); 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]; } stats.clear(); //sum of logs is slow and we dont use it, so blocking its calculation here stats.setSumLogImpl(new NullStorelessUnivariateStatistic()); 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 = dataset.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 = dataset.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, stats.getN()); max.set(amax, qpos); min.set(amin, qpos); boolean fmax = false; boolean fmin = false; if (hasNaNs) { if (ignoreNaNs) { for (int j = 0; j < alen; j++) { spos[axis] = j; final double val = dataset.getDouble(spos); if (Double.isNaN(val)) continue; if (!fmax && val == amax) { // FIXME qiter.index is wrong!!! 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 = dataset.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 = dataset.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()); lmean.setAbs(qiter.index, stats.getMean()); lvar.setAbs(qiter.index, stats.getVariance()); } } else { CompoundDataset ldataset = (CompoundDataset) dataset; CompoundDoubleDataset lmean = (CompoundDoubleDataset) mean; CompoundDoubleDataset lvar = (CompoundDoubleDataset) var; double[] darray = new double[isize]; 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[isize]; for (int k = 0; k < isize; k++) { stats[k] = new SummaryStatistics(); } for (int j = 0; j < alen; j++) { spos[axis] = j; ldataset.getDoubleArray(darray, spos); boolean skip = false; for (int k = 0; k < isize; k++) { double v = darray[k]; if (ignoreNaNs && Double.isNaN(v)) { skip = true; break; } if (ignoreInfs && Double.isInfinite(v)) { skip = true; break; } } if (!skip) for (int k = 0; k < isize; k++) { stats[k].addValue(darray[k]); } } count.setAbs(qiter.index, (int) stats[0].getN()); for (int k = 0; k < isize; k++) { darray[k] = stats[k].getSum(); } sum.set(darray, qpos); for (int k = 0; k < isize; k++) { darray[k] = stats[k].getMean(); } lmean.setItem(darray, qpos); for (int k = 0; k < isize; k++) { darray[k] = stats[k].getVariance(); } lvar.setItem(darray, qpos); } } return new Dataset[] { max, min, maxIndex, minIndex, count, mean, sum, var }; }
From source file:org.lightjason.agentspeak.action.buildin.math.statistic.CClearStatistic.java
/** * clear a summary statistic// ww w .ja va 2 s .co m * * @param p_statistic statistic object * @return successful clear */ private static boolean apply(final SummaryStatistics p_statistic) { p_statistic.clear(); return true; }
From source file:org.lightjason.agentspeak.action.builtin.math.statistic.CClearStatistic.java
/** * clear a summary statistic//from w w w .j a v a 2s.c om * * @param p_statistic statistic object * @return successful clear */ private static boolean apply(@Nonnull final SummaryStatistics p_statistic) { p_statistic.clear(); return true; }