InputType
- The input type of the decision tree to evaluateOutputType
- The output type that the decision tree returns.public class DecisionTree<InputType,OutputType> extends AbstractCloneableSerializable implements Evaluator<InputType,OutputType>
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.Modifier and Type | Field and Description |
---|---|
protected DecisionTreeNode<InputType,OutputType> |
rootNode
The root node of the decision tree.
|
Constructor and Description |
---|
DecisionTree()
Creates a new instance of DecisionTree.
|
DecisionTree(DecisionTreeNode<InputType,OutputType> rootNode)
Creates a new instance of DecisionTree.
|
Modifier and Type | Method and Description |
---|---|
DecisionTree<InputType,OutputType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
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.
|
protected DecisionTreeNode<InputType,OutputType> rootNode
public DecisionTree()
public DecisionTree(DecisionTreeNode<InputType,OutputType> rootNode)
rootNode
- The root node of the tree.public DecisionTree<InputType,OutputType> clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public OutputType evaluate(InputType input)
evaluate
in interface Evaluator<InputType,OutputType>
input
- The input to evaluate.public OutputType evaluateNode(InputType input, DecisionTreeNode<InputType,OutputType> node)
input
- The input to evaluate.node
- The node at which to evaluate.public DecisionTreeNode<InputType,OutputType> findTerminalNode(InputType input)
input
- The input to find the terminal node for.public DecisionTreeNode<InputType,OutputType> findTerminalNode(InputType input, DecisionTreeNode<InputType,OutputType> node)
input
- The input to find the terminal node for.node
- The node to search from.public DecisionTreeNode<InputType,OutputType> getRootNode()
public void setRootNode(DecisionTreeNode<InputType,OutputType> rootNode)
rootNode
- The root node of the decision tree.