@Test public void testMerge() throws Exception { CoMoment a = new CoMoment(); CoMoment b = new CoMoment(); CoMoment c = new CoMoment(); RandomGenerator r = RandomManager.getRandom(); for (int i = 0; i < 100; i++) { double r1 = r.nextDouble(); double r2 = r.nextDouble(); c.update(r1, r2); if (i % 2 == 0) { a.update(r1, r2); } else { b.update(r1, r2); } } assertEquals(c, a.merge(b)); assertEquals(c, b.merge(a)); }
public CoMoment merge(CoMoment cm) { long n = this.n + cm.n; double C = this.C + cm.C + (this.mx - cm.mx) * (this.my - cm.my) * this.n * cm.n / n; double mx = (this.n * this.mx + cm.n * cm.mx) / n; double my = (this.n * this.my + cm.n * cm.my) / n; return new CoMoment(mx, my, n, C); }
CoMoment { public CoMoment merge(CoMoment cm) { long n = this.n + cm.n; double C = this.C + cm.C + (this.mx - cm.mx) * (this.my - cm.my) * this.n * cm.n / n; double mx = (this.n * this.mx + cm.n * cm.mx) / n; double my = (this.n * this.my + cm.n * cm.my) / n; return new CoMoment(mx, my, n, C); } }
CoMoment { public CoMoment merge(CoMoment cm) { long n = this.n + cm.n; double C = this.C + cm.C + (this.mx - cm.mx) * (this.my - cm.my) * this.n * cm.n / n; double mx = (this.n * this.mx + cm.n * cm.mx) / n; double my = (this.n * this.my + cm.n * cm.my) / n; return new CoMoment(mx, my, n, C); } CoMoment();  CoMoment(double mx, double my, long n, double C); }
CoMoment { public CoMoment merge(CoMoment cm) { long n = this.n + cm.n; double C = this.C + cm.C + (this.mx - cm.mx) * (this.my - cm.my) * this.n * cm.n / n; double mx = (this.n * this.mx + cm.n * cm.mx) / n; double my = (this.n * this.my + cm.n * cm.my) / n; return new CoMoment(mx, my, n, C); } CoMoment();  CoMoment(double mx, double my, long n, double C); long getN(); double getCovariance(); double getMeanX(); void update(double x, double y); CoMoment merge(CoMoment cm); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString(); }
CoMoment { public CoMoment merge(CoMoment cm) { long n = this.n + cm.n; double C = this.C + cm.C + (this.mx - cm.mx) * (this.my - cm.my) * this.n * cm.n / n; double mx = (this.n * this.mx + cm.n * cm.mx) / n; double my = (this.n * this.my + cm.n * cm.my) / n; return new CoMoment(mx, my, n, C); } CoMoment();  CoMoment(double mx, double my, long n, double C); long getN(); double getCovariance(); double getMeanX(); void update(double x, double y); CoMoment merge(CoMoment cm); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString();  }