Search in sources :

Example 51 with DataColumnSpecCreator

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

the class DataColumnSpecListCellRenderer method createInvalidSpec.

/**
 * @param colName the name of the invalid column
 * @param type Type of the column
 * @return the invalid {@link DataColumnSpec} for the given name and type
 * @since 2.9
 */
public static DataColumnSpec createInvalidSpec(final String colName, final DataType type) {
    DataColumnSpecCreator creator = new DataColumnSpecCreator(colName, type);
    creator.setProperties(new DataColumnProperties(creaeteInvalidPropertiesMap()));
    return creator.createSpec();
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnProperties(org.knime.core.data.DataColumnProperties)

Example 52 with DataColumnSpecCreator

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

the class TreeEnsembleLearner method getColumnStatisticTableSpec.

public static synchronized DataTableSpec getColumnStatisticTableSpec() {
    if (COLUMN_STAT_TABLE_SPEC == null) {
        DataColumnSpec[] cols = new DataColumnSpec[2 * REPORT_LEVEL];
        for (int level = 0; level < REPORT_LEVEL; level++) {
            String splitName = "#splits (level " + level + ")";
            String candidateName = "#candidates (level " + level + ")";
            cols[level] = new DataColumnSpecCreator(splitName, IntCell.TYPE).createSpec();
            cols[REPORT_LEVEL + level] = new DataColumnSpecCreator(candidateName, IntCell.TYPE).createSpec();
        }
        COLUMN_STAT_TABLE_SPEC = new DataTableSpec("Tree Ensemble Column Statistic", cols);
    }
    return COLUMN_STAT_TABLE_SPEC;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator)

Example 53 with DataColumnSpecCreator

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

the class TreeNominalColumnDataTest method createPCATestData.

private static Pair<TreeNominalColumnData, TreeTargetNominalColumnData> createPCATestData(final TreeEnsembleLearnerConfiguration config) {
    DataColumnSpec colSpec = new DataColumnSpecCreator("test-col", StringCell.TYPE).createSpec();
    final String[] attVals = new String[] { "A", "B", "C", "D", "E" };
    final String[] classes = new String[] { "T1", "T2", "T3" };
    TreeNominalColumnDataCreator colCreator = new TreeNominalColumnDataCreator(colSpec);
    DataColumnSpecCreator specCreator = new DataColumnSpecCreator("target-col", StringCell.TYPE);
    specCreator.setDomain(new DataColumnDomainCreator(Arrays.stream(classes).distinct().map(s -> new StringCell(s)).toArray(i -> new StringCell[i])).createDomain());
    DataColumnSpec targetSpec = specCreator.createSpec();
    TreeTargetColumnDataCreator targetCreator = new TreeTargetNominalColumnDataCreator(targetSpec);
    long rowKeyCounter = 0;
    final int[][] classDistributions = new int[][] { { 40, 10, 10 }, { 10, 40, 10 }, { 20, 30, 10 }, { 20, 15, 25 }, { 10, 5, 45 } };
    for (int i = 0; i < attVals.length; i++) {
        for (int j = 0; j < classes.length; j++) {
            for (int k = 0; k < classDistributions[i][j]; k++) {
                RowKey key = RowKey.createRowKey(rowKeyCounter++);
                colCreator.add(key, new StringCell(attVals[i]));
                targetCreator.add(key, new StringCell(classes[j]));
            }
        }
    }
    final TreeNominalColumnData testColData = colCreator.createColumnData(0, config);
    testColData.getMetaData().setAttributeIndex(0);
    return Pair.create(testColData, (TreeTargetNominalColumnData) targetCreator.createColumnData());
}
Also used : Arrays(java.util.Arrays) RandomData(org.apache.commons.math.random.RandomData) RowKey(org.knime.core.data.RowKey) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SplitCriterion(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.SplitCriterion) DataMemberships(org.knime.base.node.mine.treeensemble2.data.memberships.DataMemberships) TreeNodeNominalCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalCondition) Pair(org.knime.core.util.Pair) Assert.assertThat(org.junit.Assert.assertThat) ColumnSamplingMode(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.ColumnSamplingMode) TreeEnsembleLearnerConfiguration(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) NominalMultiwaySplitCandidate(org.knime.base.node.mine.treeensemble2.learner.NominalMultiwaySplitCandidate) SetLogic(org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalBinaryCondition.SetLogic) NominalBinarySplitCandidate(org.knime.base.node.mine.treeensemble2.learner.NominalBinarySplitCandidate) BigInteger(java.math.BigInteger) TreeNodeNominalBinaryCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeNominalBinaryCondition) SplitCandidate(org.knime.base.node.mine.treeensemble2.learner.SplitCandidate) TreeType(org.knime.base.node.mine.treeensemble2.model.AbstractTreeEnsembleModel.TreeType) Assert.assertNotNull(org.junit.Assert.assertNotNull) IDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.IDataIndexManager) RootDataMemberships(org.knime.base.node.mine.treeensemble2.data.memberships.RootDataMemberships) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.DefaultDataIndexManager) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) StringCell(org.knime.core.data.def.StringCell) BitSet(java.util.BitSet) MissingValueHandling(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.MissingValueHandling) Assert.assertEquals(org.junit.Assert.assertEquals) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell)

Example 54 with DataColumnSpecCreator

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

the class BlobsInSetCellWorkflowTest method createBDT.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable createBDT(final ExecutionContext exec) {
    DataType t = ListCell.getCollectionType(DataType.getType(DataCell.class));
    BufferedDataContainer c = exec.createDataContainer(new DataTableSpec(new DataColumnSpecCreator("Sequence", t).createSpec()));
    for (int i = 0; i < ROW_COUNT; i++) {
        String s = "someName_" + i;
        // every other a ordinary string cell
        Collection<DataCell> cells = new ArrayList<DataCell>();
        for (int j = 0; j < LIST_SIZE * 2; j++) {
            String val = "Row_" + i + "; Cell index " + j;
            if (j % 2 == 0) {
                cells.add(new LargeBlobCell(val, LargeBlobCell.SIZE_OF_CELL));
            } else {
                cells.add(new StringCell(val));
            }
        }
        ListCell cell = CollectionCellFactory.createListCell(cells);
        c.addRowToTable(new DefaultRow(s, cell));
    }
    c.close();
    return c.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ListCell(org.knime.core.data.collection.ListCell) ArrayList(java.util.ArrayList) LargeBlobCell(org.knime.testing.data.blob.LargeBlobCell) StringCell(org.knime.core.data.def.StringCell) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 55 with DataColumnSpecCreator

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

the class RegressionTreeModel method getLearnAttributeSpec.

/**
 * Get a table spec representing the learn attributes (not the target!). For ordinary data it is just a subset of
 * the input columns, for bit vector data it's an expanded table spec with each bit represented by a StringCell
 * column ("0" or "1"), whose name is "Bit x".
 *
 * @param learnSpec The original learn spec (which is also the return value for ordinary data)
 * @return Such a learn attribute spec.
 */
public DataTableSpec getLearnAttributeSpec(final DataTableSpec learnSpec) {
    final TreeType type = getType();
    switch(type) {
        case Ordinary:
            return learnSpec;
        case BitVector:
            int nrAttributes = getMetaData().getNrAttributes();
            DataColumnSpec[] colSpecs = new DataColumnSpec[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                colSpecs[i] = new DataColumnSpecCreator(TreeBitColumnMetaData.getAttributeName(i), StringCell.TYPE).createSpec();
            }
            return new DataTableSpec(colSpecs);
        case ByteVector:
            int nrAttr = getMetaData().getNrAttributes();
            DataColumnSpec[] bvColSpecs = new DataColumnSpec[nrAttr];
            for (int i = 0; i < nrAttr; i++) {
                bvColSpecs[i] = new DataColumnSpecCreator(TreeNumericColumnMetaData.getAttributeName(i), IntCell.TYPE).createSpec();
            }
            return new DataTableSpec(bvColSpecs);
        default:
            throw new IllegalStateException("Type unknown (not implemented): " + type);
    }
}
Also used : TreeType(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModel.TreeType) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator)

Aggregations

DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)267 DataColumnSpec (org.knime.core.data.DataColumnSpec)210 DataTableSpec (org.knime.core.data.DataTableSpec)132 DataCell (org.knime.core.data.DataCell)92 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)77 DataType (org.knime.core.data.DataType)74 DataRow (org.knime.core.data.DataRow)73 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)57 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)51 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)48 ArrayList (java.util.ArrayList)46 DoubleCell (org.knime.core.data.def.DoubleCell)45 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)44 StringCell (org.knime.core.data.def.StringCell)29 BufferedDataTable (org.knime.core.node.BufferedDataTable)23 DoubleValue (org.knime.core.data.DoubleValue)22 HashSet (java.util.HashSet)19 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)17 DataColumnDomain (org.knime.core.data.DataColumnDomain)16 DefaultRow (org.knime.core.data.def.DefaultRow)16