@Test public void testImpurityRightPart() { long[] left = new long[]{0, 0, 0}; long[] right = new long[]{3, 0, 0}; GiniImpurityMeasure impurity = new GiniImpurityMeasure(left, right); assertEquals(-3, impurity.impurity(), 1e-10); }
@Override public double impurity() { long leftCnt = 0; long rightCnt = 0; double leftImpurity = 0; double rightImpurity = 0; for (long e : left) leftCnt += e; for (long e : right) rightCnt += e; if (leftCnt > 0) for (long e : left) leftImpurity += Math.pow(e, 2) / leftCnt; if (rightCnt > 0) for (long e : right) rightImpurity += Math.pow(e, 2) / rightCnt; return -(leftImpurity + rightImpurity); }
GiniImpurityMeasure implements ImpurityMeasure<GiniImpurityMeasure> { @Override public double impurity() { long leftCnt = 0; long rightCnt = 0; double leftImpurity = 0; double rightImpurity = 0; for (long e : left) leftCnt += e; for (long e : right) rightCnt += e; if (leftCnt > 0) for (long e : left) leftImpurity += Math.pow(e, 2) / leftCnt; if (rightCnt > 0) for (long e : right) rightImpurity += Math.pow(e, 2) / rightCnt; return -(leftImpurity + rightImpurity); } }
GiniImpurityMeasure implements ImpurityMeasure<GiniImpurityMeasure> { @Override public double impurity() { long leftCnt = 0; long rightCnt = 0; double leftImpurity = 0; double rightImpurity = 0; for (long e : left) leftCnt += e; for (long e : right) rightCnt += e; if (leftCnt > 0) for (long e : left) leftImpurity += Math.pow(e, 2) / leftCnt; if (rightCnt > 0) for (long e : right) rightImpurity += Math.pow(e, 2) / rightCnt; return -(leftImpurity + rightImpurity); } GiniImpurityMeasure(long[] left, long[] right); }
GiniImpurityMeasure implements ImpurityMeasure<GiniImpurityMeasure> { @Override public double impurity() { long leftCnt = 0; long rightCnt = 0; double leftImpurity = 0; double rightImpurity = 0; for (long e : left) leftCnt += e; for (long e : right) rightCnt += e; if (leftCnt > 0) for (long e : left) leftImpurity += Math.pow(e, 2) / leftCnt; if (rightCnt > 0) for (long e : right) rightImpurity += Math.pow(e, 2) / rightCnt; return -(leftImpurity + rightImpurity); } GiniImpurityMeasure(long[] left, long[] right); @Override double impurity(); @Override GiniImpurityMeasure add(GiniImpurityMeasure b); @Override GiniImpurityMeasure subtract(GiniImpurityMeasure b); long[] getLeft(); long[] getRight(); }
GiniImpurityMeasure implements ImpurityMeasure<GiniImpurityMeasure> { @Override public double impurity() { long leftCnt = 0; long rightCnt = 0; double leftImpurity = 0; double rightImpurity = 0; for (long e : left) leftCnt += e; for (long e : right) rightCnt += e; if (leftCnt > 0) for (long e : left) leftImpurity += Math.pow(e, 2) / leftCnt; if (rightCnt > 0) for (long e : right) rightImpurity += Math.pow(e, 2) / rightCnt; return -(leftImpurity + rightImpurity); } GiniImpurityMeasure(long[] left, long[] right); @Override double impurity(); @Override GiniImpurityMeasure add(GiniImpurityMeasure b); @Override GiniImpurityMeasure subtract(GiniImpurityMeasure b); long[] getLeft(); long[] getRight();  }