Search in sources :

Example 41 with DataType

use of org.knime.core.data.DataType in project knime-core by knime.

the class AttributeSelectionPanel method loadSettingsFrom.

/**
 * Load settings from config <b>cfg</b>
 *
 * @param inSpec
 * @param cfg
 * @throws NotConfigurableException
 */
public void loadSettingsFrom(final DataTableSpec inSpec, final TreeEnsembleLearnerConfiguration cfg) throws NotConfigurableException {
    // disabled automatic propagation of table specs
    m_lastTableSpec = null;
    int nrNominalCols = 0;
    int nrNumericCols = 0;
    for (DataColumnSpec col : inSpec) {
        DataType type = col.getType();
        if (type.isCompatible(NominalValue.class)) {
            nrNominalCols += 1;
        } else if (type.isCompatible(DoubleValue.class)) {
            nrNumericCols += 1;
        }
    }
    boolean hasOrdinaryColumnsInInput = nrNominalCols > 1 || nrNumericCols > 0;
    boolean hasFPColumnInInput = inSpec.containsCompatibleType(BitVectorValue.class) || inSpec.containsCompatibleType(ByteVectorValue.class) || inSpec.containsCompatibleType(DoubleVectorValue.class);
    m_targetColumnBox.update(inSpec, cfg.getTargetColumn());
    DataTableSpec attSpec = removeColumn(inSpec, m_targetColumnBox.getSelectedColumn());
    String fpColumn = cfg.getFingerprintColumn();
    m_useOrdinaryColumnsRadio.setEnabled(true);
    m_useFingerprintColumnRadio.setEnabled(true);
    // default, fix later
    m_useOrdinaryColumnsRadio.doClick();
    if (hasOrdinaryColumnsInInput) {
        m_includeColumnsFilterPanel2.loadConfiguration(cfg.getColumnFilterConfig(), attSpec);
    } else {
        m_useOrdinaryColumnsRadio.setEnabled(false);
        m_useFingerprintColumnRadio.doClick();
        m_includeColumnsFilterPanel2.loadConfiguration(cfg.getColumnFilterConfig(), NO_VALID_INPUT_SPEC);
    }
    if (hasFPColumnInInput) {
        m_fingerprintColumnBox.update(inSpec, fpColumn);
    } else {
        m_useOrdinaryColumnsRadio.doClick();
        m_fingerprintColumnBox.update(NO_VALID_INPUT_SPEC, "");
        m_useFingerprintColumnRadio.setEnabled(false);
        fpColumn = null;
    }
    if (fpColumn != null || !hasOrdinaryColumnsInInput) {
        m_useFingerprintColumnRadio.doClick();
    } else {
        m_useOrdinaryColumnsRadio.doClick();
    }
    boolean ignoreColsNoDomain = cfg.isIgnoreColumnsWithoutDomain();
    m_ignoreColumnsWithoutDomainChecker.setSelected(ignoreColsNoDomain);
    int hiliteCount = cfg.getNrHilitePatterns();
    if (hiliteCount > 0) {
        m_enableHiliteChecker.setSelected(true);
        m_hiliteCountSpinner.setValue(hiliteCount);
    } else {
        m_enableHiliteChecker.setSelected(false);
        m_hiliteCountSpinner.setValue(2000);
    }
    m_saveTargetDistributionInNodesChecker.setSelected(cfg.isSaveTargetDistributionInNodes());
    m_lastTableSpec = inSpec;
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType)

Example 42 with DataType

use of org.knime.core.data.DataType in project knime-core by knime.

the class AttributeSelectionPanel method getMissingColSpecName.

@SuppressWarnings("null")
private static String getMissingColSpecName(final DataTableSpec spec, final String[] includedNames, final String[] excludedNames) {
    ColumnRearranger r = new ColumnRearranger(spec);
    // remove columns we know from the include list
    for (String colName : includedNames) {
        if (spec.containsName(colName)) {
            r.remove(colName);
        }
    }
    // remove columns we know from the exclude list
    for (String colName : excludedNames) {
        if (spec.containsName(colName)) {
            r.remove(colName);
        }
    }
    DataTableSpec tableSpecWithMissing = r.createSpec();
    DataColumnSpec formerTargetSpec = null;
    // were either in the include or exclude list
    for (DataColumnSpec colSpec : tableSpecWithMissing) {
        DataType colType = colSpec.getType();
        if (colType.isCompatible(NominalValue.class) || colType.isCompatible(DoubleValue.class)) {
            formerTargetSpec = colSpec;
            break;
        }
    }
    assert formerTargetSpec != null : "The former target spec is no longer part of the table, please check.";
    return formerTargetSpec.getName();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) NominalValue(org.knime.core.data.NominalValue) DataType(org.knime.core.data.DataType)

Example 43 with DataType

use of org.knime.core.data.DataType in project knime-core by knime.

the class TreeEnsembleClassificationPredictorCellFactory2 method createFactory.

/**
 * Creates a TreeEnsembleClassificationPredictorCellFactory from the provided <b>predictor</b>
 * @param predictor
 * @return an instance of TreeEnsembleClassificationPredictorCellFactory configured according to the settings of the provided
 * <b>predictor<b>
 * @throws InvalidSettingsException
 */
public static TreeEnsembleClassificationPredictorCellFactory2 createFactory(final TreeEnsemblePredictor predictor) throws InvalidSettingsException {
    DataTableSpec testDataSpec = predictor.getDataSpec();
    TreeEnsembleModelPortObjectSpec modelSpec = predictor.getModelSpec();
    TreeEnsembleModelPortObject modelObject = predictor.getModelObject();
    TreeEnsemblePredictorConfiguration configuration = predictor.getConfiguration();
    UniqueNameGenerator nameGen = new UniqueNameGenerator(testDataSpec);
    Map<String, DataCell> targetValueMap = modelSpec.getTargetColumnPossibleValueMap();
    List<DataColumnSpec> newColsList = new ArrayList<DataColumnSpec>();
    DataType targetColType = modelSpec.getTargetColumn().getType();
    String targetColName = configuration.getPredictionColumnName();
    DataColumnSpec targetCol = nameGen.newColumn(targetColName, targetColType);
    newColsList.add(targetCol);
    if (configuration.isAppendPredictionConfidence()) {
        newColsList.add(nameGen.newColumn(targetCol.getName() + " (Confidence)", DoubleCell.TYPE));
    }
    if (configuration.isAppendClassConfidences()) {
        // and this class is not called)
        assert targetValueMap != null : "Target column has no possible values";
        for (String v : targetValueMap.keySet()) {
            newColsList.add(nameGen.newColumn(v, DoubleCell.TYPE));
        }
    }
    if (configuration.isAppendModelCount()) {
        newColsList.add(nameGen.newColumn("model count", IntCell.TYPE));
    }
    // assigned
    assert modelObject == null || targetValueMap != null : "Target values must be known during execution";
    DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
    int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
    return new TreeEnsembleClassificationPredictorCellFactory2(predictor, targetValueMap, newCols, learnColumnInRealDataIndices);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) TreeEnsemblePredictorConfiguration(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictorConfiguration) ArrayList(java.util.ArrayList) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType)

Example 44 with DataType

use of org.knime.core.data.DataType in project knime-core by knime.

the class MissingValueHandling2ColSetting method loadSettings.

/**
 * Loads settings from a NodeSettings object, used in
 * {@link org.knime.core.node.NodeModel}.
 *
 * @param settings the (sub-) config to load from
 * @throws InvalidSettingsException if any setting is missing
 */
protected void loadSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    // may be null to indicate meta config
    String[] names = null;
    if (settings.containsKey(CFG_COLNAME)) {
        try {
            names = settings.getStringArray(CFG_COLNAME);
        } catch (InvalidSettingsException ise) {
            // fallback to be compatible with <2.5
            String name = settings.getString(CFG_COLNAME);
            if (name != null) {
                names = new String[] { name };
            }
        }
    }
    int method = settings.getInt(CFG_METHOD);
    int type = settings.getInt(CFG_TYPE);
    DataCell fixVal = null;
    switch(method) {
        case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
        case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
        case MissingValueHandling2ColSetting.METHOD_MEAN:
        case MissingValueHandling2ColSetting.METHOD_MIN:
        case MissingValueHandling2ColSetting.METHOD_MAX:
        case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
            break;
        case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
            DataType superType;
            String errorType;
            switch(type) {
                case MissingValueHandling2ColSetting.TYPE_DOUBLE:
                    fixVal = settings.getDataCell(CFG_FIXVAL);
                    superType = DoubleCell.TYPE;
                    errorType = "Type Double";
                    break;
                case MissingValueHandling2ColSetting.TYPE_INT:
                    fixVal = settings.getDataCell(CFG_FIXVAL);
                    superType = IntCell.TYPE;
                    errorType = "Type Int";
                    break;
                case MissingValueHandling2ColSetting.TYPE_STRING:
                    superType = StringCell.TYPE;
                    fixVal = settings.getDataCell(CFG_FIXVAL);
                    errorType = "Type String";
                    break;
                default:
                    throw new InvalidSettingsException("Unable to define fix value for unknown type");
            }
            if (fixVal == null) {
                throw new InvalidSettingsException("No replacement value for column: " + (isMetaConfig() ? "meta" : Arrays.toString(m_names)) + "(" + errorType + ")");
            }
            if (!superType.isASuperTypeOf(fixVal.getType())) {
                throw new InvalidSettingsException("Wrong type of replacement value for column: " + (isMetaConfig() ? "meta" : Arrays.toString(m_names)) + "(" + errorType + "): " + fixVal.getType());
            }
            break;
        default:
            throw new InvalidSettingsException("Unknown method: " + method);
    }
    m_names = names;
    m_method = method;
    m_type = type;
    m_fixCell = fixVal;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType)

Example 45 with DataType

use of org.knime.core.data.DataType in project knime-core by knime.

the class CollectionSplitNodeModel method getColSpecsByElementNames.

/**
 * Get new column specs as inferred from the element names in the
 * collection column.
 */
private DataColumnSpec[] getColSpecsByElementNames(final DataTableSpec spec) throws InvalidSettingsException {
    int colIndex = getTargetColIndex(spec);
    DataColumnSpec colSpec = spec.getColumnSpec(colIndex);
    List<String> elementNames = colSpec.getElementNames();
    if (elementNames.isEmpty()) {
        throw new InvalidSettingsException("Input column \"" + colSpec.getName() + "\" does not provide element names; " + "consider to change option in dialog or make sure that" + "the input table contains the necessary information.");
    }
    DataType type = colSpec.getType().getCollectionElementType();
    HashSet<String> hashNames = new HashSet<String>();
    for (DataColumnSpec s : spec) {
        hashNames.add(s.getName());
    }
    if (m_settings.isReplaceInputColumn()) {
        hashNames.remove(colSpec.getName());
    }
    DataColumnSpec[] newColSpec = new DataColumnSpec[elementNames.size()];
    for (int i = 0; i < newColSpec.length; i++) {
        String baseName = elementNames.get(i);
        int uniquifier = 1;
        while (!hashNames.add(baseName)) {
            baseName = elementNames.get(i) + "(#" + (uniquifier++) + ")";
        }
        newColSpec[i] = new DataColumnSpecCreator(baseName, type).createSpec();
    }
    return newColSpec;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) HashSet(java.util.HashSet)

Aggregations

DataType (org.knime.core.data.DataType)330 DataColumnSpec (org.knime.core.data.DataColumnSpec)142 DataTableSpec (org.knime.core.data.DataTableSpec)101 DataCell (org.knime.core.data.DataCell)96 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)95 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)71 DoubleValue (org.knime.core.data.DoubleValue)67 DataRow (org.knime.core.data.DataRow)61 ArrayList (java.util.ArrayList)55 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)34 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)32 DefaultRow (org.knime.core.data.def.DefaultRow)24 HashSet (java.util.HashSet)23 HashMap (java.util.HashMap)20 StringCell (org.knime.core.data.def.StringCell)20 NominalValue (org.knime.core.data.NominalValue)18 DoubleCell (org.knime.core.data.def.DoubleCell)18 IntCell (org.knime.core.data.def.IntCell)18 BitVectorValue (org.knime.core.data.vector.bitvector.BitVectorValue)18 ByteVectorValue (org.knime.core.data.vector.bytevector.ByteVectorValue)18