Package dtree

Class DTNode

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

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

    Fields
    Modifier and Type
    Field
    Description
    protected table.Column
    the test attribute
    protected int
    the best class (highest probability)
    protected int
    the bottom border of the node cell
    protected DTNode[]
    the vector of children
    protected double
    the cut value
    protected double
    the deviation of the prediction value (regression tree)
    protected boolean
    whether subtree is folded
    protected double[]
    the class frequencies (decision tree)
    protected int
    the left border of the node cell
    protected DTNode
    the parent node
    protected double
    the prediction value (regression tree)
    protected int
    the right border of the node cell
    protected String
    the set of attribute values
    protected double
    the total frequency (total number of cases)
    protected int
    the bottom border of the subtree
    protected int
    the left border of the subtree
    protected int
    the top border of the node cell
    protected DTree
    the containing decision tree
    protected int
    the right border of the subtree
    protected int
    the top border of the subtree
    protected int
    parent attribute value id
  • Constructor Summary

    Constructors
    Constructor
    Description
    DTNode(DTree tree)
    Create a decision/regression tree leaf.
    DTNode(DTree tree, String name)
    Create a decision/regression tree node.
    DTNode(DTree tree, table.Column att)
    Create a decision/regression tree node.
    DTNode(DTree tree, table.Column att, double cut)
    Create a decision/regression tree node.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addChild(int id, DTNode child)
    Add a child node.
    void
    addChild(String value, DTNode child)
    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
    Get the test attribute of the node.
    Get the name of the test attribute of the node.
    int
    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
    Get the cut value of the node.
    double
    Get the deviation of the prediction value of the node.
    Get the containing decision tree.
    double
    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
    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
    Get the size of the subtree rooted at the node.
    Get the value associated with the edge to the node.
    int
    Get the value id associated with the edge to the node.
    protected int
    Get the width of the subtree rooted at the node (total number of leaves in the subtree).
    int
    Get the x-coordinate of the node.
    int
    Get the y-coordinate of the node.
    boolean
    Check whether the subtree rooted at the node is folded.
    boolean
    Check whether the node is a leaf node.
    boolean
    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(DTree dtree, util.Scanner scan)
    Parse a decision/regression tree node/subtree.
    void
    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.

    Methods inherited from class java.lang.Object

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

    • tree

      protected DTree tree
      the containing decision tree
    • att

      protected table.Column att
      the test attribute
    • cut

      protected double cut
      the cut value
    • freqs

      protected double[] freqs
      the class frequencies (decision tree)
    • sum

      protected double sum
      the total frequency (total number of cases)
    • best

      protected int best
      the best class (highest probability)
    • pred

      protected double pred
      the prediction value (regression tree)
    • dev

      protected double dev
      the deviation of the prediction value (regression tree)
    • children

      protected DTNode[] children
      the vector of children
    • parent

      protected DTNode parent
      the parent node
    • valid

      protected int valid
      parent attribute value id
    • set

      protected String set
      the set of attribute values
    • lft

      protected int lft
      the left border of the node cell
    • rgt

      protected int rgt
      the right border of the node cell
    • top

      protected int top
      the top border of the node cell
    • bot

      protected int bot
      the bottom border of the node cell
    • tlft

      protected int tlft
      the left border of the subtree
    • trgt

      protected int trgt
      the right border of the subtree
    • ttop

      protected int ttop
      the top border of the subtree
    • tbot

      protected int tbot
      the bottom border of the subtree
    • folded

      protected boolean folded
      whether subtree is folded
  • Constructor Details

    • DTNode

      public DTNode(DTree tree, table.Column att, double cut)
      Create a decision/regression tree node.
      Parameters:
      tree - the corresponding decision/regression tree
      att - the test attribute of the node
      cut - the cut value of the node
      Since:
      2004.05.10 (Christian Borgelt)
    • DTNode

      public DTNode(DTree tree, table.Column att)
      Create a decision/regression tree node.
      Parameters:
      tree - the corresponding decision/regression tree
      att - the test attribute of the node
      Since:
      2004.05.10 (Christian Borgelt)
    • DTNode

      public DTNode(DTree tree, String name)
      Create a decision/regression tree node.
      Parameters:
      tree - the corresponding decision/regression tree
      name - the name of the test attribute of the node
      Since:
      2007.02.17 (Christian Borgelt)
    • DTNode

      public DTNode(DTree tree)
      Create a decision/regression tree leaf.
      Parameters:
      tree - the corresponding decision/regression tree
      Since:
      2007.02.17 (Christian Borgelt)
  • Method Details

    • getDTree

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

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

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

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

      public DTNode getChild(int id)
      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

      public void addChild(int id, DTNode child)
      Add a child node.
      Parameters:
      id - the id of the child node
      child - the child node to add
      Since:
      2004.05.10 (Christian Borgelt)
    • addChild

      public void addChild(String value, DTNode child)
      Add a child node.
      Parameters:
      value - the value associated with the edge to the child
      child - 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 subtree
      all - 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 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 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 subtree
      w - the width of a cell for a node
      lft - 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 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
      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 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 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 subtree
      h - the height of a cell for a node
      top - 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 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
      Since:
      2015.12.02 (Christian Borgelt)
    • findVert

      protected DTNode findVert(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)
    • findHorz

      protected DTNode findHorz(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)
    • toString

      protected String toString(int depth)
      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

      protected static DTNode parse(DTree dtree, util.Scanner scan) throws IOException
      Parse a decision/regression tree node/subtree.
      Parameters:
      dtree - the corresponding decision tree
      scan - 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)