test_class.declarator: useIdx
test_class.modifier: @Parameterized.Parameter
      public
test_class.original_string: @Parameterized.Parameter
      public boolean useIdx;
test_class.type: boolean
test_class.var_name: useIdx
test_class.file: modules/ml/src/test/java/org/apache/ignite/ml/tree/impurity/gini/GiniImpurityMeasureCalculatorTest.java
test_class.identifier: GiniImpurityMeasureCalculatorTest
test_case.body: @Test
      public void testCalculateWithRepeatedData() {
          double[][] data = new double[][]{{0}, {1}, {2}, {2}, {3}};
          double[] labels = new double[]{0, 1, 1, 1, 1};
  
          Map<Double, Integer> encoder = new HashMap<>();
          encoder.put(0.0, 0);
          encoder.put(1.0, 1);
          GiniImpurityMeasureCalculator calculator = new GiniImpurityMeasureCalculator(encoder, useIdx);
  
          StepFunction<GiniImpurityMeasure>[] impurity = calculator.calculate(new DecisionTreeData(data, labels, useIdx), fs -> true, 0);
  
          assertEquals(1, impurity.length);
  
          // Check Gini calculated for the first column.
          assertArrayEquals(new double[]{Double.NEGATIVE_INFINITY, 0, 1, 2, 3}, impurity[0].getX(), 1e-10);
          assertEquals(-3.400, impurity[0].getY()[0].impurity(), 1e-3);
          assertEquals(-5.000, impurity[0].getY()[1].impurity(),1e-3);
          assertEquals(-4.000, impurity[0].getY()[2].impurity(),1e-3);
          assertEquals(-3.500, impurity[0].getY()[3].impurity(),1e-3);
          assertEquals(-3.400, impurity[0].getY()[4].impurity(),1e-3);
      }
test_case.class_method_signature: GiniImpurityMeasureCalculatorTest.testCalculateWithRepeatedData()
test_case.full_signature: @Test public void testCalculateWithRepeatedData()
test_case.identifier: testCalculateWithRepeatedData
test_case.invocations: put put calculate assertEquals assertArrayEquals getX assertEquals impurity getY assertEquals impurity getY assertEquals impurity getY assertEquals impurity getY assertEquals impurity getY
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCalculateWithRepeatedData()
focal_class.declarator: serialVersionUID = -522995134128519679L
focal_class.modifier: private static final
focal_class.original_string: private static final long serialVersionUID = -522995134128519679L;
focal_class.type: long
focal_class.var_name: serialVersionUID
focal_class.declarator: lbEncoder
focal_class.modifier: private final
focal_class.original_string: private final Map<Double, Integer> lbEncoder;
focal_class.type: Map<Double, Integer>
focal_class.var_name: lbEncoder
focal_class.file: modules/ml/src/main/java/org/apache/ignite/ml/tree/impurity/gini/GiniImpurityMeasureCalculator.java
focal_class.identifier: GiniImpurityMeasureCalculator
focal_class.class_method_signature: GiniImpurityMeasureCalculator.GiniImpurityMeasureCalculator(Map<Double, Integer> lbEncoder, boolean useIdx)
focal_class.full_signature: public  GiniImpurityMeasureCalculator(Map<Double, Integer> lbEncoder, boolean useIdx)
focal_class.identifier: GiniImpurityMeasureCalculator
focal_class.modifiers: public
focal_class.parameters: (Map<Double, Integer> lbEncoder, boolean useIdx)
focal_class.signature:  GiniImpurityMeasureCalculator(Map<Double, Integer> lbEncoder, boolean useIdx)
focal_class.class_method_signature: GiniImpurityMeasureCalculator.calculate(DecisionTreeData data, TreeFilter filter, int depth)
focal_class.full_signature: @SuppressWarnings("unchecked") @Override public StepFunction<GiniImpurityMeasure>[] calculate(DecisionTreeData data, TreeFilter filter, int depth)
focal_class.identifier: calculate
focal_class.modifiers: @SuppressWarnings("unchecked") @Override public
focal_class.parameters: (DecisionTreeData data, TreeFilter filter, int depth)
focal_class.return: StepFunction<GiniImpurityMeasure>[]
focal_class.signature: StepFunction<GiniImpurityMeasure>[] calculate(DecisionTreeData data, TreeFilter filter, int depth)
focal_class.class_method_signature: GiniImpurityMeasureCalculator.getLabelCode(double lb)
focal_class.full_signature:  int getLabelCode(double lb)
focal_class.identifier: getLabelCode
focal_class.parameters: (double lb)
focal_class.return: int
focal_class.signature: int getLabelCode(double lb)
focal_class.superclass: extends ImpurityMeasureCalculator<GiniImpurityMeasure>
focal_method.body: @SuppressWarnings("unchecked")
      @Override public StepFunction<GiniImpurityMeasure>[] calculate(DecisionTreeData data, TreeFilter filter, int depth) {
          TreeDataIndex idx = null;
          boolean canCalculate = false;
  
          if (useIdx) {
              idx = data.createIndexByFilter(depth, filter);
              canCalculate = idx.rowsCount() > 0;
          }
          else {
              data = data.filter(filter);
              canCalculate = data.getFeatures().length > 0;
          }
  
          if (canCalculate) {
              int rowsCnt = rowsCount(data, idx);
              int colsCnt = columnsCount(data, idx);
  
              StepFunction<GiniImpurityMeasure>[] res = new StepFunction[colsCnt];
  
              long right[] = new long[lbEncoder.size()];
              for (int i = 0; i < rowsCnt; i++) {
                  double lb = getLabelValue(data, idx, 0, i);
                  right[getLabelCode(lb)]++;
              }
  
              for (int col = 0; col < res.length; col++) {
                  if (!useIdx)
                      data.sort(col);
  
                  double[] x = new double[rowsCnt + 1];
                  GiniImpurityMeasure[] y = new GiniImpurityMeasure[rowsCnt + 1];
  
                  long[] left = new long[lbEncoder.size()];
                  long[] rightCp = Arrays.copyOf(right, right.length);
  
                  int xPtr = 0, yPtr = 0;
                  x[xPtr++] = Double.NEGATIVE_INFINITY;
                  y[yPtr++] = new GiniImpurityMeasure(
                      Arrays.copyOf(left, left.length),
                      Arrays.copyOf(rightCp, rightCp.length)
                  );
  
                  for (int i = 0; i < rowsCnt; i++) {
                      double lb = getLabelValue(data, idx, col, i);
                      left[getLabelCode(lb)]++;
                      rightCp[getLabelCode(lb)]--;
  
                      double featureVal = getFeatureValue(data, idx, col, i);
                      if (i < (rowsCnt - 1) && getFeatureValue(data, idx, col, i + 1) == featureVal)
                          continue;
  
                      x[xPtr++] = featureVal;
                      y[yPtr++] = new GiniImpurityMeasure(
                          Arrays.copyOf(left, left.length),
                          Arrays.copyOf(rightCp, rightCp.length)
                      );
                  }
  
                  res[col] = new StepFunction<>(Arrays.copyOf(x, xPtr), Arrays.copyOf(y, yPtr));
              }
  
              return res;
          }
  
          return null;
      }
focal_method.class_method_signature: GiniImpurityMeasureCalculator.calculate(DecisionTreeData data, TreeFilter filter, int depth)
focal_method.full_signature: @SuppressWarnings("unchecked") @Override public StepFunction<GiniImpurityMeasure>[] calculate(DecisionTreeData data, TreeFilter filter, int depth)
focal_method.identifier: calculate
focal_method.invocations: createIndexByFilter rowsCount filter getFeatures rowsCount columnsCount size getLabelValue getLabelCode sort size copyOf copyOf copyOf getLabelValue getLabelCode getLabelCode getFeatureValue getFeatureValue copyOf copyOf copyOf copyOf
focal_method.modifiers: @SuppressWarnings("unchecked") @Override public
focal_method.parameters: (DecisionTreeData data, TreeFilter filter, int depth)
focal_method.return: StepFunction<GiniImpurityMeasure>[]
focal_method.signature: StepFunction<GiniImpurityMeasure>[] calculate(DecisionTreeData data, TreeFilter filter, int depth)