CovarianceMatricesAggregator implements Serializable { CovarianceMatricesAggregator plus(CovarianceMatricesAggregator other) { A.ensure(this.mean.equals(other.mean), "this.mean == other.mean"); return new CovarianceMatricesAggregator( mean, this.weightedSum.plus(other.weightedSum), this.rowCount + other.rowCount ); } CovarianceMatricesAggregator(Vector mean);   CovarianceMatricesAggregator(Vector mean, Matrix weightedSum, int rowCount); int rowCount();  }
@Test public void testPlus() { Vector mean = VectorUtils.of(1, 0); CovarianceMatricesAggregator agg1 = new CovarianceMatricesAggregator(mean, identity(2), 1); CovarianceMatricesAggregator agg2 = new CovarianceMatricesAggregator(mean, identity(2).times(2), 3); CovarianceMatricesAggregator res = agg1.plus(agg2); assertArrayEquals(mean.asArray(), res.mean().asArray(), 1e-4); assertArrayEquals(identity(2).times(3).getStorage().data(), res.weightedSum().getStorage().data(), 1e-4); assertEquals(4, res.rowCount()); }