Package dtree

Class DTree

java.lang.Object
dtree.DTree
All Implemented Interfaces:
Serializable

public class DTree extends Object implements Serializable
Class for a decision/regression tree.
Since:
2004.05.10
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected table.Table
    the underlying attributes
    static final int
    layout mode: center parent node
    protected int
    the number of classes (decision tree)
    static final int
    layout mode: compact
    protected DTNode
    the current node of the tree
    static final int
    layout mode: horizontal
    protected int
    the layout mode
    static final int
    layout mode: reverse branch order
    protected DTNode
    the root node of the tree
    protected table.Column
    the target/class attribute
    protected int
    the id of the target/class attribute
    protected table.ColType
    the type of the target/class attribute
    static final int
    layout mode: vertical
  • Constructor Summary

    Constructors
    Constructor
    Description
    DTree(table.Table atts, int trgid)
    Create a decision/regression tree.
    DTree(table.Table atts, String trgname)
    Create a decision/regression tree.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addNode(int id, DTNode node)
    Add a node to the decision tree.
    void
    addNode(String value, DTNode node)
    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
    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[]
    Get the range of the prediction values.
    Get the root node of the decision/regression tree.
    int
    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
    Get the width of the tree.
    boolean
    goDown(int id)
    Go to a child of the current node.
    boolean
    goDown(String value)
    Go to a child of the current node.
    void
    Set the current node to the root node.
    void
    Go to the parent node of the current node.
    boolean
    Check whether the current node is a leaf node.
    boolean
    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(String[] args)
    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.
    Create a string description of the decision/regression tree.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • VERTICAL

      public static final int VERTICAL
      layout mode: vertical
      See Also:
    • HORIZONTAL

      public static final int HORIZONTAL
      layout mode: horizontal
      See Also:
    • COMPACT

      public static final int COMPACT
      layout mode: compact
      See Also:
    • CENTER

      public static final int CENTER
      layout mode: center parent node
      See Also:
    • REVERSE

      public static final int REVERSE
      layout mode: reverse branch order
      See Also:
    • atts

      protected table.Table atts
      the underlying attributes
    • target

      protected table.Column target
      the target/class attribute
    • trgid

      protected int trgid
      the id of the target/class attribute
    • type

      protected table.ColType type
      the type of the target/class attribute
    • clscnt

      protected int clscnt
      the number of classes (decision tree)
    • root

      protected DTNode root
      the root node of the tree
    • curr

      protected DTNode curr
      the current node of the tree
    • mode

      protected int mode
      the layout mode
  • Constructor Details

    • DTree

      public DTree(table.Table atts, String trgname)
      Create a decision/regression tree.
      Parameters:
      atts - the underlying attributes
      trgname - 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 attributes
      trgid - 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

      public void addNode(int id, DTNode node)
      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 node
      node - the node to add as a child
      Since:
      2004.05.10 (Christian Borgelt)
    • addNode

      public void addNode(String value, DTNode node)
      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 edge
      node - the node to add as a child
      Since:
      2004.05.10 (Christian Borgelt)
    • getRoot

      public DTNode 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

      public DTNode 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 to getChildCount()-1
      Returns:
      whether the child exists and thus was actually moved to
      Since:
      2004.05.10 (Christian Borgelt)
    • goDown

      public boolean goDown(String value)
      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

      public Dimension layout(int mode, int x, int y, int w, int h)
      Lay out the nodes of the tree.
      Parameters:
      mode - the layout mode
      x - the x-coordinate of the upper left corner
      y - the y-coordinate of the upper left corner
      w - the width of a cell for a node
      h - the height of a cell for a node
      Returns:
      the width and height of the full tree
      Since:
      2004.05.10 (Christian Borgelt)
    • find

      public DTNode find(int x, int y)
      Find the node that is located at given coordinates.
      Parameters:
      x - the x-coordinate
      y - 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

      public String toString()
      Create a string description of the decision/regression tree.
      Overrides:
      toString in class Object
      Returns:
      a string description of the decision/regression tree
      Since:
      2004.05.10 (Christian Borgelt)
    • parse

      public static DTree parse(util.Scanner scan) throws IOException
      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

      public static DTree parse(util.Scanner scan, table.Table atts) throws IOException
      Parse a decision/regression tree description.
      Parameters:
      scan - the scanner to read from
      atts - the underlying attributes
      Returns:
      the parsed decision tree
      Throws:
      IOException - if a read error occurs
      Since:
      2004.05.10 (Christian Borgelt)
    • main

      public static void main(String[] args)
      Main function for testing basic functionality.
      Parameters:
      args - the command line arguments
      Since:
      2004.05.10 (Christian Borgelt)