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

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
          extended by gov.sandia.cognition.learning.algorithm.tree.AbstractDecisionTreeLearner<InputType,OutputType>
Type Parameters:
InputType - The input type for the decision tree.
OutputType - The output type for the decision tree.
All Implemented Interfaces:
IterativeAlgorithm, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
CategorizationTreeLearner, RegressionTreeLearner

public abstract class AbstractDecisionTreeLearner<InputType,OutputType>
extends AbstractIterativeAlgorithm
implements Serializable

The AbstractDecisionTreeLearner implements common functionality for learning algorithms that learn a decision tree.

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

Field Summary
protected  DeciderLearner<? super InputType,OutputType,?,?> deciderLearner
          The learning algorithm for the decision function.
 
Fields inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
DEFAULT_ITERATION, iteration
 
Constructor Summary
AbstractDecisionTreeLearner()
          Creates a new instance of AbstractDecisionTreeLearner
AbstractDecisionTreeLearner(DeciderLearner<? super InputType,OutputType,?,?> deciderLearner)
          Creates a new instance of AbstractDecisionTreeLearner.
 
Method Summary
 boolean areAllOutputsEqual(Collection<? extends InputOutputPair<? extends InputType,OutputType>> data)
          Determines if all of the output values in the collection are equal.
 DeciderLearner<? super InputType,OutputType,?,?> getDeciderLearner()
          Gets the learner for the decision function.
protected
<DecisionType>
void
learnChildNodes(AbstractDecisionTreeNode<InputType,OutputType,DecisionType> node, Collection<? extends InputOutputPair<? extends InputType,OutputType>> data, Categorizer<? super InputType,? extends DecisionType> decider)
          Learns the child nodes for a node using the given data at the node plus the decision function for the node.
protected abstract  AbstractDecisionTreeNode<InputType,OutputType,?> learnNode(Collection<? extends InputOutputPair<? extends InputType,OutputType>> data, AbstractDecisionTreeNode<InputType,OutputType,?> parent)
          Recursively learns the decision tree using the given collection of data, returning the created node.
 void setDeciderLearner(DeciderLearner<? super InputType,OutputType,?,?> deciderLearner)
          Sets the learner for the decision function.
<DecisionType>
Map<DecisionType,LinkedList<InputOutputPair<? extends InputType,OutputType>>>
splitData(Collection<? extends InputOutputPair<? extends InputType,OutputType>> data, Categorizer<? super InputType,? extends DecisionType> decider)
          Splits the data into new lists based on the given decision function.
 
Methods inherited from class gov.sandia.cognition.algorithm.AbstractIterativeAlgorithm
addIterativeAlgorithmListener, clone, fireAlgorithmEnded, fireAlgorithmStarted, fireStepEnded, fireStepStarted, getIteration, getListeners, removeIterativeAlgorithmListener, setIteration, setListeners
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

deciderLearner

protected DeciderLearner<? super InputType,OutputType,?,?> deciderLearner
The learning algorithm for the decision function.

Constructor Detail

AbstractDecisionTreeLearner

public AbstractDecisionTreeLearner()
Creates a new instance of AbstractDecisionTreeLearner


AbstractDecisionTreeLearner

public AbstractDecisionTreeLearner(DeciderLearner<? super InputType,OutputType,?,?> deciderLearner)
Creates a new instance of AbstractDecisionTreeLearner.

Parameters:
deciderLearner - The learner for the decision function
Method Detail

learnNode

protected abstract AbstractDecisionTreeNode<InputType,OutputType,?> learnNode(Collection<? extends InputOutputPair<? extends InputType,OutputType>> data,
                                                                              AbstractDecisionTreeNode<InputType,OutputType,?> parent)
Recursively learns the decision tree using the given collection of data, returning the created node.

Parameters:
data - The set of data to learn a node from.
parent - The parent node.
Returns:
The decision tree node learned from the given data.

learnChildNodes

protected <DecisionType> void learnChildNodes(AbstractDecisionTreeNode<InputType,OutputType,DecisionType> node,
                                              Collection<? extends InputOutputPair<? extends InputType,OutputType>> data,
                                              Categorizer<? super InputType,? extends DecisionType> decider)
Learns the child nodes for a node using the given data at the node plus the decision function for the node. It recursively calls the learnNode method on each child and then adds the child to the given node.

Type Parameters:
DecisionType - The type of decision function.
Parameters:
node - The node to learn the children for. The child nodes are added by this method.
data - The data at the node to learn the children for.
decider - The decision function to use.

splitData

public <DecisionType> Map<DecisionType,LinkedList<InputOutputPair<? extends InputType,OutputType>>> splitData(Collection<? extends InputOutputPair<? extends InputType,OutputType>> data,
                                                                                                              Categorizer<? super InputType,? extends DecisionType> decider)
Splits the data into new lists based on the given decision function.

Type Parameters:
DecisionType - The type of decision function.
Parameters:
data - The data to split.
decider - The decision function.
Returns:
A mapping of category decided by the decision function to a list of examples that have that value as indicated by the decision function.

areAllOutputsEqual

public boolean areAllOutputsEqual(Collection<? extends InputOutputPair<? extends InputType,OutputType>> data)
Determines if all of the output values in the collection are equal. It does this in a fast way by getting the first value and then checking it against the subsequent values and failing if one does not match.

Parameters:
data - The data to check for equality on the outputs.
Returns:
True if all the output values are equal; otherwise, false.

getDeciderLearner

public DeciderLearner<? super InputType,OutputType,?,?> getDeciderLearner()
Gets the learner for the decision function.

Returns:
deciderLearner The learner for the decision function

setDeciderLearner

public void setDeciderLearner(DeciderLearner<? super InputType,OutputType,?,?> deciderLearner)
Sets the learner for the decision function.

Parameters:
deciderLearner - The learner for the decision function