protected Node generateRandomTreeNode()

in samoa-api/src/main/java/org/apache/samoa/streams/generators/RandomTreeGenerator.java [216:260]


  protected Node generateRandomTreeNode(int currentDepth,
      ArrayList<Integer> nominalAttCandidates, double[] minNumericVals,
      double[] maxNumericVals, Random treeRand) {
    if ((currentDepth >= this.maxTreeDepthOption.getValue())
        || ((currentDepth >= this.firstLeafLevelOption.getValue()) && (this.leafFractionOption.getValue() >= (1.0 - treeRand
            .nextDouble())))) {
      Node leaf = new Node();
      leaf.classLabel = treeRand.nextInt(this.numClassesOption.getValue());
      return leaf;
    }
    Node node = new Node();
    int chosenAtt = treeRand.nextInt(nominalAttCandidates.size()
        + this.numNumericsOption.getValue());
    if (chosenAtt < nominalAttCandidates.size()) {
      node.splitAttIndex = nominalAttCandidates.get(chosenAtt);
      node.children = new Node[this.numValsPerNominalOption.getValue()];
      ArrayList<Integer> newNominalCandidates = new ArrayList<>(
          nominalAttCandidates);
      newNominalCandidates.remove(new Integer(node.splitAttIndex));
      newNominalCandidates.trimToSize();
      for (int i = 0; i < node.children.length; i++) {
        node.children[i] = generateRandomTreeNode(currentDepth + 1,
            newNominalCandidates, minNumericVals, maxNumericVals,
            treeRand);
      }
    } else {
      int numericIndex = chosenAtt - nominalAttCandidates.size();
      node.splitAttIndex = this.numNominalsOption.getValue()
          + numericIndex;
      double minVal = minNumericVals[numericIndex];
      double maxVal = maxNumericVals[numericIndex];
      node.splitAttValue = ((maxVal - minVal) * treeRand.nextDouble())
          + minVal;
      node.children = new Node[2];
      double[] newMaxVals = maxNumericVals.clone();
      newMaxVals[numericIndex] = node.splitAttValue;
      node.children[0] = generateRandomTreeNode(currentDepth + 1,
          nominalAttCandidates, minNumericVals, newMaxVals, treeRand);
      double[] newMinVals = minNumericVals.clone();
      newMinVals[numericIndex] = node.splitAttValue;
      node.children[1] = generateRandomTreeNode(currentDepth + 1,
          nominalAttCandidates, newMinVals, maxNumericVals, treeRand);
    }
    return node;
  }