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

java.lang.Object
  extended by org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode
      extended by org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf
All Implemented Interfaces:
Serializable, TreeNode

public class DecisionTreeNodeLeaf
extends DecisionTreeNode

The Leaf of a decision tree. It stores class information and also some information about the patterns this leaf "coveres".

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

Constructor Summary
DecisionTreeNodeLeaf()
          Empty Constructor visible only within package.
DecisionTreeNodeLeaf(int nodeId, DataCell majorityClass, LinkedHashMap<DataCell,Double> classCounts)
          Constructor of base class.
DecisionTreeNodeLeaf(Node xmlNode, DataCellStringMapper mapper)
          Constructor of derived class.
 
Method Summary
 void addCoveredColor(DataRow row, DataTableSpec spec, double weight)
          Add colors for a pattern given as a row of values.
 void addCoveredPattern(DataRow row, DataTableSpec spec, double weight)
          Add patterns given as a row of values.
 boolean addNodeToTreeDepthFirst(DecisionTreeNode node, int ix)
          Add a new node to the tree structure based on a depth-first indexing strategy.
 Enumeration<DecisionTreeNode> children()
          
 Set<RowKey> coveredPattern()
           
 boolean getAllowsChildren()
          
 TreeNode getChildAt(int pos)
          
 int getChildCount()
          
 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.
 String getStringSummary()
           
 boolean isLeaf()
          
 boolean isPureEnough()
          Get the marker field for the purity.
 void loadNodeInternalsFromPredParams(ModelContentRO pConf)
          Load internal node settings from a model content object.
 void saveNodeInternalsToPredParams(ModelContentWO pConf, boolean saveKeysAndPatterns)
          Save internal node settings to a model content object.
 void setPureEnough(boolean pureEnough)
          Set the marker field for the purity.
 
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, 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

DecisionTreeNodeLeaf

DecisionTreeNodeLeaf()
Empty Constructor visible only within package.


DecisionTreeNodeLeaf

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

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

DecisionTreeNodeLeaf

public DecisionTreeNodeLeaf(int nodeId,
                            DataCell majorityClass,
                            LinkedHashMap<DataCell,Double> classCounts)
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
Method Detail

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:
false always since this node is a leaf!

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)

addCoveredPattern

public final void addCoveredPattern(DataRow row,
                                    DataTableSpec spec,
                                    double weight)
                             throws Exception
Add patterns given as a row of values. This is a leaf so we will simply add the RowKey to our list of hiliteable rows.

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 attriubte for example)

addCoveredColor

public final void addCoveredColor(DataRow row,
                                  DataTableSpec spec,
                                  double weight)
                           throws Exception
Add colors for a pattern given as a row of values. This is a leaf so we will simply add the color to our list.

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 attriubte for example)

coveredPattern

public Set<RowKey> coveredPattern()
Specified by:
coveredPattern in class DecisionTreeNode
Returns:
set of data cells which are the row keys that are covered by this leaf node

getStringSummary

public String getStringSummary()
Specified by:
getStringSummary in class DecisionTreeNode
Returns:
string summary of node content (class of leaf)

saveNodeInternalsToPredParams

public 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

loadNodeInternalsFromPredParams

public 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

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

getAllowsChildren

public boolean getAllowsChildren()

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

getCountOfSubtree

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

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

isPureEnough

public boolean isPureEnough()
Get the marker field for the purity.

Returns:
whether this leaf is pure enough or not; must have been set properly

setPureEnough

public void setPureEnough(boolean pureEnough)
Set the marker field for the purity.

Parameters:
pureEnough - true if this leaf should be marked as pure enough


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.