MSEImpurityMeasure implements ImpurityMeasure<MSEImpurityMeasure> { @Override public MSEImpurityMeasure add(MSEImpurityMeasure b) { return new MSEImpurityMeasure( leftY + b.leftY, leftY2 + b.leftY2, leftCnt + b.leftCnt, rightY + b.rightY, rightY2 + b.rightY2, rightCnt + b.rightCnt ); } MSEImpurityMeasure(double leftY, double leftY2, long leftCnt, double rightY, double rightY2, long rightCnt); @Override double impurity(); @Override MSEImpurityMeasure add(MSEImpurityMeasure b); @Override MSEImpurityMeasure subtract(MSEImpurityMeasure b); double getLeftY(); double getLeftY2(); long getLeftCnt(); double getRightY(); double getRightY2(); long getRightCnt();  }
@Test public void testAdd() { Random rnd = new Random(0); MSEImpurityMeasure a = new MSEImpurityMeasure( rnd.nextDouble(), rnd.nextDouble(), rnd.nextInt(), rnd.nextDouble(), rnd.nextDouble(), rnd.nextInt() ); MSEImpurityMeasure b = new MSEImpurityMeasure( rnd.nextDouble(), rnd.nextDouble(), rnd.nextInt(), rnd.nextDouble(), rnd.nextDouble(), rnd.nextInt() ); MSEImpurityMeasure c = a.add(b); assertEquals(a.getLeftY() + b.getLeftY(), c.getLeftY(), 1e-10); assertEquals(a.getLeftY2() + b.getLeftY2(), c.getLeftY2(), 1e-10); assertEquals(a.getLeftCnt() + b.getLeftCnt(), c.getLeftCnt()); assertEquals(a.getRightY() + b.getRightY(), c.getRightY(), 1e-10); assertEquals(a.getRightY2() + b.getRightY2(), c.getRightY2(), 1e-10); assertEquals(a.getRightCnt() + b.getRightCnt(), c.getRightCnt()); }