Centroid extends WeightedVector { public void update(Vector v) { if (v instanceof Centroid) { Centroid c = (Centroid) v; update(c.delegate, c.getWeight()); } else { update(v, 1); } } Centroid(WeightedVector original);  Centroid(int key, Vector initialValue);  Centroid(int key, Vector initialValue, double weight); static Centroid create(int key, Vector initialValue); void update(Vector v); void update(Vector other, final double wy); @Override Centroid like(); @Deprecated int getKey(); void addWeight(double newWeight); @Override String toString(); @SuppressWarnings("CloneDoesntCallSuperClone") @Override Centroid clone();  }
@Test public void testUpdate() { MultiNormal f = new MultiNormal(20); Vector a = f.sample(); Vector b = f.sample(); Vector c = f.sample(); DenseVector x = new DenseVector(a); Centroid x1 = new Centroid(1, x); x1.update(new Centroid(2, new DenseVector(b))); Centroid x2 = new Centroid(x1); x1.update(c); Vector mean = a.plus(b).plus(c).assign(Functions.div(3)); assertEquals(0, x1.getVector().minus(mean).norm(1), 1.0e-8); assertEquals(3, x1.getWeight(), 0); assertEquals(0, x2.minus(a.plus(b).divide(2)).norm(1), 1.0e-8); assertEquals(2, x2.getWeight(), 0); assertEquals(0, new Centroid(x1.getIndex(), x1, x1.getWeight()).minus(x1).norm(1), 1.0e-8); assertEquals(0, x.minus(x1).norm(1), 0); assertEquals(3, x1.getWeight(), 1.0e-8); assertEquals(1, x1.getIndex()); }