org.knime.base.node.mine.decisiontree2.model
Class DecisionTreeNodeSplit

java.lang.Object
  extended by org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode
      extended by org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplit
All Implemented Interfaces:
Serializable, TreeNode
Direct Known Subclasses:
DecisionTreeNodeSplitContinuous, DecisionTreeNodeSplitNominal, DecisionTreeNodeSplitPMML

public abstract class DecisionTreeNodeSplit
extends DecisionTreeNode

An abstract implementation of an inner node of a decision tree, i.e. one that is not a leaf. It mostly holds information about children.

Author:
Michael Berthold, University of Konstanz, Christoph Sieb, University of Konstanz
See Also:
Serialized Form

Constructor Summary
(package private) DecisionTreeNodeSplit()
          Empty Constructor visible only within package.
protected DecisionTreeNodeSplit(int nodeId, DataCell majorityClass, LinkedHashMap<DataCell,Double> classCounts, String splitAttribute)
          Constructor of base class.
  DecisionTreeNodeSplit(Node xmlNode, DataCellStringMapper mapper)
          Constructor of derived class.
 
Method Summary
abstract  void addCoveredColor(DataCell cell, DataRow row, DataTableSpec spec, double weight)
          Add colors for patterns given as a row of values if they fall within a specific node.
 void addCoveredColor(DataRow row, DataTableSpec spec, double weight)
          Add colors for a row of values if they fall within a specific node/branch.
abstract  void addCoveredPattern(DataCell cell, DataRow row, DataTableSpec spec, double weight)
          Add patterns given as a row of values if they fall within a specific node.
 void addCoveredPattern(DataRow row, DataTableSpec spec, double weight)
          Add patterns given as a row of values if they fall within a specific node.
 void addNode(DecisionTreeNode node, int index)
          Add the given node to this node at the given branch index.
 boolean addNodeToTreeDepthFirst(DecisionTreeNode node, int ix)
          Add a new node to the tree structure based on a depth-first indexing strategy.
 Enumeration<DecisionTreeNode> children()
           
abstract  Set<RowKey> coveredPattern()
          
 boolean getAllowsChildren()
          
 TreeNode getChildAt(int pos)
          
 int getChildCount()
          
protected  DecisionTreeNode getChildNodeAt(int pos)
          Return DecisionTreeNode at specific branch.
 DecisionTreeNode[] getChildren()
          Returns the children.
abstract  LinkedHashMap<DataCell,Double> getClassCounts(DataCell cell, DataRow row, DataTableSpec spec)
          Determine class counts for a new pattern given as a row of values.
 LinkedHashMap<DataCell,Double> getClassCounts(DataRow row, DataTableSpec spec)
          Determine class counts for a new pattern given as a row of values.
 int getCountOfSubtree()
          Returns the count of the subtree.
 int getIndex(TreeNode node)
          Returns the index of node in the receivers children.
 PMMLMissingValueStrategy getMVStrategy()
           
protected  LinkedHashMap<DataCell,Double> getNodeClassWeights()
          Combines all class weights from _all_ branches of this node.
 PMMLNoTrueChildStrategy getNTCStrategy()
           
 String getSplitAttr()
          Return name of attribute this node splits on.
 boolean isLeaf()
          
 void loadNodeInternalsFromPredParams(ModelContentRO pConf)
          Load internal node settings from a model content object.
abstract  void loadNodeSplitInternalsFromPredParams(ModelContentRO pConf)
          Load internal SplitNode settings from a ModelContent object.
protected  void makeRoomForKids(int nrKids)
          Reserve space for specific number of kids.
 void replaceChild(DecisionTreeNode oldNode, DecisionTreeNode newNode)
          Replace the given child by the new given one.
 void saveNodeInternalsToPredParams(ModelContentWO pConf, boolean saveKeysAndPatterns)
          Save internal node settings to a model content object.
abstract  void saveNodeSplitInternalsToPredParams(ModelContentWO pConf)
          save internal SplitNode settings to a ModelContent object.
protected  void setChildNodeIndex(int pos, int index)
          Mark index of child node at a specific branch.
 void setMVStrategy(PMMLMissingValueStrategy strategy)
          Set the missing value strategy and propagate it to all children that are split nodes.
 void setNTCStrategy(PMMLNoTrueChildStrategy ntcStrategy)
          Set the no true child strategy and propagate it to all children that are split nodes.
 
Methods inherited from class org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode
addColorToMap, classifyPattern, coveredColors, createNewNode, createNodeFromPredictorParams, getClassCounts, getCustomData, getEntireClassCount, getMajorityClass, getOverallColorCount, getOwnClassCount, getOwnIndex, getParent, getPrefix, getStringSummary, getWinner, loadFromPredictorParams, newColors, resetColorInformation, saveToPredictorParams, setCoveredColors, setCustomData, setParent, setPrefix, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DecisionTreeNodeSplit

DecisionTreeNodeSplit()
Empty Constructor visible only within package.


DecisionTreeNodeSplit

public DecisionTreeNodeSplit(Node xmlNode,
                             DataCellStringMapper mapper)
Constructor of derived class. Read all type-specific information from XML File.

Parameters:
xmlNode - XML node info
mapper - map translating column names to DataCells and vice versa

DecisionTreeNodeSplit

protected DecisionTreeNodeSplit(int nodeId,
                                DataCell majorityClass,
                                LinkedHashMap<DataCell,Double> classCounts,
                                String splitAttribute)
Constructor of base class. The necessary data is provided directly in the constructor.

Parameters:
nodeId - the id of this node
majorityClass - the majority class of the records in this node
classCounts - the class distribution of the data in this node
splitAttribute - the attribute name on which to split
Method Detail

getSplitAttr

public String getSplitAttr()
Return name of attribute this node splits on.

Returns:
string the name of the column used for the split

makeRoomForKids

protected void makeRoomForKids(int nrKids)
Reserve space for specific number of kids.

Parameters:
nrKids - number of children attached to this node

setChildNodeIndex

protected void setChildNodeIndex(int pos,
                                 int index)
Mark index of child node at a specific branch.

Parameters:
pos - position of branch at this node
index - index of child node

getChildNodeAt

protected DecisionTreeNode getChildNodeAt(int pos)
Return DecisionTreeNode at specific branch.

Parameters:
pos - position of branch
Returns:
node attached to this branch

addNode

public void addNode(DecisionTreeNode node,
                    int index)
Add the given node to this node at the given branch index.

Parameters:
node - node to be inserted
index - of the child array where to insert the given node

addNodeToTreeDepthFirst

public boolean addNodeToTreeDepthFirst(DecisionTreeNode node,
                                       int ix)
Add a new node to the tree structure based on a depth-first indexing strategy.

Specified by:
addNodeToTreeDepthFirst in class DecisionTreeNode
Parameters:
node - node to be inserted
ix - index of this node in depth first traversal order
Returns:
true only if the node was successfully inserted

getClassCounts

public LinkedHashMap<DataCell,Double> getClassCounts(DataRow row,
                                                     DataTableSpec spec)
                                              throws Exception
Determine class counts for a new pattern given as a row of values. Returns a HashMap listing counts for all classes.

Specified by:
getClassCounts in class DecisionTreeNode
Parameters:
row - input pattern
spec - the corresponding table spec
Returns:
HashMap class/count
Throws:
Exception - if something went wrong (unknown attriubte for example)

getNodeClassWeights

protected LinkedHashMap<DataCell,Double> getNodeClassWeights()
Combines all class weights from _all_ branches of this node.

Returns:
the combined class weights.

getClassCounts

public abstract LinkedHashMap<DataCell,Double> getClassCounts(DataCell cell,
                                                              DataRow row,
                                                              DataTableSpec spec)
                                                       throws Exception
Determine class counts for a new pattern given as a row of values. Returns a HashMap listing counts for all classes.

Parameters:
cell - the call to be used for classification at this node
row - input pattern
spec - the corresponding table spec
Returns:
HashMap class/count
Throws:
Exception - if something went wrong (unknown attriubte for example)

addCoveredPattern

public final void addCoveredPattern(DataRow row,
                                    DataTableSpec spec,
                                    double weight)
                             throws Exception
Add patterns given as a row of values if they fall within a specific node. Usually only Leafs will actually hold a list of RowKeys, all intermediate nodes will collect "their" information recursively.

Specified by:
addCoveredPattern in class DecisionTreeNode
Parameters:
row - input pattern
spec - the corresponding table spec
weight - the weight of the row (between 0.0 and 1.0)
Throws:
Exception - if something went wrong (unknown attribute for example)

addCoveredPattern

public abstract void addCoveredPattern(DataCell cell,
                                       DataRow row,
                                       DataTableSpec spec,
                                       double weight)
                                throws Exception
Add patterns given as a row of values if they fall within a specific node. Usually only Leafs will actually hold a list of RowKeys, all intermediate nodes will collect "their" information recursively.

Parameters:
cell - the cell to be used for classification at this node
row - input pattern
spec - the corresponding table spec
weight - the weight of this row (between 0.0 and 1.0)
Throws:
Exception - if something went wrong (unknown attribute for example)

addCoveredColor

public final void addCoveredColor(DataRow row,
                                  DataTableSpec spec,
                                  double weight)
                           throws Exception
Add colors for a row of values if they fall within a specific node/branch. Used if we don't want to (or can't anymore) store the pattern itself. We still want the color pie chart to be correct.

Specified by:
addCoveredColor in class DecisionTreeNode
Parameters:
row - input pattern
spec - the corresponding table spec
weight - the weight of the row (between 0.0 and 1.0)
Throws:
Exception - if something went wrong (unknown attribute for example)

addCoveredColor

public abstract void addCoveredColor(DataCell cell,
                                     DataRow row,
                                     DataTableSpec spec,
                                     double weight)
                              throws Exception
Add colors for patterns given as a row of values if they fall within a specific node.

Parameters:
cell - the call to be used for classification at this node
row - input pattern
spec - the corresponding table spec
weight - the weight of this row (between 0.0 and 1.0)
Throws:
Exception - if something went wrong (unknown attribute for example)

coveredPattern

public abstract Set<RowKey> coveredPattern()

Specified by:
coveredPattern in class DecisionTreeNode
Returns:
set of data cells which are the row keys that are covered by all nodes of this branch

saveNodeInternalsToPredParams

public final void saveNodeInternalsToPredParams(ModelContentWO pConf,
                                                boolean saveKeysAndPatterns)
Save internal node settings to a model content object.

Specified by:
saveNodeInternalsToPredParams in class DecisionTreeNode
Parameters:
pConf - configuration object to attach decision tree to
saveKeysAndPatterns - whether to save the keys and patterns

saveNodeSplitInternalsToPredParams

public abstract void saveNodeSplitInternalsToPredParams(ModelContentWO pConf)
save internal SplitNode settings to a ModelContent object.

Parameters:
pConf - configuration object to save decision tree to

loadNodeInternalsFromPredParams

public final void loadNodeInternalsFromPredParams(ModelContentRO pConf)
                                           throws InvalidSettingsException
Load internal node settings from a model content object.

Specified by:
loadNodeInternalsFromPredParams in class DecisionTreeNode
Parameters:
pConf - configuration object to load decision tree from
Throws:
InvalidSettingsException - if something goes wrong

loadNodeSplitInternalsFromPredParams

public abstract void loadNodeSplitInternalsFromPredParams(ModelContentRO pConf)
                                                   throws InvalidSettingsException
Load internal SplitNode settings from a ModelContent object.

Parameters:
pConf - configuration object to load decision tree from.
Throws:
InvalidSettingsException - if something goes wrong

getChildCount

public int getChildCount()

Specified by:
getChildCount in interface TreeNode
Specified by:
getChildCount in class DecisionTreeNode
Returns:
count of children

getIndex

public int getIndex(TreeNode node)
Returns the index of node in the receivers children. If the receiver does not contain node, -1 will be returned.

Specified by:
getIndex in interface TreeNode
Specified by:
getIndex in class DecisionTreeNode
Parameters:
node - that supposedly is a child of this one
Returns:
index of node (or -1 if not found)

getChildAt

public TreeNode getChildAt(int pos)

Specified by:
getChildAt in interface TreeNode
Specified by:
getChildAt in class DecisionTreeNode
Parameters:
pos - position of child
Returns:
child node at index

isLeaf

public boolean isLeaf()

Specified by:
isLeaf in interface TreeNode
Specified by:
isLeaf in class DecisionTreeNode
Returns:
true if node is a leaf

children

public Enumeration<DecisionTreeNode> children()
Specified by:
children in interface TreeNode
Specified by:
children in class DecisionTreeNode
Returns:
enumeration of all children

getChildren

public DecisionTreeNode[] getChildren()
Returns the children.

Returns:
the children

getAllowsChildren

public boolean getAllowsChildren()

Specified by:
getAllowsChildren in interface TreeNode
Specified by:
getAllowsChildren in class DecisionTreeNode
Returns:
true if the receiver allows children

replaceChild

public void replaceChild(DecisionTreeNode oldNode,
                         DecisionTreeNode newNode)
Replace the given child by the new given one.

Parameters:
oldNode - the node to replace
newNode - the new node

getCountOfSubtree

public int getCountOfSubtree()
Returns the count of the subtree.

Specified by:
getCountOfSubtree in class DecisionTreeNode
Returns:
the count of the subtree

getMVStrategy

public PMMLMissingValueStrategy getMVStrategy()
Returns:
the missing value strategy

setMVStrategy

public void setMVStrategy(PMMLMissingValueStrategy strategy)
Set the missing value strategy and propagate it to all children that are split nodes.

Parameters:
strategy - the strategy to set

getNTCStrategy

public PMMLNoTrueChildStrategy getNTCStrategy()
Returns:
the the no true child strategy

setNTCStrategy

public void setNTCStrategy(PMMLNoTrueChildStrategy ntcStrategy)
Set the no true child strategy and propagate it to all children that are split nodes.

Parameters:
ntcStrategy - the strategy to set


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.