Documentation of 'jsat.classifiers.trees.TreeNodeVisitor' Java class
TreeNodeVisitor
jsat.classifiers.trees

Class TreeNodeVisitor

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable


    public abstract class TreeNodeVisitor
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Provides an abstracted mechanism for traversing and predicting from nodes in a tree meant for a supervised learning problem. Paths and children are used interchangeably, every node has one path to one child
    Paths to children nodes can be disabled, but not removed. This is done so that the implementation does not have to worry about changes in the indices to children nodes, which would be complicated to implement. Once a path is disabled, it can not be re-enabled.
    If all paths to any children have been disabled, childrenCount() may choose to return 0, otherwise - it must return the original number of paths to children nodes. The implementation for a given tree should override localClassify(jsat.classifiers.DataPoint) and localRegress(jsat.classifiers.DataPoint) if the operations are supported.
    See Also:
    TreeLearner, TreePruner, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      TreeNodeVisitor() 
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      abstract int childrenCount()
      Returns the number of children this node of the tree has, and may return a non zero value even if the node is a leaf
      CategoricalResults classify(DataPoint dp) 
      abstract TreeNodeVisitor clone() 
      abstract void disablePath(int child)
      Disables the selected path to the specified child from the current node.
      abstract java.util.Collection<java.lang.Integer> featuresUsed()
      Returns a collection of the indices of the features used by this node in the tree to make its decision about what branch to use next.
      abstract TreeNodeVisitor getChild(int child)
      Returns the node for the specific child, or null if the child index was not valid
      abstract int getPath(DataPoint dp)
      Returns the path down the tree the given data point would have taken, or -1 if this node was a leaf node OR if a missing value prevent traversal down the path
      double getPathWeight(int path)
      Returns the relative weight of each path, which should be an indication of how much of the training data went down each path.
      abstract boolean isLeaf()
      Returns true if the node is a leaf, meaning it has no valid paths to any children
      abstract boolean isPathDisabled(int child)
      Returns true if the path to the specified child is disabled, meaning it can not be traveled to.
      CategoricalResults localClassify(DataPoint dp)
      Returns the classification result that would have been obtained if the current node was a leaf node.
      double localRegress(DataPoint dp)
      Returns the regression result that would have been obtained if the current node was a leaf node.
      double regress(DataPoint dp)
      Performs regression on the given data point by following it down the tree until it finds the correct terminal node.
      void setPath(int child, TreeNodeVisitor node)
      Optional operation!
      This method, if supported, will set the path so that the child is set to the given value.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TreeNodeVisitor

        public TreeNodeVisitor()
    • Method Detail

      • childrenCount

        public abstract int childrenCount()
        Returns the number of children this node of the tree has, and may return a non zero value even if the node is a leaf
        Returns:
        the number of children this node has
      • isLeaf

        public abstract boolean isLeaf()
        Returns true if the node is a leaf, meaning it has no valid paths to any children
        Returns:
        true if the node is purely a leaf node
      • getChild

        public abstract TreeNodeVisitor getChild(int child)
        Returns the node for the specific child, or null if the child index was not valid
        Parameters:
        child - the index of the child node to obtain
        Returns:
        the node for the child
      • disablePath

        public abstract void disablePath(int child)
        Disables the selected path to the specified child from the current node. All child indices will not be effected by this operation.
        Parameters:
        child - the index of the child to disable the path too
      • setPath

        public void setPath(int child,
                            TreeNodeVisitor node)
        Optional operation!
        This method, if supported, will set the path so that the child is set to the given value.
        The implementation may choose to throw an exception if the NodeVisitor is not of the same implementing class.
        Parameters:
        child - the child path
        node - the node to make the child
      • isPathDisabled

        public abstract boolean isPathDisabled(int child)
        Returns true if the path to the specified child is disabled, meaning it can not be traveled to. It will also return true for an invalid child path, since a non existent node can not be reached.
        Parameters:
        child - the child index to check the path for
        Returns:
        true if the path is unavailable, false if the path is good.
      • localClassify

        public CategoricalResults localClassify(DataPoint dp)
        Returns the classification result that would have been obtained if the current node was a leaf node.
        Parameters:
        dp - the data point to localClassify
        Returns:
        the classification result
        Throws:
        java.lang.UnsupportedOperationException - if the tree node does not support or was not trained for classification
      • getPath

        public abstract int getPath(DataPoint dp)
        Returns the path down the tree the given data point would have taken, or -1 if this node was a leaf node OR if a missing value prevent traversal down the path
        Parameters:
        dp - the data point to send down the tree
        Returns:
        the path that would be taken
      • getPathWeight

        public double getPathWeight(int path)
        Returns the relative weight of each path, which should be an indication of how much of the training data went down each path. By default, returns 1.0/childrenCount(). The result should sum to one
        Parameters:
        path - the path to select
        Returns:
        the fraction of data estimated to travel the specified path, with respect to data that reaches this node.
      • localRegress

        public double localRegress(DataPoint dp)
        Returns the regression result that would have been obtained if the current node was a leaf node.
        Parameters:
        dp - the data point to regress
        Returns:
        the classification result
        Throws:
        java.lang.UnsupportedOperationException - if the tree node does not support or was not trained for classification
      • regress

        public double regress(DataPoint dp)
        Performs regression on the given data point by following it down the tree until it finds the correct terminal node.
        Parameters:
        dp - the data point to regress
        Returns:
        the regression result from the tree starting from the current node
      • featuresUsed

        public abstract java.util.Collection<java.lang.Integer> featuresUsed()
        Returns a collection of the indices of the features used by this node in the tree to make its decision about what branch to use next. Numeric features start from zero, and categorical features start from the number of numeric features.
        Returns:
        the integers indicating which features were used for this node in the tree.
      • clone

        public abstract TreeNodeVisitor clone()
        Overrides:
        clone in class java.lang.Object

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.