Package dtree
Class DTNode
java.lang.Object
dtree.DTNode
- All Implemented Interfaces:
Serializable
Class for a decision/regression tree node.
- Since:
- 2004.05.10
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected table.Column
the test attributeprotected int
the best class (highest probability)protected int
the bottom border of the node cellprotected DTNode[]
the vector of childrenprotected double
the cut valueprotected double
the deviation of the prediction value (regression tree)protected boolean
whether subtree is foldedprotected double[]
the class frequencies (decision tree)protected int
the left border of the node cellprotected DTNode
the parent nodeprotected double
the prediction value (regression tree)protected int
the right border of the node cellprotected String
the set of attribute valuesprotected double
the total frequency (total number of cases)protected int
the bottom border of the subtreeprotected int
the left border of the subtreeprotected int
the top border of the node cellprotected DTree
the containing decision treeprotected int
the right border of the subtreeprotected int
the top border of the subtreeprotected int
parent attribute value id -
Constructor Summary
ConstructorsConstructorDescriptionCreate a decision/regression tree leaf.Create a decision/regression tree node.Create a decision/regression tree node.Create a decision/regression tree node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a child node.void
Add a child node.protected int
cloHorz1
(int mode, int n, int h, int[] top, int[] bot) Do a compact horizontal layout of the subtree (pass 1).protected void
cloHorz2
(int mode, int x, int y, int w, int h) Do a compact horizontal layout of the subtree (pass 2).protected int
cloVert1
(int mode, int n, int w, int[] lft, int[] rgt) Do a compact vertical layout of the subtree (pass 1).protected void
cloVert2
(int mode, int x, int y, int w, int h) Do a compact vertical layout of the subtree (pass 2).protected DTNode
findHorz
(int x, int y) Find the node that is located at given coordinates.protected DTNode
findVert
(int x, int y) Find the node that is located at given coordinates.void
fold
(boolean f, boolean all) Fold/unfold the subtree rooted at the node.table.Column
getAtt()
Get the test attribute of the node.Get the name of the test attribute of the node.int
getBest()
Get the best class of the node.getChild
(int id) Get a child of the node.int
Get the number of children of the node.double
getCut()
Get the cut value of the node.double
getDev()
Get the deviation of the prediction value of the node.getDTree()
Get the containing decision tree.double
getFreq()
Get the total of the class frequencies.double
getFreq
(int id) Get the frequency of a given class.int
Get the number of class frequencies.protected int
Get the height of the subtree rooted at the node.Get the parent of the node.double
getPred()
Get the prediction value of the node.double
getProb
(int id) Get the probability of a given class.int
Get the number of class probabilities.protected void
getRange
(double[] range) Get the range of prediction values in the subtree.protected int
getSize()
Get the size of the subtree rooted at the node.getValue()
Get the value associated with the edge to the node.int
Get the value id associated with the edge to the node.protected int
getWidth()
Get the width of the subtree rooted at the node (total number of leaves in the subtree).int
getX()
Get the x-coordinate of the node.int
getY()
Get the y-coordinate of the node.boolean
isFolded()
Check whether the subtree rooted at the node is folded.boolean
isLeaf()
Check whether the node is a leaf node.boolean
isRoot()
Check whether the node is a root node.protected int
layoutHorz
(int mode, int x, int y, int w, int h) Do a horizontal layout of the subtree.protected int
layoutVert
(int mode, int x, int y, int w, int h) Do a vertical layout of the subtree.protected static DTNode
Parse a decision/regression tree node/subtree.void
prune()
Prune the subtree rooted at the node, that is, replace it with a leaf.protected String
toString
(int depth) Create a string description of the subtree.
-
Field Details
-
tree
the containing decision tree -
att
protected table.Column attthe test attribute -
cut
protected double cutthe cut value -
freqs
protected double[] freqsthe class frequencies (decision tree) -
sum
protected double sumthe total frequency (total number of cases) -
best
protected int bestthe best class (highest probability) -
pred
protected double predthe prediction value (regression tree) -
dev
protected double devthe deviation of the prediction value (regression tree) -
children
the vector of children -
parent
the parent node -
valid
protected int validparent attribute value id -
set
the set of attribute values -
lft
protected int lftthe left border of the node cell -
rgt
protected int rgtthe right border of the node cell -
top
protected int topthe top border of the node cell -
bot
protected int botthe bottom border of the node cell -
tlft
protected int tlftthe left border of the subtree -
trgt
protected int trgtthe right border of the subtree -
ttop
protected int ttopthe top border of the subtree -
tbot
protected int tbotthe bottom border of the subtree -
folded
protected boolean foldedwhether subtree is folded
-
-
Constructor Details
-
DTNode
Create a decision/regression tree node.- Parameters:
tree
- the corresponding decision/regression treeatt
- the test attribute of the nodecut
- the cut value of the node- Since:
- 2004.05.10 (Christian Borgelt)
-
DTNode
Create a decision/regression tree node.- Parameters:
tree
- the corresponding decision/regression treeatt
- the test attribute of the node- Since:
- 2004.05.10 (Christian Borgelt)
-
DTNode
Create a decision/regression tree node.- Parameters:
tree
- the corresponding decision/regression treename
- the name of the test attribute of the node- Since:
- 2007.02.17 (Christian Borgelt)
-
DTNode
Create a decision/regression tree leaf.- Parameters:
tree
- the corresponding decision/regression tree- Since:
- 2007.02.17 (Christian Borgelt)
-
-
Method Details
-
getDTree
Get the containing decision tree.- Returns:
- the containing decision tree
- Since:
- 2015.11.24 (Christian Borgelt)
-
isRoot
public boolean isRoot()Check whether the node is a root node.- Returns:
- whether the node is a root node
- Since:
- 2004.05.10 (Christian Borgelt)
-
isLeaf
public boolean isLeaf()Check whether the node is a leaf node.- Returns:
- whether the node is a leaf node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getValueId
public int getValueId()Get the value id associated with the edge to the node.- Returns:
- the value id associated with the edge to the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getValue
Get the value associated with the edge to the node.- Returns:
- the value associated with the edge to the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getAtt
public table.Column getAtt()Get the test attribute of the node.- Returns:
- the test attribute of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getAttName
Get the name of the test attribute of the node.- Returns:
- the name of the test attribute of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getCut
public double getCut()Get the cut value of the node.- Returns:
- the cut value of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getFreqCount
public int getFreqCount()Get the number of class frequencies.- Returns:
- the number of class frequencies
- Since:
- 2004.05.10 (Christian Borgelt)
-
getFreq
public double getFreq()Get the total of the class frequencies.- Returns:
- the total of the class frequencies
- Since:
- 2004.05.10 (Christian Borgelt)
-
getFreq
public double getFreq(int id) Get the frequency of a given class.- Parameters:
id
- the id of the class- Returns:
- the frequency of the given class
- Since:
- 2004.05.10 (Christian Borgelt)
-
getProbCount
public int getProbCount()Get the number of class probabilities.- Returns:
- the number of class probabilities
- Since:
- 2004.05.10 (Christian Borgelt)
-
getProb
public double getProb(int id) Get the probability of a given class.- Parameters:
id
- the id of the class- Returns:
- the probability of the given class
- Since:
- 2004.05.10 (Christian Borgelt)
-
getBest
public int getBest()Get the best class of the node.- Returns:
- the id of the best class
- Since:
- 2004.05.10 (Christian Borgelt)
-
getPred
public double getPred()Get the prediction value of the node.- Returns:
- the prediction value of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getDev
public double getDev()Get the deviation of the prediction value of the node.- Returns:
- the deviation of the prediction value of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getParent
Get the parent of the node.- Returns:
- the parent of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getChildCount
public int getChildCount()Get the number of children of the node.- Returns:
- the number of children of the node
- Since:
- 2004.05.11 (Christian Borgelt)
-
getChild
Get a child of the node.- Parameters:
id
- the id of the child node- Returns:
- the child with the given id
- Since:
- 2004.05.10 (Christian Borgelt)
-
addChild
Add a child node.- Parameters:
id
- the id of the child nodechild
- the child node to add- Since:
- 2004.05.10 (Christian Borgelt)
-
addChild
Add a child node.- Parameters:
value
- the value associated with the edge to the childchild
- the child node to add- Since:
- 2004.05.10 (Christian Borgelt)
-
getX
public int getX()Get the x-coordinate of the node.- Returns:
- the x-coordinate of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getY
public int getY()Get the y-coordinate of the node.- Returns:
- the y-coordinate of the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
isFolded
public boolean isFolded()Check whether the subtree rooted at the node is folded.- Returns:
- whether the subtree rooted at the node is folded
- Since:
- 2004.05.10 (Christian Borgelt)
-
fold
public void fold(boolean f, boolean all) Fold/unfold the subtree rooted at the node.- Parameters:
f
- whether to fold the subtreeall
- whether to fold/unfold all descendants recursively- Since:
- 2004.05.10 (Christian Borgelt)
-
prune
public void prune()Prune the subtree rooted at the node, that is, replace it with a leaf.- Since:
- 2004.05.10 (Christian Borgelt)
-
getHeight
protected int getHeight()Get the height of the subtree rooted at the node.- Returns:
- the height of the subtree rooted at the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getWidth
protected int getWidth()Get the width of the subtree rooted at the node (total number of leaves in the subtree).- Returns:
- the width of the subtree rooted at the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getSize
protected int getSize()Get the size of the subtree rooted at the node.The size of a tree/subtree is its number of nodes.
- Returns:
- the size of the subtree rooted at the node
- Since:
- 2004.05.10 (Christian Borgelt)
-
getRange
protected void getRange(double[] range) Get the range of prediction values in the subtree.- Parameters:
range
- the range of prediction values in the subtree- Since:
- 2004.05.10 (Christian Borgelt)
-
layoutVert
protected int layoutVert(int mode, int x, int y, int w, int h) Do a vertical layout of the subtree.- Parameters:
mode
- layout mode (center, reverse etc.)x
- 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 right border of the rectangle used
- Since:
- 2004.05.10 (Christian Borgelt)
-
cloVert1
protected int cloVert1(int mode, int n, int w, int[] lft, int[] rgt) Do a compact vertical layout of the subtree (pass 1).- Parameters:
mode
- layout mode (center, reverse etc.)n
- the (potentially remaining) depth of the subtreew
- the width of a cell for a nodelft
- the left border of the subtree (to be filled)rgt
- the right border of the subtree (to be filled)- Returns:
- the number of (valid) entries in the border arrays
- Since:
- 2015.12.02 (Christian Borgelt)
-
cloVert2
protected void cloVert2(int mode, int x, int y, int w, int h) Do a compact vertical layout of the subtree (pass 2).- Parameters:
mode
- layout mode (center, reverse etc.)x
- 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- Since:
- 2015.12.02 (Christian Borgelt)
-
layoutHorz
protected int layoutHorz(int mode, int x, int y, int w, int h) Do a horizontal layout of the subtree.- Parameters:
mode
- layout mode (center, reverse etc.)x
- 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 bottom border of the rectangle used
- Since:
- 2004.05.10 (Christian Borgelt)
-
cloHorz1
protected int cloHorz1(int mode, int n, int h, int[] top, int[] bot) Do a compact horizontal layout of the subtree (pass 1).- Parameters:
mode
- layout mode (center, reverse etc.)n
- the (potentially remaining) depth of the subtreeh
- the height of a cell for a nodetop
- the top border of the subtree (to be filled)bot
- the bottom border of the subtree (to be filled)- Returns:
- the number of (valid) entries in the border arrays
- Since:
- 2015.12.02 (Christian Borgelt)
-
cloHorz2
protected void cloHorz2(int mode, int x, int y, int w, int h) Do a compact horizontal layout of the subtree (pass 2).- Parameters:
mode
- layout mode (center, reverse etc.)x
- 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- Since:
- 2015.12.02 (Christian Borgelt)
-
findVert
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)
-
findHorz
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)
-
toString
Create a string description of the subtree.- Parameters:
depth
- the depth of the decision tree node- Returns:
- a string description of the subtree
- Since:
- 2004.05.10 (Christian Borgelt)
-
parse
Parse a decision/regression tree node/subtree.- Parameters:
dtree
- the corresponding decision treescan
- the scanner to read from- Returns:
- the parsed decision/regression tree node/subtree
- Throws:
IOException
- if a read error occurs- Since:
- 2004.05.10 (Christian Borgelt)
-