Class LeafNode<T extends Output<T>>

java.lang.Object
org.tribuo.common.tree.LeafNode<T>
All Implemented Interfaces:
Serializable, Node<T>

public class LeafNode<T extends Output<T>> extends Object implements Node<T>
An immutable leaf Node that can create a prediction.

equals(java.lang.Object) uses the Output.fullEquals(Output) method to determine equality of two leaves.

See Also:
  • Constructor Details

    • LeafNode

      public LeafNode(double impurity, T output, Map<String,T> scores, boolean generatesProbabilities)
      Constructs a leaf node.
      Parameters:
      impurity - The impurity value calculated at training time.
      output - The output value from this node.
      scores - The score map for the other outputs.
      generatesProbabilities - If the scores are probabilities.
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getNextNode

      public Node<T> getNextNode(SparseVector e)
      Description copied from interface: Node
      Returns the next node in the tree based on the supplied example, or null if it's a leaf.
      Specified by:
      getNextNode in interface Node<T extends Output<T>>
      Parameters:
      e - The example.
      Returns:
      The next node down in the tree.
    • isLeaf

      public boolean isLeaf()
      Description copied from interface: Node
      Is it a leaf node?
      Specified by:
      isLeaf in interface Node<T extends Output<T>>
      Returns:
      True if it's a leaf node.
    • getImpurity

      public double getImpurity()
      Description copied from interface: Node
      The impurity score of this node.
      Specified by:
      getImpurity in interface Node<T extends Output<T>>
      Returns:
      The node impurity.
    • copy

      public LeafNode<T> copy()
      Description copied from interface: Node
      Copies the node and it's children.
      Specified by:
      copy in interface Node<T extends Output<T>>
      Returns:
      A deep copy.
    • getOutput

      public T getOutput()
      Gets the output in this node.
      Returns:
      The output.
    • getDistribution

      public Map<String,T> getDistribution()
      Gets the distribution over scores in this node.
      Returns:
      The score distribution.
    • getPrediction

      public Prediction<T> getPrediction(int numUsed, Example<T> example)
      Constructs a new prediction object based on this node's scores.
      Parameters:
      numUsed - The number of features used.
      example - The example to be scored.
      Returns:
      The prediction for the supplied example.
    • toString

      public String toString()
      Overrides:
      toString in class Object