public class TreeNode
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
assignOutputClass()
Initializes the output class stored in the node with a valid output class, in a standard way,
with the class stored in the node if it is pure or with the class of the majority of the instances
where if there are two majority classes, it selects randomly one of them
|
boolean |
equals(java.lang.Object obj)
Checks if a tree node is the same tree node as another object
|
int |
evaluate(double[] ind)
Classifies a given item with the information stored in the node and its descendants, making a call
to the specific classifiers at the leaves
|
Split |
evaluateAllSplits(int splitCriteria)
Evaluates all splits and returns the best split found.
|
java.util.ArrayList<java.lang.Double> |
getClasses()
Gets an array list with the different classes in the node
|
Split |
getCondition()
Gets the relationship between this node and its descendats, that's the way to split this node in two
|
int |
getIdentifier()
Gets the identifier of the node
|
int |
getLeafs()
Gets the number of leaf nodes from this node and its descendants
|
TreeNode |
getLeft()
Gets the left descendant of the node, if it is not a leaf node
|
TreeNode |
getNode(int id)
Searches a descendant node from this node with a specific id
|
int[] |
getNodeError()
Obtains the error of a leave node in a the tree from all the instances in the leaf in
a two number array
|
int |
getNumClasses()
Gets the number of different classes in the node
|
int |
getNumNodes()
Gets the number of internal nodes from this node and its descendants.
|
int |
getOutputClass()
Gets the output class stored for the node.
|
TreeNode |
getRight()
Gets the right descendant of the node, if it is not a leaf node
|
int[] |
getTreeError()
Obtains the general error of the tree from all its leaves in a two number array
|
int |
hashCode()
Hash-code function for the class that is used when object is inserted in a structure like a hashtable
|
boolean |
isLeaf()
Answers if the node is a leaf node or not
|
boolean |
isPartitionable(int num_min_instances)
Decides if a node is partitionable or not.
|
java.lang.String |
printTree()
Prints the tree in a String with all the information that makes it human readable
|
void |
prune(double error)
Prunes this leave or its descendants according to the error given, making it a leave with a
classifier on it
|
void |
pruneAllLeaves()
Prunes all the leaves in the tree, this means, that all the leaves disappear and the ascendants
of those leaves become the new leaves of the tree with the classifier at leaves
|
void |
pruneWithError()
Prunes the leaves in the tree that have greater error than the general error of the tree, making
them leaves with classifiers on them
|
void |
setAsClassifierLeaf()
Sets this node as a classifier leaf node.
|
void |
setAsLeaf()
Sets this node as a leaf node.
|
void |
setCondition(Split condition)
Replaces the relationship between this node and its descendants, this means, changing the condition how
the two descendants are created.
|
void |
setIdentifier(int identifier)
Replaces the identifier of the node with another new node
|
void |
setLeaf(boolean isLeaf)
Changes the logical attribute stating if a node is leaf or not
|
void |
setLeft(TreeNode left)
Replaces the left descendant of the node with another new left descendant
|
void |
setOutputClass(int outputClass)
Replaces the output class of the node with another new output class
|
void |
setRight(TreeNode right)
Replaces the right descendant of the node with another new right descendant
|
java.util.ArrayList<TreeNode> |
split(Split sp,
int newidentifier)
Splits a node into two nodes from a split following the identifier of a given number into an arraylist
of nodes.
|
java.lang.String |
toString()
Overriden function that converts the class to a string
|
boolean |
valid_split(Split sp)
Checks if a split is valid for a TreeNode, this means, that it will generate valid child nodes
|
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- Object that is checked to see if it is the same tree nodeObject.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public java.lang.String printTree()
public int getIdentifier()
public void setIdentifier(int identifier)
identifier
- New identifier for the nodepublic TreeNode getLeft()
public void setLeft(TreeNode left)
left
- New node that is going to be kept as left descendant of this nodepublic TreeNode getRight()
public void setRight(TreeNode right)
right
- New node that is going to be kept as right descendant of this nodepublic boolean isLeaf()
public void setLeaf(boolean isLeaf)
isLeaf
- Logical value stating if a node is leaf or notpublic int getOutputClass()
public void setOutputClass(int outputClass)
outputClass
- New output class for the nodepublic Split getCondition()
public void setCondition(Split condition)
condition
- New relationship between this node and its descendantspublic TreeNode getNode(int id)
id
- Identifier of the node we are searching forpublic int getNumNodes()
public int getLeafs()
public int evaluate(double[] ind)
ind
- Data attribute values for the item we are classifyingpublic boolean isPartitionable(int num_min_instances)
num_min_instances
- The minimum number of data instances that the tree node must contain to
be considered a partitionable nodepublic void setAsLeaf()
public void setAsClassifierLeaf()
public void assignOutputClass()
public int getNumClasses()
public java.util.ArrayList<java.lang.Double> getClasses()
public Split evaluateAllSplits(int splitCriteria)
splitCriteria
- Information measure used to compute the best split. 0 is the value for
Entropy, 1 is for InformationGain, 2 is for GiniIndex and 3 is for GainRatiopublic boolean valid_split(Split sp)
sp
- Split that is going to be checked if it generates valid child nodespublic java.util.ArrayList<TreeNode> split(Split sp, int newidentifier)
sp
- Split used in this node to divide the node into two new nodes left and rightnewidentifier
- Identifier of the last node created in the algorithmpublic void pruneAllLeaves()
public void pruneWithError()
public void prune(double error)
error
- General error of the tree that has to be surpassed in order to prune the leavepublic int[] getTreeError()
public int[] getNodeError()