FixedStreamFeatureStatistics implements StreamFeatureStatistics, Serializable { public void update(double feature) { this.count = this.count + 1; double delta = feature - this.mean; this.mean = this.mean + delta / this.count; this.m2 = this.m2 + delta * (feature - this.mean); }  void update(double feature); @Override Long getCount(); @Override Double getMean(); @Override Double getVariance(); @Override Double getStdDev(); @Override String toString();  }
@Test public void testUpdate() { Random random = new Random(); double expectedMean = 4.0; double stdDev = 6.0; int size = 10000; double[] features = new double[size]; for (int i = 0; i < size; i++) { features[i] = expectedMean + random.nextGaussian() * stdDev; } FixedStreamFeatureStatistics statistics = new FixedStreamFeatureStatistics(); for (int i = 0; i < size; i++) { statistics.update(features[i]); } assertEquals(expectedMean, statistics.getMean(), 0.1); assertEquals(stdDev, statistics.getStdDev(), 0.1); }