Search in sources :

Example 21 with ModelContentRO

use of org.knime.core.node.ModelContentRO in project knime-core by knime.

the class DecisionTree method loadFromPredictorParams.

/**
 * Load Decision Tree from a ModelContent object.
 *
 * @param pConf configuration object to load decision tree from
 * @throws InvalidSettingsException if something goes wrong
 */
public void loadFromPredictorParams(final ModelContentRO pConf) throws InvalidSettingsException {
    String type = pConf.getString("type");
    String version = pConf.getString("version");
    // added in v2.3
    m_colorColumn = pConf.getString("color_column", null);
    if (!type.equals("DecisionTree")) {
        throw new InvalidSettingsException("DecisionTree cannot load" + " information of type '" + type + "'!");
    }
    if (!version.equals("0.0")) {
        throw new InvalidSettingsException("DecisionTree v0.0 cannot" + " load information of version '" + type + "'!");
    }
    ModelContentRO newNodeConf = pConf.getModelContent("rootNode");
    m_rootNode = DecisionTreeNode.createNodeFromPredictorParams(newNodeConf, null);
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 22 with ModelContentRO

use of org.knime.core.node.ModelContentRO in project knime-core by knime.

the class DecisionTreeNodeSplit method loadNodeInternalsFromPredParams.

/**
 * {@inheritDoc}
 */
@Override
public final void loadNodeInternalsFromPredParams(final ModelContentRO pConf) throws InvalidSettingsException {
    loadNodeSplitInternalsFromPredParams(pConf);
    m_splitAttr = pConf.getString("splitAttribute");
    int nrKids = pConf.getInt("nrChildren");
    m_child = new DecisionTreeNode[nrKids];
    m_childIndex = new int[nrKids];
    for (int i = 0; i < nrKids; i++) {
        ModelContentRO newChildConf = pConf.getModelContent("child" + i);
        m_child[i] = DecisionTreeNode.createNodeFromPredictorParams(newChildConf, this);
    // int kidIndex = newChildConf.getInt("index");
    // if (!getPrefix().equals("root")
    // && kidIndex != m_child[i].getOwnIndex()) {
    // throw new InvalidSettingsException("DecisionTreeNode: Expected"
    // + " index does not match real index: " + kidIndex
    // + " != " + m_child[i].getOwnIndex());
    // }
    }
    // no need to store or load these, since they are only used to
    // speed up subsequent access to the same attribute:
    m_previousSpec = null;
    m_previousIndex = -1;
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO)

Example 23 with ModelContentRO

use of org.knime.core.node.ModelContentRO in project knime-core by knime.

the class DecTreePredictorNodeModel method loadInternals.

/**
 * Load internals.
 *
 * @param nodeInternDir The intern node directory to load tree from.
 * @param exec Used to report progress or cancel saving.
 * @throws IOException Always, since this method has not been implemented
 *             yet.
 * @see org.knime.core.node.NodeModel
 *      #loadInternals(java.io.File,ExecutionMonitor)
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    // read the decision tree
    File internalsFile = new File(nodeInternDir, INTERNALS_FILE_NAME);
    if (!internalsFile.exists()) {
        // file to load internals from not available
        setWarningMessage("Internal model could not be loaded.");
        return;
    }
    BufferedInputStream in2 = new BufferedInputStream(new GZIPInputStream(new FileInputStream(internalsFile)));
    ModelContentRO binModel = ModelContent.loadFromXML(in2);
    try {
        m_decTree = new DecisionTree(binModel);
    } catch (InvalidSettingsException ise) {
        LOGGER.warn("Model (internals) could not be loaded.", ise);
        setWarningMessage("Internal model could not be loaded.");
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) ModelContentRO(org.knime.core.node.ModelContentRO) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 24 with ModelContentRO

use of org.knime.core.node.ModelContentRO in project knime-core by knime.

the class SotaTreeCell method loadFrom.

/**
 * Loads the values from the given <code>ModelContentWO</code>.
 *
 * @param modelContent The <code>ModelContentWO</code> to load the cells
 * from.
 * @param index The index of the cell to load.
 * @param anchestor The anchsetor cell of the cell to load.
 * @param isLeft Specifies if the cell to load is a cell at the left side of
 * its anchestor.
 *
 * @throws InvalidSettingsException If setting to load is not valid.
 */
public void loadFrom(final ModelContentRO modelContent, final int index, final SotaTreeCell anchestor, final boolean isLeft) throws InvalidSettingsException {
    int ind = index;
    ind++;
    // load resource etc.
    m_isCell = modelContent.getBoolean(CFG_KEY_IS_CELL);
    m_resource = modelContent.getDouble(CFG_KEY_RESOURCE);
    m_maxDistance = modelContent.getDouble(CFG_KEY_MAX_DISTANCE);
    // load level information
    m_level = modelContent.getInt(CFG_KEY_LEVEL);
    m_hierarchyLevel = modelContent.getInt(CFG_KEY_H_LEVEL);
    m_levelInHierarchy = modelContent.getInt(CFG_KEY_LEVEL_IN_H);
    // load data ids
    int size = modelContent.getInt(CFG_KEY_DATA_ID + "SIZE");
    m_dataIds = new ArrayList<Integer>();
    int dataIdCount = 0;
    for (int i = 0; i < size; i++) {
        m_dataIds.add(modelContent.getInt(CFG_KEY_DATA_ID + dataIdCount));
        dataIdCount++;
    }
    // load row keys
    size = modelContent.getInt(CFG_KEY_ROW_KEY + "SIZE");
    m_rowKeys = new ArrayList<RowKey>();
    int rowKeyCount = 0;
    for (int i = 0; i < size; i++) {
        m_rowKeys.add(new RowKey(modelContent.getString(CFG_KEY_ROW_KEY + rowKeyCount)));
        rowKeyCount++;
    }
    // load data
    String type = "";
    size = modelContent.getInt(CFG_KEY_DATA + "SIZE");
    if (size > 0) {
        type = modelContent.getString(CFG_KEY_DATA + "TYPE");
        m_data = new SotaCell[size];
    }
    for (int i = 0; i < size; i++) {
        ModelContentRO subContent = modelContent.getModelContent(CFG_KEY_DATA + i);
        m_data[i] = SotaCellFactory.createSotaCell(type);
        m_data[i].loadFrom(subContent);
    }
    // load data
    String cellClass = modelContent.getString(CFG_KEY_CLASS);
    m_classCounter = new CellClassCounter();
    m_classCounter.addClass(cellClass);
    // load left and right
    boolean hasLeft = modelContent.getBoolean("HAS" + CFG_KEY_LEFT);
    boolean hasRight = modelContent.getBoolean("HAS" + CFG_KEY_RIGHT);
    if (hasLeft) {
        ModelContentRO subContent = modelContent.getModelContent(CFG_KEY_LEFT + ind);
        m_left = new SotaTreeCell(0, true);
        m_left.loadFrom(subContent, ind, this, true);
    } else {
        m_left = null;
    }
    if (hasRight) {
        ModelContentRO subContent = modelContent.getModelContent(CFG_KEY_RIGHT + ind);
        m_right = new SotaTreeCell(0, true);
        m_right.loadFrom(subContent, ind, this, false);
    } else {
        m_right = null;
    }
    // set anchestor
    if (anchestor != null) {
        this.setAncestor(anchestor);
    }
    // set sister
    if (!isLeft) {
        if (this.getAncestor() != null) {
            SotaTreeCell leftSister = this.getAncestor().getLeft();
            if (leftSister != null) {
                this.setSister(leftSister);
                leftSister.setSister(this);
            }
        }
    }
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO) RowKey(org.knime.core.data.RowKey)

Example 25 with ModelContentRO

use of org.knime.core.node.ModelContentRO in project knime-core by knime.

the class BasisFunctionLearnerNodeView method getNextValue.

private void getNextValue(final ModelContentRO pp, final StringBuilder buf) {
    for (String key : pp.keySet()) {
        String value = pp.getString(key, null);
        if (value == null) {
            try {
                ModelContentRO nextCont = pp.getModelContent(key);
                buf.append("<ul>");
                getNextValue(nextCont, buf);
                buf.append("</ul>");
            } catch (InvalidSettingsException ise) {
                LOGGER.coding("Could not find model content for key: " + key, ise);
            }
        } else {
            buf.append("<li>" + key + " " + value + "\n</li>");
        }
    }
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

ModelContentRO (org.knime.core.node.ModelContentRO)32 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)19 IOException (java.io.IOException)16 File (java.io.File)15 FileInputStream (java.io.FileInputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 GZIPInputStream (java.util.zip.GZIPInputStream)11 DataTableSpec (org.knime.core.data.DataTableSpec)6 DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5 ArrayList (java.util.ArrayList)3 ZipEntry (java.util.zip.ZipEntry)3 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)3 ZipInputStream (java.util.zip.ZipInputStream)2 GroupKey (org.knime.base.node.preproc.groupby.GroupKey)2 ContainerTable (org.knime.core.data.container.ContainerTable)2 NonClosableInputStream (org.knime.core.data.util.NonClosableInputStream)2 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1