Ejemplo n.º 1
0
 /* returns number of nodes in this subtree */
 public int nodeCount() {
   if (leaf) {
     return 1;
   } else {
     return 1 + leftChild.nodeCount() + rightChild.nodeCount();
   }
 }
Ejemplo n.º 2
0
 /* returns number of leaves in this subtree */
 public int leafCount() {
   if (leaf) {
     return 1;
   } else {
     return leftChild.leafCount() + rightChild.leafCount();
   }
 }
Ejemplo n.º 3
0
 /* Recursive, returns an array list
  * containing this node and all child nodes */
 public ArrayList<avPair> enumeratePairs() {
   ArrayList<avPair> myAV = new ArrayList<avPair>();
   if (leaf) {
     myAV.add(this);
     return myAV;
   } else {
     myAV.add(this);
     myAV.addAll(leftChild.enumeratePairs());
     myAV.addAll(rightChild.enumeratePairs());
     return myAV;
   }
 }
Ejemplo n.º 4
0
 /* The main tree traversal function; if node is a leaf,
  * return classification; otherwise, determine whether
  * instance is higher or lower than this attribute-value
  * pair and returns testInstance of proper child
  */
 public boolean testInstance(Instance in) {
   if (majority) {
     return majClass;
   }
   if (leaf) {
     return classification;
   } else {
     if (in.get((int) attribute) <= value) {
       return leftChild.testInstance(in);
     } else {
       return rightChild.testInstance(in);
     }
   }
 }