@Test public void testReduce() { MeanWithClusterProbAggregator aggregator3 = new MeanWithClusterProbAggregator(); MeanWithClusterProbAggregator aggregator4 = new MeanWithClusterProbAggregator(); aggregator3.add(VectorUtils.of(1., 1.), 0.5); aggregator3.add(VectorUtils.of(0., 1.), 0.25); aggregator3.add(VectorUtils.of(1., 0.), 0.25); aggregator3.add(VectorUtils.of(0., 0.), 0.5); aggregator4.add(VectorUtils.of(1., 1.), 1.0); aggregator4.add(VectorUtils.of(0., 1.), 1.0); aggregator4.add(VectorUtils.of(1., 0.), 1.0); aggregator4.add(VectorUtils.of(0., 0.), 1.0); List<MeanWithClusterProbAggregator> res = MeanWithClusterProbAggregator.reduce( Arrays.asList(aggregator1, aggregator3), Arrays.asList(aggregator2, aggregator4) ); MeanWithClusterProbAggregator res1 = res.get(0); assertEquals(0.70, res1.clusterProb(), 1e-2); assertArrayEquals(new double[] {0.580, 0.491}, res1.mean().asArray(), 1e-2); MeanWithClusterProbAggregator res2 = res.get(1); assertEquals(0.68, res2.clusterProb(), 1e-2); assertArrayEquals(new double[] {0.50, 0.50}, res2.mean().asArray(), 1e-2); }
static List<MeanWithClusterProbAggregator> reduce(List<MeanWithClusterProbAggregator> l, List<MeanWithClusterProbAggregator> r) { A.ensure(l != null || r != null, "Both partitions cannot equal to null"); if (l == null || l.isEmpty()) return r; if (r == null || r.isEmpty()) return l; A.ensure(l.size() == r.size(), "l.size() == r.size()"); List<MeanWithClusterProbAggregator> res = new ArrayList<>(); for (int i = 0; i < l.size(); i++) res.add(l.get(i).plus(r.get(i))); return res; }
MeanWithClusterProbAggregator implements Serializable { static List<MeanWithClusterProbAggregator> reduce(List<MeanWithClusterProbAggregator> l, List<MeanWithClusterProbAggregator> r) { A.ensure(l != null || r != null, "Both partitions cannot equal to null"); if (l == null || l.isEmpty()) return r; if (r == null || r.isEmpty()) return l; A.ensure(l.size() == r.size(), "l.size() == r.size()"); List<MeanWithClusterProbAggregator> res = new ArrayList<>(); for (int i = 0; i < l.size(); i++) res.add(l.get(i).plus(r.get(i))); return res; } }
MeanWithClusterProbAggregator implements Serializable { static List<MeanWithClusterProbAggregator> reduce(List<MeanWithClusterProbAggregator> l, List<MeanWithClusterProbAggregator> r) { A.ensure(l != null || r != null, "Both partitions cannot equal to null"); if (l == null || l.isEmpty()) return r; if (r == null || r.isEmpty()) return l; A.ensure(l.size() == r.size(), "l.size() == r.size()"); List<MeanWithClusterProbAggregator> res = new ArrayList<>(); for (int i = 0; i < l.size(); i++) res.add(l.get(i).plus(r.get(i))); return res; } MeanWithClusterProbAggregator();   MeanWithClusterProbAggregator(Vector weightedXsSum, double pcxiSum, int rowCount); }
MeanWithClusterProbAggregator implements Serializable { static List<MeanWithClusterProbAggregator> reduce(List<MeanWithClusterProbAggregator> l, List<MeanWithClusterProbAggregator> r) { A.ensure(l != null || r != null, "Both partitions cannot equal to null"); if (l == null || l.isEmpty()) return r; if (r == null || r.isEmpty()) return l; A.ensure(l.size() == r.size(), "l.size() == r.size()"); List<MeanWithClusterProbAggregator> res = new ArrayList<>(); for (int i = 0; i < l.size(); i++) res.add(l.get(i).plus(r.get(i))); return res; } MeanWithClusterProbAggregator();   MeanWithClusterProbAggregator(Vector weightedXsSum, double pcxiSum, int rowCount); Vector mean(); double clusterProb(); static AggregatedStats aggreateStats(Dataset<EmptyContext, GmmPartitionData> dataset, int countOfComponents); }
MeanWithClusterProbAggregator implements Serializable { static List<MeanWithClusterProbAggregator> reduce(List<MeanWithClusterProbAggregator> l, List<MeanWithClusterProbAggregator> r) { A.ensure(l != null || r != null, "Both partitions cannot equal to null"); if (l == null || l.isEmpty()) return r; if (r == null || r.isEmpty()) return l; A.ensure(l.size() == r.size(), "l.size() == r.size()"); List<MeanWithClusterProbAggregator> res = new ArrayList<>(); for (int i = 0; i < l.size(); i++) res.add(l.get(i).plus(r.get(i))); return res; } MeanWithClusterProbAggregator();   MeanWithClusterProbAggregator(Vector weightedXsSum, double pcxiSum, int rowCount); Vector mean(); double clusterProb(); static AggregatedStats aggreateStats(Dataset<EmptyContext, GmmPartitionData> dataset, int countOfComponents);  }