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

java.lang.Object
  extended by gov.sandia.cognition.learning.algorithm.tree.AbstractDecisionTreeNode<InputType,OutputType,InteriorType>
Type Parameters:
InputType - The input type of the tree.
OutputType - The output type of the tree.
InteriorType - The output of the decision at this node.
All Implemented Interfaces:
DecisionTreeNode<InputType,OutputType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
CategorizationTreeNode, RegressionTreeNode

public abstract class AbstractDecisionTreeNode<InputType,OutputType,InteriorType>
extends Object
implements DecisionTreeNode<InputType,OutputType>, Serializable

The AbstractDecisionTreeNode class implements common functionality for a decision tree node. It keeps the internal decider plus the collection of child nodes and the incoming label value for the node.

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

Field Summary
protected  Map<InteriorType,DecisionTreeNode<InputType,OutputType>> childMap
          The mapping of decider decision values to child nodes.
protected  Categorizer<? super InputType,? extends InteriorType> decider
          The decider used to make a decision as to which child use.
protected  Object incomingValue
          The incoming value for the node.
protected  DecisionTreeNode<InputType,OutputType> parent
          The parent node of this node.
 
Constructor Summary
AbstractDecisionTreeNode()
          Creates a new instance of AbstractDecisionTreeNode
AbstractDecisionTreeNode(DecisionTreeNode<InputType,OutputType> parent, Categorizer<? super InputType,? extends InteriorType> decider, Object incomingValue)
          Creates a new instance of CategorizationTreeNode.
 
Method Summary
 void addChild(InteriorType value, DecisionTreeNode<InputType,OutputType> child)
          Adds a child for a given interior type.
 DecisionTreeNode<InputType,OutputType> chooseChild(InputType input)
          Chooses the child node corresponding to the given input.
 AbstractDecisionTreeNode<InputType,OutputType,InteriorType> clone()
          Creates a new clone (shallow copy) of this object.
 Map<InteriorType,DecisionTreeNode<InputType,OutputType>> getChildMap()
          Gets the mapping of decision values to child nodes.
 Collection<? extends DecisionTreeNode<InputType,OutputType>> getChildren()
          Gets the collection of children of the node.
 Categorizer<? super InputType,? extends InteriorType> getDecider()
          Gets the decider used at this node.
 int getDepth()
          Gets the depth of the node in the tree.
 Object getIncomingValue()
          Gets the label of the incoming value to the node.
 DecisionTreeNode<InputType,OutputType> getParent()
          Gets the parent node for this node.
 int getTreeSize()
          Gets the size of the sub-tree from this node.
 boolean isLeaf()
          Returns true if this node is a leaf node (has no children) and false otherwise.
protected  void setChildMap(Map<InteriorType,DecisionTreeNode<InputType,OutputType>> childMap)
          Sets the mapping of decision values to child nodes.
 void setDecider(Categorizer<? super InputType,? extends InteriorType> decider)
          Sets the decider used at this node.
 void setIncomingValue(Object incomingValue)
          Sets the incoming value for the node.
 void setParent(DecisionTreeNode<InputType,OutputType> parent)
          Sets the parent node for this node.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.tree.DecisionTreeNode
getOutput
 

Field Detail

parent

protected DecisionTreeNode<InputType,OutputType> parent
The parent node of this node.


childMap

protected Map<InteriorType,DecisionTreeNode<InputType,OutputType>> childMap
The mapping of decider decision values to child nodes. For a leaf node, this can be null or empty.


decider

protected Categorizer<? super InputType,? extends InteriorType> decider
The decider used to make a decision as to which child use. For a leaf node, the decider should be null.


incomingValue

protected Object incomingValue
The incoming value for the node. Usually if this is null it means that the node is a root node.

Constructor Detail

AbstractDecisionTreeNode

public AbstractDecisionTreeNode()
Creates a new instance of AbstractDecisionTreeNode


AbstractDecisionTreeNode

public AbstractDecisionTreeNode(DecisionTreeNode<InputType,OutputType> parent,
                                Categorizer<? super InputType,? extends InteriorType> decider,
                                Object incomingValue)
Creates a new instance of CategorizationTreeNode.

Parameters:
parent - The parent node of this node.
decider - The decision function.
incomingValue - The incoming value.
Method Detail

clone

public AbstractDecisionTreeNode<InputType,OutputType,InteriorType> clone()
Description copied from interface: CloneableSerializable
Creates a new clone (shallow copy) of this object.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class Object
Returns:
A new clone (shallow copy) of this object.

addChild

public void addChild(InteriorType value,
                     DecisionTreeNode<InputType,OutputType> child)
Adds a child for a given interior type.

Parameters:
value - The interior type value for the child.
child - The child node to add.

getChildren

public Collection<? extends DecisionTreeNode<InputType,OutputType>> getChildren()
Description copied from interface: DecisionTreeNode
Gets the collection of children of the node.

Specified by:
getChildren in interface DecisionTreeNode<InputType,OutputType>
Returns:
The collection of children of the node.

isLeaf

public boolean isLeaf()
Description copied from interface: DecisionTreeNode
Returns true if this node is a leaf node (has no children) and false otherwise.

Specified by:
isLeaf in interface DecisionTreeNode<InputType,OutputType>
Returns:
True if this is a leaf node; false otherwise.

chooseChild

public DecisionTreeNode<InputType,OutputType> chooseChild(InputType input)
Description copied from interface: DecisionTreeNode
Chooses the child node corresponding to the given input. If there is no corresponding child node, then null is returned.

Specified by:
chooseChild in interface DecisionTreeNode<InputType,OutputType>
Parameters:
input - The input.
Returns:
The corresponding child node for the given input, if one exists; otherwise, null.

getDepth

public int getDepth()
Description copied from interface: DecisionTreeNode
Gets the depth of the node in the tree.

Specified by:
getDepth in interface DecisionTreeNode<InputType,OutputType>
Returns:
The depth of the node. The root is depth 1.

getTreeSize

public int getTreeSize()
Description copied from interface: DecisionTreeNode
Gets the size of the sub-tree from this node.

Specified by:
getTreeSize in interface DecisionTreeNode<InputType,OutputType>
Returns:
The size of the sub-tree rooted at this node. Must be positive.

getParent

public DecisionTreeNode<InputType,OutputType> getParent()
Gets the parent node for this node. Null if it is the root node.

Specified by:
getParent in interface DecisionTreeNode<InputType,OutputType>
Returns:
The parent node for this node.

setParent

public void setParent(DecisionTreeNode<InputType,OutputType> parent)
Sets the parent node for this node. Null if it is the root node.

Parameters:
parent - The parent node for this node.

getDecider

public Categorizer<? super InputType,? extends InteriorType> getDecider()
Gets the decider used at this node.

Returns:
The decider used.

setDecider

public void setDecider(Categorizer<? super InputType,? extends InteriorType> decider)
Sets the decider used at this node.

Parameters:
decider - The decider used.

getChildMap

public Map<InteriorType,DecisionTreeNode<InputType,OutputType>> getChildMap()
Gets the mapping of decision values to child nodes.

Returns:
The child map.

setChildMap

protected void setChildMap(Map<InteriorType,DecisionTreeNode<InputType,OutputType>> childMap)
Sets the mapping of decision values to child nodes.

Parameters:
childMap - The child map.

getIncomingValue

public Object getIncomingValue()
Gets the label of the incoming value to the node.

Specified by:
getIncomingValue in interface DecisionTreeNode<InputType,OutputType>
Returns:
The incoming value to the node, if any.

setIncomingValue

public void setIncomingValue(Object incomingValue)
Sets the incoming value for the node.

Parameters:
incomingValue - The incoming value for the node.