use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.
the class TreeEnsembleLearnerNodeView method getSubtree.
private List<DecisionTreeNode> getSubtree(final DecisionTreeNode node) {
List<DecisionTreeNode> subTree = new ArrayList<DecisionTreeNode>();
List<DecisionTreeNode> toProcess = new LinkedList<DecisionTreeNode>();
toProcess.add(0, node);
// Traverse the tree breadth first
while (!toProcess.isEmpty()) {
DecisionTreeNode curr = toProcess.remove(0);
subTree.add(curr);
for (int i = 0; i < curr.getChildCount(); i++) {
toProcess.add(0, curr.getChildAt(i));
}
}
return subTree;
}
use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.
the class TreeEnsembleLearnerNodeView method createTreeMenu.
/**
* Create menu to control tree.
*
* @return A new JMenu with tree operation buttons
*/
private JMenu createTreeMenu() {
final JMenu result = new JMenu("Tree");
result.setMnemonic('T');
Action expand = new ExpandBranchAction<DecisionTreeNode>(m_graph);
expand.putValue(Action.NAME, "Expand Selected Branch");
Action collapse = new CollapseBranchAction<DecisionTreeNode>(m_graph);
collapse.putValue(Action.NAME, "Collapse Selected Branch");
result.add(expand);
result.add(collapse);
return result;
}
use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.
the class TreeEnsembleLearnerNodeView method updateHiLite.
// ///////////////////////////////////////////////////
private void updateHiLite(final boolean state) {
DecisionTreeNode selected = m_graph.getSelected();
if (selected == null) {
return;
}
Set<RowKey> covPat = new HashSet<RowKey>();
covPat.addAll(selected.coveredPattern());
if (state) {
m_hiLiteHdl.fireHiLiteEvent(covPat);
} else {
m_hiLiteHdl.fireUnHiLiteEvent(covPat);
}
}
use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.
the class TreeEnsembleLearnerNodeView method recreateHiLite.
private void recreateHiLite() {
HiLiteHandler handler = m_hiLiteHdl;
if (handler == null) {
return;
}
Set<RowKey> hilited = handler.getHiLitKeys();
Set<DecisionTreeNode> toHilite = new HashSet<DecisionTreeNode>();
DecisionTreeNode root = m_graph.getRootNode();
List<DecisionTreeNode> toProcess = new LinkedList<DecisionTreeNode>();
if (null != root) {
toProcess.add(0, root);
}
// Traverse the tree breadth first
while (!toProcess.isEmpty()) {
DecisionTreeNode curr = toProcess.remove(0);
// cover any pattern
if (curr.coveredPattern().isEmpty()) {
continue;
}
if (hilited.containsAll(curr.coveredPattern())) {
// hilite subtree starting from curr
toHilite.addAll(getSubtree(curr));
} else {
for (int i = 0; i < curr.getChildCount(); i++) {
toProcess.add(0, curr.getChildAt(i));
}
}
}
m_graph.hiLite(toHilite);
}
use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.
the class TreeNodeRegression method createDecisionTreeNode.
/**
* @param metaData
* @return
*/
public DecisionTreeNode createDecisionTreeNode(final MutableInteger idGenerator, final TreeMetaData metaData) {
DataCell majorityCell = new StringCell(DoubleFormat.formatDouble(m_mean));
final int nrChildren = getNrChildren();
LinkedHashMap<DataCell, Double> distributionMap = new LinkedHashMap<DataCell, Double>();
distributionMap.put(majorityCell, m_totalSum);
if (nrChildren == 0) {
return new DecisionTreeNodeLeaf(idGenerator.inc(), majorityCell, distributionMap);
} else {
int id = idGenerator.inc();
DecisionTreeNode[] childNodes = new DecisionTreeNode[nrChildren];
int splitAttributeIndex = getSplitAttributeIndex();
assert splitAttributeIndex >= 0 : "non-leaf node has no split";
String splitAttribute = metaData.getAttributeMetaData(splitAttributeIndex).getAttributeName();
PMMLPredicate[] childPredicates = new PMMLPredicate[nrChildren];
for (int i = 0; i < nrChildren; i++) {
final TreeNodeRegression treeNode = getChild(i);
TreeNodeCondition cond = treeNode.getCondition();
childPredicates[i] = cond.toPMMLPredicate();
childNodes[i] = treeNode.createDecisionTreeNode(idGenerator, metaData);
}
return new DecisionTreeNodeSplitPMML(id, majorityCell, distributionMap, splitAttribute, childPredicates, childNodes);
}
}
Aggregations