@Test public void statisticsOf3() { List<Statistics> list = new ArrayList<Statistics>(); for (int i = 0; i < 10; i++) { list.add(StatisticsUtil.statisticsOf(new ArrayDouble(i))); } Statistics stats = StatisticsUtil.statisticsOf(list); assertThat(stats.getAverage(), equalTo(4.5)); assertThat(stats.getStdDev(), equalTo(2.8722813232690143)); assertThat(stats.getRange().getMinimum(), equalTo(0.0)); assertThat(stats.getRange().getMaximum(), equalTo(9.0)); assertThat(stats.getCount(), equalTo(10)); }
public static Statistics statisticsOf(CollectionNumber data) { IteratorNumber iterator = data.iterator(); if (!iterator.hasNext()) { return null; } int count = 0; double min = iterator.nextDouble(); while (Double.isNaN(min)) { if (!iterator.hasNext()) { return null; } else { min = iterator.nextDouble(); } } double max = min; double total = min; double totalSquare = min*min; count++; while (iterator.hasNext()) { double value = iterator.nextDouble(); if (!Double.isNaN(value)) { if (value > max) max = value; if (value < min) min = value; total += value; totalSquare += value*value; count++; } } double average = total/count; double stdDev = Math.sqrt(totalSquare / count - average * average); return new StatisticsImpl(Ranges.range(min, max), count, average, stdDev); }
StatisticsUtil { public static Statistics statisticsOf(CollectionNumber data) { IteratorNumber iterator = data.iterator(); if (!iterator.hasNext()) { return null; } int count = 0; double min = iterator.nextDouble(); while (Double.isNaN(min)) { if (!iterator.hasNext()) { return null; } else { min = iterator.nextDouble(); } } double max = min; double total = min; double totalSquare = min*min; count++; while (iterator.hasNext()) { double value = iterator.nextDouble(); if (!Double.isNaN(value)) { if (value > max) max = value; if (value < min) min = value; total += value; totalSquare += value*value; count++; } } double average = total/count; double stdDev = Math.sqrt(totalSquare / count - average * average); return new StatisticsImpl(Ranges.range(min, max), count, average, stdDev); } }
StatisticsUtil { public static Statistics statisticsOf(CollectionNumber data) { IteratorNumber iterator = data.iterator(); if (!iterator.hasNext()) { return null; } int count = 0; double min = iterator.nextDouble(); while (Double.isNaN(min)) { if (!iterator.hasNext()) { return null; } else { min = iterator.nextDouble(); } } double max = min; double total = min; double totalSquare = min*min; count++; while (iterator.hasNext()) { double value = iterator.nextDouble(); if (!Double.isNaN(value)) { if (value > max) max = value; if (value < min) min = value; total += value; totalSquare += value*value; count++; } } double average = total/count; double stdDev = Math.sqrt(totalSquare / count - average * average); return new StatisticsImpl(Ranges.range(min, max), count, average, stdDev); }  }
StatisticsUtil { public static Statistics statisticsOf(CollectionNumber data) { IteratorNumber iterator = data.iterator(); if (!iterator.hasNext()) { return null; } int count = 0; double min = iterator.nextDouble(); while (Double.isNaN(min)) { if (!iterator.hasNext()) { return null; } else { min = iterator.nextDouble(); } } double max = min; double total = min; double totalSquare = min*min; count++; while (iterator.hasNext()) { double value = iterator.nextDouble(); if (!Double.isNaN(value)) { if (value > max) max = value; if (value < min) min = value; total += value; totalSquare += value*value; count++; } } double average = total/count; double stdDev = Math.sqrt(totalSquare / count - average * average); return new StatisticsImpl(Ranges.range(min, max), count, average, stdDev); }  static Statistics statisticsOf(CollectionNumber data); static Statistics statisticsOf(List<Statistics> data); static Statistics lazyStatisticsOf(CollectionNumber data); }
StatisticsUtil { public static Statistics statisticsOf(CollectionNumber data) { IteratorNumber iterator = data.iterator(); if (!iterator.hasNext()) { return null; } int count = 0; double min = iterator.nextDouble(); while (Double.isNaN(min)) { if (!iterator.hasNext()) { return null; } else { min = iterator.nextDouble(); } } double max = min; double total = min; double totalSquare = min*min; count++; while (iterator.hasNext()) { double value = iterator.nextDouble(); if (!Double.isNaN(value)) { if (value > max) max = value; if (value < min) min = value; total += value; totalSquare += value*value; count++; } } double average = total/count; double stdDev = Math.sqrt(totalSquare / count - average * average); return new StatisticsImpl(Ranges.range(min, max), count, average, stdDev); }  static Statistics statisticsOf(CollectionNumber data); static Statistics statisticsOf(List<Statistics> data); static Statistics lazyStatisticsOf(CollectionNumber data);  }