Package dtree
Class DTree
java.lang.Object
dtree.DTree
- All Implemented Interfaces:
Serializable
Class for a decision/regression tree.
- Since:
- 2004.05.10
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected table.Table
the underlying attributesstatic final int
layout mode: center parent nodeprotected int
the number of classes (decision tree)static final int
layout mode: compactprotected DTNode
the current node of the treestatic final int
layout mode: horizontalprotected int
the layout modestatic final int
layout mode: reverse branch orderprotected DTNode
the root node of the treeprotected table.Column
the target/class attributeprotected int
the id of the target/class attributeprotected table.ColType
the type of the target/class attributestatic final int
layout mode: vertical -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a node to the decision tree.void
Add a node to the decision tree.find
(int x, int y) Find the node that is located at given coordinates.void
fold
(boolean f) Fold/unfold all nodes of the decision/regression tree.table.Table
getAtts()
Get the underlying attributes.int
Get the number of children of the current node.Get the current node of the decision/regression tree.int
Get the height of the tree.double[]
getRange()
Get the range of the prediction values.getRoot()
Get the root node of the decision/regression tree.int
getSize()
Get the size of the tree (number of nodes).table.Column
Get the target attribute of the tree.int
Get the id of the target attribute of the tree.table.ColType
Get the type of the target attribute of the tree.int
getWidth()
Get the width of the tree.boolean
goDown
(int id) Go to a child of the current node.boolean
Go to a child of the current node.void
goToRoot()
Set the current node to the root node.void
goUp()
Go to the parent node of the current node.boolean
isLeaf()
Check whether the current node is a leaf node.boolean
isRoot()
Check whether the current node is the root.layout
(int mode, int x, int y, int w, int h) Lay out the nodes of the tree.static void
Main function for testing basic functionality.static DTree
parse
(util.Scanner scan) Parse a decision/regression tree description.static DTree
parse
(util.Scanner scan, table.Table atts) Parse a decision/regression tree description.toString()
Create a string description of the decision/regression tree.
-
Field Details
-
VERTICAL
public static final int VERTICALlayout mode: vertical- See Also:
-
HORIZONTAL
public static final int HORIZONTALlayout mode: horizontal- See Also:
-
COMPACT
public static final int COMPACTlayout mode: compact- See Also:
-
CENTER
public static final int CENTERlayout mode: center parent node- See Also:
-
REVERSE
public static final int REVERSElayout mode: reverse branch order- See Also:
-
atts
protected table.Table attsthe underlying attributes -
target
protected table.Column targetthe target/class attribute -
trgid
protected int trgidthe id of the target/class attribute -
type
protected table.ColType typethe type of the target/class attribute -
clscnt
protected int clscntthe number of classes (decision tree) -
root
the root node of the tree -
curr
the current node of the tree -
mode
protected int modethe layout mode
-
-
Constructor Details
-
DTree
Create a decision/regression tree.- Parameters:
atts
- the underlying attributestrgname
- the name of the target attribute- Since:
- 2004.05.10 (Christian Borgelt)
-
DTree
public DTree(table.Table atts, int trgid) Create a decision/regression tree.- Parameters:
atts
- the underlying attributestrgid
- the id of the target attribute- Since:
- 2004.05.10 (Christian Borgelt)
-
-
Method Details
-
getAtts
public table.Table getAtts()Get the underlying attributes.- Returns:
- the underlying attributes
- Since:
- 2004.05.10 (Christian Borgelt)
-
getTarget
public table.Column getTarget()Get the target attribute of the tree.- Returns:
- the target attribute of the tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
getTargetId
public int getTargetId()Get the id of the target attribute of the tree.- Returns:
- the id of the target attribute of the tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
getTargetType
public table.ColType getTargetType()Get the type of the target attribute of the tree.- Returns:
- the type of the target attribute of the tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
addNode
Add a node to the decision tree.The node is added as a child of the current node.
- Parameters:
id
- the id of the child nodenode
- the node to add as a child- Since:
- 2004.05.10 (Christian Borgelt)
-
addNode
Add a node to the decision tree.The node is added as a child of the current node.
- Parameters:
value
- the value associated with the tree edgenode
- the node to add as a child- Since:
- 2004.05.10 (Christian Borgelt)
-
getRoot
Get the root node of the decision/regression tree.- Returns:
- the root node of the decision/regression tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
getCurrent
Get the current node of the decision/regression tree.- Returns:
- the current node of the decision/regression tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
isRoot
public boolean isRoot()Check whether the current node is the root.- Returns:
- whether the current node is the root
- Since:
- 2004.05.10 (Christian Borgelt)
-
isLeaf
public boolean isLeaf()Check whether the current node is a leaf node.- Returns:
- whether the current node is a leaf node
- Since:
- 2004.05.10 (Christian Borgelt)
-
goToRoot
public void goToRoot()Set the current node to the root node.- Since:
- 2004.05.10 (Christian Borgelt)
-
goUp
public void goUp()Go to the parent node of the current node.- Since:
- 2004.05.10 (Christian Borgelt)
-
getChildCount
public int getChildCount()Get the number of children of the current node.- Returns:
- the number of children of the current node
- Since:
- 2004.05.10 (Christian Borgelt)
-
goDown
public boolean goDown(int id) Go to a child of the current node.- Parameters:
id
- the id of the child node to go to; must be in the range 0 togetChildCount()-1
- Returns:
- whether the child exists and thus was actually moved to
- Since:
- 2004.05.10 (Christian Borgelt)
-
goDown
Go to a child of the current node.- Parameters:
value
- the value associated with the tree edge- Returns:
- whether the child exists and thus was actually moved to
- Since:
- 2004.05.10 (Christian Borgelt)
-
getHeight
public int getHeight()Get the height of the tree.- Returns:
- the height of the tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
getWidth
public int getWidth()Get the width of the tree.- Returns:
- the width of the tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
getSize
public int getSize()Get the size of the tree (number of nodes).- Returns:
- the size of the tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
getRange
public double[] getRange()Get the range of the prediction values.The union of all ranges of all nodes is determined.
- Returns:
- the range of the prediction values
- Since:
- 2004.05.10 (Christian Borgelt)
-
layout
Lay out the nodes of the tree.- Parameters:
mode
- the layout modex
- the x-coordinate of the upper left cornery
- the y-coordinate of the upper left cornerw
- the width of a cell for a nodeh
- the height of a cell for a node- Returns:
- the width and height of the full tree
- Since:
- 2004.05.10 (Christian Borgelt)
-
find
Find the node that is located at given coordinates.- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- node that is located at the given coordinates
- Since:
- 2004.05.10 (Christian Borgelt)
-
fold
public void fold(boolean f) Fold/unfold all nodes of the decision/regression tree.- Parameters:
f
- whether to fold all nodes- Since:
- 2004.05.16 (Christian Borgelt)
-
toString
Create a string description of the decision/regression tree. -
parse
Parse a decision/regression tree description.- Parameters:
scan
- the scanner to read from- Returns:
- the parsed decision tree
- Throws:
IOException
- if a read error occurs- Since:
- 2004.05.10 (Christian Borgelt)
-
parse
Parse a decision/regression tree description.- Parameters:
scan
- the scanner to read fromatts
- the underlying attributes- Returns:
- the parsed decision tree
- Throws:
IOException
- if a read error occurs- Since:
- 2004.05.10 (Christian Borgelt)
-
main
Main function for testing basic functionality.- Parameters:
args
- the command line arguments- Since:
- 2004.05.10 (Christian Borgelt)
-