dice.tree.builder
Class TreeBuilder

java.lang.Object
  extended by dice.tree.builder.TreeBuilder

public class TreeBuilder
extends java.lang.Object

Build random decision trees. The usage of TreeBuilder is demostrated in dice.examples package.

Version:
0.000
Author:
Xiatian Zhang

Field Summary
static byte CBR_RDT
           
static byte CLASSIFICATION
           
protected  int clsSize
          The class number of the data.
protected  Instances insts
          The training data set.
protected  java.util.List<int[]> ions
          The instance ids belong to the nodes in current level
protected  java.util.List<Node> level
          Current level of nodes of the trees.
protected  int maxDeep
          The max depth of the tree.
protected  int maxS
          The max number of instances should be in a leaf node.
protected  java.util.Map<Node,Node> parents
          The parent nodes of the nodes in current level
protected  java.util.Random rd
          Random number generator.
static byte REGRESSION
           
protected  byte type
          The type indicate what kind of tree will be built.
 
Constructor Summary
TreeBuilder(long randomSeed, byte type)
          Create the object.
 
Method Summary
 Node build()
          Build a tree.
 Node[] buildTrees(int treeNum)
          Build trees.
 void clear()
          Clear the tree builder.
private  Leaf closeCBRNode(Node node, int[] ion)
          Close a node for multi-label classification.
private  Leaf closeClassificationNode(Node node, int[] ion)
          Close a node for classification.
private  Leaf closeNode(Node node, int[] ion)
          Close a node to the leaf node.
private  Leaf closeRegressionNode(Node node, int[] ion)
           
 int getClsSize()
           
 Instances getInstances()
          Get the training data set.
 int getMaxDeep()
           
 int getMaxS()
           
private  void incLevel(Node root)
          Build a level of a tree.
 void init()
          Initialize the tree builder.
private  int selectAttr(InnerNode node, InnerNode root, Instance inst)
          Randomly select a attribute.
 void setClsSize(int clsSize)
          Set the number of classes.
 void setInstances(Instances instances)
          Set the training data set.
 void setMaxDeep(int maxDeep)
          Set the max depth of the tree to build.
 void setMaxS(int maxS)
           
 void setRandomSeed(long randomSeed)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSIFICATION

public static final byte CLASSIFICATION
See Also:
type, Constant Field Values

REGRESSION

public static final byte REGRESSION
See Also:
type, Constant Field Values

CBR_RDT

public static final byte CBR_RDT
See Also:
type, Constant Field Values

rd

protected java.util.Random rd
Random number generator.


type

protected byte type
The type indicate what kind of tree will be built. 0: classification, 1: regression, 2: CBR-RDT


maxDeep

protected int maxDeep
The max depth of the tree. When an branch achieve the threshold, the branch will stop grow.


maxS

protected int maxS
The max number of instances should be in a leaf node. It is not a hard threshold. When a branch's number of instances are less than or equals to the property, the branch will stop grow.


clsSize

protected int clsSize
The class number of the data. Note, the class attributes can only in the tail of each instance attribute vector.


insts

protected Instances insts
The training data set.


level

protected java.util.List<Node> level
Current level of nodes of the trees.


ions

protected java.util.List<int[]> ions
The instance ids belong to the nodes in current level


parents

protected java.util.Map<Node,Node> parents
The parent nodes of the nodes in current level

Constructor Detail

TreeBuilder

public TreeBuilder(long randomSeed,
                   byte type)
Create the object.

Parameters:
randomSeed - Random seed.
type - The type of the tree builder.
Method Detail

setClsSize

public void setClsSize(int clsSize)
Set the number of classes.

Parameters:
clsSize - Number of classes.

getInstances

public Instances getInstances()
Get the training data set.

Returns:
the instances

setInstances

public void setInstances(Instances instances)
Set the training data set.

Parameters:
instances - the instances to set

getMaxDeep

public int getMaxDeep()
Returns:
the maxDeep

setMaxDeep

public void setMaxDeep(int maxDeep)
Set the max depth of the tree to build. Should be used after set a instances

Parameters:
maxDeep - the maxDeep to set

getMaxS

public int getMaxS()
Returns:
the maxS
See Also:
maxS

setMaxS

public void setMaxS(int maxS)
Parameters:
maxS -
See Also:
maxS

getClsSize

public int getClsSize()
Returns:
The number of classes.
See Also:
clsSize

setRandomSeed

public void setRandomSeed(long randomSeed)
Parameters:
randomSeed -

init

public void init()
Initialize the tree builder.


clear

public void clear()
Clear the tree builder.


buildTrees

public Node[] buildTrees(int treeNum)
Build trees.

Parameters:
treeNum - The number of trees to build.
Returns:

build

public Node build()
Build a tree.

Returns:

incLevel

private void incLevel(Node root)
Build a level of a tree.

Parameters:
root - The root of the tree. It is just used for attribute selection.

closeNode

private Leaf closeNode(Node node,
                       int[] ion)
Close a node to the leaf node.

Parameters:
node - The node to be closed.
ion - The instance ids on the node.
Returns:
Leaf node.

closeClassificationNode

private Leaf closeClassificationNode(Node node,
                                     int[] ion)
Close a node for classification.

Parameters:
node - The node to be closed.
ion - The instance ids on the node.
Returns:
Leaf node.

closeRegressionNode

private Leaf closeRegressionNode(Node node,
                                 int[] ion)

closeCBRNode

private Leaf closeCBRNode(Node node,
                          int[] ion)
Close a node for multi-label classification.

Parameters:
node - The node to be closed.
ion - The instance ids on the node.
Returns:
Leaf node.

selectAttr

private int selectAttr(InnerNode node,
                       InnerNode root,
                       Instance inst)
Randomly select a attribute.

Parameters:
node -
root -
inst -
Returns: