AdaptiveStreamFeatureStatistics implements StreamFeatureStatistics, Serializable { public void update(double feature) { this.count++; this.features.add(feature); this.sum += feature; this.squaresSum += Math.pow(feature, 2); if (this.features.size() > maxSize) { double first = this.features.removeFirst(); this.sum -= first; this.squaresSum -= Math.pow(first, 2); } } AdaptiveStreamFeatureStatistics();  AdaptiveStreamFeatureStatistics(long maxSize); 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 = 3.0; int size = 10000; double[] features = new double[size]; for (int i = 0; i < size; i++) { features[i] = expectedMean + random.nextGaussian() * stdDev; } AdaptiveStreamFeatureStatistics statistics = new AdaptiveStreamFeatureStatistics(1000); for (int i = 0; i < size; i++) { statistics.update(features[i]); } assertEquals(expectedMean, statistics.getMean(), 0.3); assertEquals(stdDev, statistics.getStdDev(), 0.3); }