Package org.tribuo.common.tree
Class AbstractTrainingNode<T extends Output<T>>
java.lang.Object
org.tribuo.common.tree.AbstractTrainingNode<T>
- All Implemented Interfaces:
Serializable
,Node<T>
- Direct Known Subclasses:
ClassifierTrainingNode
,JointRegressorTrainingNode
,RegressorTrainingNode
Base class for decision tree nodes used at training time.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Contains parameters needed to determine whether a node is a leaf. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
Default buffer size used in the split operation.protected final int
protected double
protected final AbstractTrainingNode.LeafDeterminer
protected final int
protected boolean
protected int
protected double
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractTrainingNode
(int depth, int numExamples, AbstractTrainingNode.LeafDeterminer leafDeterminer) Builds an abstract training node. -
Method Summary
Modifier and TypeMethodDescriptionabstract List<AbstractTrainingNode<T>>
buildTree
(int[] featureIDs, SplittableRandom rng, boolean useRandomSplitPoints) Builds next level of a tree.Converts a tree from a training representation to the final inference time representation.copy()
Copies the node and it's children.Transforms anAbstractTrainingNode
into aSplitNode
int
getDepth()
The depth of this node in the tree.getNextNode
(SparseVector example) Returns the next node in the tree based on the supplied example, or null if it's a leaf.int
The number of training examples in this node.abstract float
The sum of the weights associated with this node's examples.boolean
isLeaf()
Is it a leaf node?boolean
shouldMakeLeaf
(double impurityScore, float weightSum) Determines whether the node to be created should be aLeafNode
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.tribuo.common.tree.Node
getImpurity
-
Field Details
-
DEFAULT_SIZE
protected static final int DEFAULT_SIZEDefault buffer size used in the split operation.- See Also:
-
depth
protected final int depth -
numExamples
protected final int numExamples -
leafDeterminer
-
split
protected boolean split -
splitID
protected int splitID -
splitValue
protected double splitValue -
impurityScore
protected double impurityScore -
greaterThan
-
lessThanOrEqual
-
-
Constructor Details
-
AbstractTrainingNode
protected AbstractTrainingNode(int depth, int numExamples, AbstractTrainingNode.LeafDeterminer leafDeterminer) Builds an abstract training node.- Parameters:
depth
- The depth of this node.numExamples
- The number of examples in this node.leafDeterminer
- The parameters which determine if the node forms a leaf.
-
-
Method Details
-
buildTree
public abstract List<AbstractTrainingNode<T>> buildTree(int[] featureIDs, SplittableRandom rng, boolean useRandomSplitPoints) Builds next level of a tree.- Parameters:
featureIDs
- Indices of the features available in this split.rng
- Splittable random number generator.useRandomSplitPoints
- Whether to choose split points for features at random.- Returns:
- A possibly empty list of TrainingNodes.
-
convertTree
Converts a tree from a training representation to the final inference time representation.- Returns:
- The converted subtree.
-
getWeightSum
public abstract float getWeightSum()The sum of the weights associated with this node's examples.- Returns:
- the sum of the weights associated with this node's examples.
-
getDepth
public int getDepth()The depth of this node in the tree.- Returns:
- The depth.
-
shouldMakeLeaf
public boolean shouldMakeLeaf(double impurityScore, float weightSum) Determines whether the node to be created should be aLeafNode
.- Parameters:
impurityScore
- impurity score for the new node.weightSum
- total example weight for the new node.- Returns:
- Whether the new node should be a
LeafNode
.
-
createSplitNode
Transforms anAbstractTrainingNode
into aSplitNode
- Returns:
- A
SplitNode
-
getNextNode
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 interfaceNode<T extends Output<T>>
- Parameters:
example
- The example.- Returns:
- The next node down in the tree.
-
getNumExamples
public int getNumExamples()The number of training examples in this node.- Returns:
- The number of training examples in this node.
-
isLeaf
public boolean isLeaf()Description copied from interface:Node
Is it a leaf node? -
copy
Description copied from interface:Node
Copies the node and it's children.
-