Search in sources :

Example 16 with TreeEnsembleLearnerConfiguration

use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.

the class TreeLearnerRegression method learnSingleTree.

/**
 * {@inheritDoc}
 */
@Override
public TreeModelRegression learnSingleTree(final ExecutionMonitor exec, final RandomData rd) throws CanceledExecutionException {
    final TreeTargetNumericColumnData targetColumn = getTargetData();
    final TreeData data = getData();
    final RowSample rowSampling = getRowSampling();
    final TreeEnsembleLearnerConfiguration config = getConfig();
    double[] dataMemberships = new double[data.getNrRows()];
    for (int i = 0; i < dataMemberships.length; i++) {
        dataMemberships[i] = rowSampling.getCountFor(i);
    }
    RegressionPriors targetPriors = targetColumn.getPriors(dataMemberships, config);
    BitSet forbiddenColumnSet = new BitSet(data.getNrAttributes());
    // TreeNodeMembershipController rootMembershipController = new TreeNodeMembershipController(data, dataMemberships);
    TreeNodeMembershipController rootMembershipController = null;
    TreeNodeRegression rootNode = buildTreeNode(exec, 0, dataMemberships, TreeNodeSignature.ROOT_SIGNATURE, targetPriors, forbiddenColumnSet, rootMembershipController);
    assert forbiddenColumnSet.cardinality() == 0;
    rootNode.setTreeNodeCondition(TreeNodeTrueCondition.INSTANCE);
    return new TreeModelRegression(rootNode);
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration) TreeNodeMembershipController(org.knime.base.node.mine.treeensemble.data.TreeNodeMembershipController) RegressionPriors(org.knime.base.node.mine.treeensemble.data.RegressionPriors) BitSet(java.util.BitSet) TreeTargetNumericColumnData(org.knime.base.node.mine.treeensemble.data.TreeTargetNumericColumnData) TreeData(org.knime.base.node.mine.treeensemble.data.TreeData) RowSample(org.knime.base.node.mine.treeensemble.sample.row.RowSample) TreeNodeRegression(org.knime.base.node.mine.treeensemble.model.TreeNodeRegression) TreeModelRegression(org.knime.base.node.mine.treeensemble.model.TreeModelRegression)

Example 17 with TreeEnsembleLearnerConfiguration

use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration 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)

Example 18 with TreeEnsembleLearnerConfiguration

use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.

the class TreeEnsembleRegressionLearnerNodeDialogPane method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    TreeEnsembleLearnerConfiguration cfg = new TreeEnsembleLearnerConfiguration(true);
    m_attributeSelectionPanel.saveSettings(cfg);
    m_treeOptionsPanel.saveSettings(cfg);
    m_ensembleOptionsPanel.saveSettings(cfg);
    cfg.save(settings);
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration)

Example 19 with TreeEnsembleLearnerConfiguration

use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.

the class TreeEnsembleRegressionLearnerNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    final DataTableSpec inSpec = specs[0];
    TreeEnsembleLearnerConfiguration cfg = new TreeEnsembleLearnerConfiguration(true);
    cfg.loadInDialog(settings, inSpec);
    m_attributeSelectionPanel.loadSettingsFrom(inSpec, cfg);
    m_treeOptionsPanel.loadSettingsFrom(inSpec, cfg);
    m_ensembleOptionsPanel.loadSettings(cfg);
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration) DataTableSpec(org.knime.core.data.DataTableSpec)

Example 20 with TreeEnsembleLearnerConfiguration

use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.

the class RandomForestRegressionLearnerNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(true);
    config.loadInModel(settings);
    m_configuration = config;
}
Also used : TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration)

Aggregations

TreeEnsembleLearnerConfiguration (org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration)22 TreeData (org.knime.base.node.mine.treeensemble.data.TreeData)6 DataTableSpec (org.knime.core.data.DataTableSpec)5 TreeAttributeColumnData (org.knime.base.node.mine.treeensemble.data.TreeAttributeColumnData)4 TreeNodeMembershipController (org.knime.base.node.mine.treeensemble.data.TreeNodeMembershipController)4 TreeTargetNominalColumnData (org.knime.base.node.mine.treeensemble.data.TreeTargetNominalColumnData)3 TreeTargetNumericColumnData (org.knime.base.node.mine.treeensemble.data.TreeTargetNumericColumnData)3 BitSet (java.util.BitSet)2 ClassificationPriors (org.knime.base.node.mine.treeensemble.data.ClassificationPriors)2 RegressionPriors (org.knime.base.node.mine.treeensemble.data.RegressionPriors)2 TreeNodeClassification (org.knime.base.node.mine.treeensemble.model.TreeNodeClassification)2 TreeNodeCondition (org.knime.base.node.mine.treeensemble.model.TreeNodeCondition)2 TreeNodeRegression (org.knime.base.node.mine.treeensemble.model.TreeNodeRegression)2 TreeNodeSignature (org.knime.base.node.mine.treeensemble.model.TreeNodeSignature)2 ColumnSample (org.knime.base.node.mine.treeensemble.sample.column.ColumnSample)2 ColumnSampleStrategy (org.knime.base.node.mine.treeensemble.sample.column.ColumnSampleStrategy)2 RowSample (org.knime.base.node.mine.treeensemble.sample.row.RowSample)2 AbstractTreeModel (org.knime.base.node.mine.treeensemble.model.AbstractTreeModel)1 TreeEnsembleModel (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModel)1 TreeModelClassification (org.knime.base.node.mine.treeensemble.model.TreeModelClassification)1