Search in sources :

Example 1 with TreeNodeCondition

use of org.knime.base.node.mine.treeensemble.model.TreeNodeCondition in project knime-core by knime.

the class NominalSplitCandidate method getChildConditions.

/**
 * {@inheritDoc}
 */
@Override
public TreeNodeCondition[] getChildConditions() {
    TreeNominalColumnMetaData columnMeta = getColumnData().getMetaData();
    NominalValueRepresentation[] values = columnMeta.getValues();
    List<TreeNodeCondition> resultList = new ArrayList<TreeNodeCondition>(values.length);
    for (int i = 0; i < values.length; i++) {
        if (m_sumWeightsAttributes[i] >= TreeColumnData.EPSILON) {
            resultList.add(new TreeNodeNominalCondition(columnMeta, i));
        }
    }
    return resultList.toArray(new TreeNodeCondition[resultList.size()]);
}
Also used : TreeNominalColumnMetaData(org.knime.base.node.mine.treeensemble.data.TreeNominalColumnMetaData) TreeNodeNominalCondition(org.knime.base.node.mine.treeensemble.model.TreeNodeNominalCondition) ArrayList(java.util.ArrayList) NominalValueRepresentation(org.knime.base.node.mine.treeensemble.data.NominalValueRepresentation) TreeNodeCondition(org.knime.base.node.mine.treeensemble.model.TreeNodeCondition)

Example 2 with TreeNodeCondition

use of org.knime.base.node.mine.treeensemble.model.TreeNodeCondition in project knime-core by knime.

the class BitSplitCandidate method getChildConditions.

/**
 * {@inheritDoc}
 */
@Override
public TreeNodeCondition[] getChildConditions() {
    TreeBitColumnMetaData metaData = getColumnData().getMetaData();
    TreeNodeCondition[] result = new TreeNodeCondition[2];
    result[0] = new TreeNodeBitCondition(metaData, true);
    result[1] = new TreeNodeBitCondition(metaData, false);
    return result;
}
Also used : TreeBitColumnMetaData(org.knime.base.node.mine.treeensemble.data.TreeBitColumnMetaData) TreeNodeCondition(org.knime.base.node.mine.treeensemble.model.TreeNodeCondition) TreeNodeBitCondition(org.knime.base.node.mine.treeensemble.model.TreeNodeBitCondition)

Example 3 with TreeNodeCondition

use of org.knime.base.node.mine.treeensemble.model.TreeNodeCondition in project knime-core by knime.

the class TreeLearnerClassification method buildTreeNode.

private TreeNodeClassification buildTreeNode(final ExecutionMonitor exec, final int currentDepth, final double[] rowSampleWeights, final TreeNodeSignature treeNodeSignature, final ClassificationPriors targetPriors, final BitSet forbiddenColumnSet, final TreeNodeMembershipController membershipController) throws CanceledExecutionException {
    final TreeData data = getData();
    final TreeEnsembleLearnerConfiguration config = getConfig();
    exec.checkCanceled();
    SplitCandidate bestSplit = findBestSplitClassification(currentDepth, rowSampleWeights, treeNodeSignature, targetPriors, forbiddenColumnSet, membershipController);
    if (bestSplit == null) {
        return new TreeNodeClassification(treeNodeSignature, targetPriors, getConfig());
    }
    TreeAttributeColumnData splitColumn = bestSplit.getColumnData();
    final int attributeIndex = splitColumn.getMetaData().getAttributeIndex();
    boolean markAttributeAsForbidden = !bestSplit.canColumnBeSplitFurther();
    forbiddenColumnSet.set(attributeIndex, markAttributeAsForbidden);
    TreeNodeCondition[] childConditions = bestSplit.getChildConditions();
    if (childConditions.length > Short.MAX_VALUE) {
        throw new RuntimeException("Too many children when splitting " + "attribute " + bestSplit.getColumnData() + " (maximum supported: " + Short.MAX_VALUE + "): " + childConditions.length);
    }
    TreeNodeClassification[] childNodes = new TreeNodeClassification[childConditions.length];
    final double[] dataMemberships = rowSampleWeights;
    // final double[] dataMemberships = rowSampleWeights.getMemberships();
    final double[] childMemberships = new double[dataMemberships.length];
    final TreeTargetNominalColumnData targetColumn = (TreeTargetNominalColumnData) data.getTargetColumn();
    for (int i = 0; i < childConditions.length; i++) {
        System.arraycopy(dataMemberships, 0, childMemberships, 0, dataMemberships.length);
        TreeNodeCondition cond = childConditions[i];
        splitColumn.updateChildMemberships(cond, dataMemberships, childMemberships);
        // TreeNodeMembershipController childMembershipController = membershipController.createChildTreeNodeMembershipController(childMemberships);
        TreeNodeMembershipController childMembershipController = null;
        ClassificationPriors childTargetPriors = targetColumn.getDistribution(childMemberships, config);
        TreeNodeSignature childSignature = treeNodeSignature.createChildSignature((short) i);
        childNodes[i] = buildTreeNode(exec, currentDepth + 1, childMemberships, childSignature, childTargetPriors, forbiddenColumnSet, childMembershipController);
        childNodes[i].setTreeNodeCondition(cond);
    }
    if (markAttributeAsForbidden) {
        forbiddenColumnSet.set(attributeIndex, false);
    }
    return new TreeNodeClassification(treeNodeSignature, targetPriors, childNodes, getConfig());
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration) TreeNodeClassification(org.knime.base.node.mine.treeensemble.model.TreeNodeClassification) TreeNodeMembershipController(org.knime.base.node.mine.treeensemble.data.TreeNodeMembershipController) TreeAttributeColumnData(org.knime.base.node.mine.treeensemble.data.TreeAttributeColumnData) TreeNodeSignature(org.knime.base.node.mine.treeensemble.model.TreeNodeSignature) TreeData(org.knime.base.node.mine.treeensemble.data.TreeData) TreeNodeCondition(org.knime.base.node.mine.treeensemble.model.TreeNodeCondition) TreeTargetNominalColumnData(org.knime.base.node.mine.treeensemble.data.TreeTargetNominalColumnData) ClassificationPriors(org.knime.base.node.mine.treeensemble.data.ClassificationPriors)

Example 4 with TreeNodeCondition

use of org.knime.base.node.mine.treeensemble.model.TreeNodeCondition in project knime-core by knime.

the class TreeLearnerRegression method buildTreeNode.

private TreeNodeRegression buildTreeNode(final ExecutionMonitor exec, final int currentDepth, final double[] rowSampleWeights, final TreeNodeSignature treeNodeSignature, final RegressionPriors targetPriors, final BitSet forbiddenColumnSet, final TreeNodeMembershipController membershipController) throws CanceledExecutionException {
    final TreeData data = getData();
    final TreeEnsembleLearnerConfiguration config = getConfig();
    exec.checkCanceled();
    SplitCandidate bestSplit = findBestSplitRegression(currentDepth, rowSampleWeights, treeNodeSignature, targetPriors, forbiddenColumnSet, membershipController);
    if (bestSplit == null) {
        return new TreeNodeRegression(treeNodeSignature, targetPriors);
    }
    TreeAttributeColumnData splitColumn = bestSplit.getColumnData();
    final int attributeIndex = splitColumn.getMetaData().getAttributeIndex();
    boolean markAttributeAsForbidden = !bestSplit.canColumnBeSplitFurther();
    forbiddenColumnSet.set(attributeIndex, markAttributeAsForbidden);
    TreeNodeCondition[] childConditions = bestSplit.getChildConditions();
    if (childConditions.length > Short.MAX_VALUE) {
        throw new RuntimeException("Too many children when splitting " + "attribute " + bestSplit.getColumnData() + " (maximum supported: " + Short.MAX_VALUE + "): " + childConditions.length);
    }
    TreeNodeRegression[] childNodes = new TreeNodeRegression[childConditions.length];
    final double[] dataMemberships = rowSampleWeights;
    final double[] childMemberships = new double[dataMemberships.length];
    final TreeTargetNumericColumnData targetColumn = (TreeTargetNumericColumnData) data.getTargetColumn();
    for (int i = 0; i < childConditions.length; i++) {
        System.arraycopy(dataMemberships, 0, childMemberships, 0, dataMemberships.length);
        TreeNodeCondition cond = childConditions[i];
        splitColumn.updateChildMemberships(cond, dataMemberships, childMemberships);
        RegressionPriors childTargetPriors = targetColumn.getPriors(childMemberships, config);
        TreeNodeSignature childSignature = treeNodeSignature.createChildSignature((short) i);
        TreeNodeMembershipController childMembershipController = splitColumn.getChildNodeMembershipController(cond, membershipController);
        childNodes[i] = buildTreeNode(exec, currentDepth + 1, childMemberships, childSignature, childTargetPriors, forbiddenColumnSet, childMembershipController);
        childNodes[i].setTreeNodeCondition(cond);
    }
    if (markAttributeAsForbidden) {
        forbiddenColumnSet.set(attributeIndex, false);
    }
    return new TreeNodeRegression(treeNodeSignature, targetPriors, childNodes);
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration) TreeNodeMembershipController(org.knime.base.node.mine.treeensemble.data.TreeNodeMembershipController) TreeAttributeColumnData(org.knime.base.node.mine.treeensemble.data.TreeAttributeColumnData) RegressionPriors(org.knime.base.node.mine.treeensemble.data.RegressionPriors) TreeTargetNumericColumnData(org.knime.base.node.mine.treeensemble.data.TreeTargetNumericColumnData) TreeNodeSignature(org.knime.base.node.mine.treeensemble.model.TreeNodeSignature) TreeNodeRegression(org.knime.base.node.mine.treeensemble.model.TreeNodeRegression) TreeData(org.knime.base.node.mine.treeensemble.data.TreeData) TreeNodeCondition(org.knime.base.node.mine.treeensemble.model.TreeNodeCondition)

Aggregations

TreeNodeCondition (org.knime.base.node.mine.treeensemble.model.TreeNodeCondition)4 TreeAttributeColumnData (org.knime.base.node.mine.treeensemble.data.TreeAttributeColumnData)2 TreeData (org.knime.base.node.mine.treeensemble.data.TreeData)2 TreeNodeMembershipController (org.knime.base.node.mine.treeensemble.data.TreeNodeMembershipController)2 TreeNodeSignature (org.knime.base.node.mine.treeensemble.model.TreeNodeSignature)2 TreeEnsembleLearnerConfiguration (org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration)2 ArrayList (java.util.ArrayList)1 ClassificationPriors (org.knime.base.node.mine.treeensemble.data.ClassificationPriors)1 NominalValueRepresentation (org.knime.base.node.mine.treeensemble.data.NominalValueRepresentation)1 RegressionPriors (org.knime.base.node.mine.treeensemble.data.RegressionPriors)1 TreeBitColumnMetaData (org.knime.base.node.mine.treeensemble.data.TreeBitColumnMetaData)1 TreeNominalColumnMetaData (org.knime.base.node.mine.treeensemble.data.TreeNominalColumnMetaData)1 TreeTargetNominalColumnData (org.knime.base.node.mine.treeensemble.data.TreeTargetNominalColumnData)1 TreeTargetNumericColumnData (org.knime.base.node.mine.treeensemble.data.TreeTargetNumericColumnData)1 TreeNodeBitCondition (org.knime.base.node.mine.treeensemble.model.TreeNodeBitCondition)1 TreeNodeClassification (org.knime.base.node.mine.treeensemble.model.TreeNodeClassification)1 TreeNodeNominalCondition (org.knime.base.node.mine.treeensemble.model.TreeNodeNominalCondition)1 TreeNodeRegression (org.knime.base.node.mine.treeensemble.model.TreeNodeRegression)1