gov.sandia.cognition.learning.algorithm.tree
Class DecisionTree<InputType,OutputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.algorithm.tree.DecisionTree<InputType,OutputType>
Type Parameters:
InputType - The input type of the decision tree to evaluate
OutputType - The output type that the decision tree returns.
All Implemented Interfaces:
Evaluator<InputType,OutputType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
CategorizationTree, RegressionTree

public class DecisionTree<InputType,OutputType>
extends AbstractCloneableSerializable
implements Evaluator<InputType,OutputType>

The DecisionTree class implements a standard decision tree that is made up of DecisionTreeNode objects. It contains the root node of the tree plus the code that descends the decision tree to come up with a result value.

Since:
2.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  DecisionTreeNode<InputType,OutputType> rootNode
          The root node of the decision tree.
 
Constructor Summary
DecisionTree()
          Creates a new instance of DecisionTree.
DecisionTree(DecisionTreeNode<InputType,OutputType> rootNode)
          Creates a new instance of DecisionTree.
 
Method Summary
 OutputType evaluate(InputType input)
          Evaluates the decision tree against the given input.
 OutputType evaluateNode(InputType input, DecisionTreeNode<InputType,OutputType> node)
          Evaluates an input against the given node of a decision tree, using recursion to come up with the answer.
 DecisionTreeNode<InputType,OutputType> findTerminalNode(InputType input)
          Finds the terminal node for the given input.
 DecisionTreeNode<InputType,OutputType> findTerminalNode(InputType input, DecisionTreeNode<InputType,OutputType> node)
          Finds the terminal node for the given input, starting from the given node.
 DecisionTreeNode<InputType,OutputType> getRootNode()
          Gets the root node of the decision tree.
 void setRootNode(DecisionTreeNode<InputType,OutputType> rootNode)
          Sets the root node of the decision tree.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootNode

protected DecisionTreeNode<InputType,OutputType> rootNode
The root node of the decision tree.

Constructor Detail

DecisionTree

public DecisionTree()
Creates a new instance of DecisionTree.


DecisionTree

public DecisionTree(DecisionTreeNode<InputType,OutputType> rootNode)
Creates a new instance of DecisionTree.

Parameters:
rootNode - The root node of the tree.
Method Detail

evaluate

public OutputType evaluate(InputType input)
Evaluates the decision tree against the given input.

Specified by:
evaluate in interface Evaluator<InputType,OutputType>
Parameters:
input - The input to evaluate.
Returns:
The output of the decision tree for the given input.

evaluateNode

public OutputType evaluateNode(InputType input,
                               DecisionTreeNode<InputType,OutputType> node)
Evaluates an input against the given node of a decision tree, using recursion to come up with the answer.

Parameters:
input - The input to evaluate.
node - The node at which to evaluate.
Returns:
The output of the decision tree for the given input.

findTerminalNode

public DecisionTreeNode<InputType,OutputType> findTerminalNode(InputType input)
Finds the terminal node for the given input. The terminal node is the node in the tree that the input will use to produce an output. It is usually the case that it is a leaf node, but it is not required, since it may happen that the decision function finds a node that has no child for that input. In this case, this is the node returned.

Parameters:
input - The input to find the terminal node for.
Returns:
The terminal node for the input, starting from the root node.

findTerminalNode

public DecisionTreeNode<InputType,OutputType> findTerminalNode(InputType input,
                                                               DecisionTreeNode<InputType,OutputType> node)
Finds the terminal node for the given input, starting from the given node. The terminal node is the node in the tree that the input will use to produce an output. It is usually the case that it is a leaf node, but it is not required, since it may happen that the decision function finds a node that has no child for that input. In this case, this is the node returned.

Parameters:
input - The input to find the terminal node for.
node - The node to search from.
Returns:
The terminal node for the input, starting from the root node.

getRootNode

public DecisionTreeNode<InputType,OutputType> getRootNode()
Gets the root node of the decision tree.

Returns:
The root node of the decision tree.

setRootNode

public void setRootNode(DecisionTreeNode<InputType,OutputType> rootNode)
Sets the root node of the decision tree.

Parameters:
rootNode - The root node of the decision tree.