GiniImpurityMeasureCalculator extends ImpurityMeasureCalculator<GiniImpurityMeasure> { int getLabelCode(double lb) { Integer code = lbEncoder.get(lb); assert code != null : "Can't find code for label " + lb; return code; } GiniImpurityMeasureCalculator(Map<Double, Integer> lbEncoder, boolean useIdx); @SuppressWarnings("unchecked") @Override StepFunction<GiniImpurityMeasure>[] calculate(DecisionTreeData data, TreeFilter filter, int depth);  }
@Test public void testGetLabelCode() { Map<Double, Integer> encoder = new HashMap<>(); encoder.put(0.0, 0); encoder.put(1.0, 1); encoder.put(2.0, 2); GiniImpurityMeasureCalculator calculator = new GiniImpurityMeasureCalculator(encoder, useIdx); assertEquals(0, calculator.getLabelCode(0.0)); assertEquals(1, calculator.getLabelCode(1.0)); assertEquals(2, calculator.getLabelCode(2.0)); }