NewComponentStatisticsAggregator implements Serializable { void add(Vector x, boolean isAnomaly) { if (isAnomaly) { if (sumOfAnomalies == null) sumOfAnomalies = x.copy(); else sumOfAnomalies = sumOfAnomalies.plus(x); rowCountForNewCluster += 1; } totalRowCount += 1; } NewComponentStatisticsAggregator(long totalRowCount, long rowCountForNewCluster, Vector sumOfAnomalies);  NewComponentStatisticsAggregator(); Vector mean(); long rowCountForNewCluster(); long totalRowCount();  }
@Test public void testAdd() { NewComponentStatisticsAggregator agg = new NewComponentStatisticsAggregator(); int rowCount = 10; for (int i = 0; i < rowCount; i++) agg.add(VectorUtils.of(0, 1, 2), i % 2 == 0); assertEquals(rowCount / 2, agg.rowCountForNewCluster()); assertEquals(rowCount, agg.totalRowCount()); assertArrayEquals(new double[] {0, 1, 2}, agg.mean().asArray(), 1e-4); }