Search in sources :

Example 26 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class RegressionTreeModel method createLearnAttributeRow.

public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
    final TreeType type = getType();
    switch(type) {
        case Ordinary:
            return learnRow;
        case BitVector:
            DataCell c = learnRow.getCell(0);
            if (c.isMissing()) {
                return null;
            }
            BitVectorValue bv = (BitVectorValue) c;
            final long length = bv.length();
            int nrAttributes = getMetaData().getNrAttributes();
            if (length != nrAttributes) {
                // TODO indicate error message
                return null;
            }
            DataCell trueCell = new StringCell("1");
            DataCell falseCell = new StringCell("0");
            DataCell[] cells = new DataCell[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                cells[i] = bv.get(i) ? trueCell : falseCell;
            }
            return new DefaultRow(learnRow.getKey(), cells);
        case ByteVector:
            DataCell cell = learnRow.getCell(0);
            if (cell.isMissing()) {
                return null;
            }
            ByteVectorValue byteVector = (ByteVectorValue) cell;
            final long bvLength = byteVector.length();
            int nrAttr = getMetaData().getNrAttributes();
            if (bvLength != nrAttr) {
                return null;
            }
            DataCell[] bvCells = new DataCell[nrAttr];
            for (int i = 0; i < nrAttr; i++) {
                bvCells[i] = new IntCell(byteVector.get(i));
            }
            return new DefaultRow(learnRow.getKey(), bvCells);
        default:
            throw new IllegalStateException("Type unknown (not implemented): " + type);
    }
}
Also used : TreeType(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModel.TreeType) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 27 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class TreeEnsembleModel method createLearnAttributeRow.

public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
    final TreeType type = getType();
    switch(type) {
        case Ordinary:
            return learnRow;
        case BitVector:
            DataCell c = learnRow.getCell(0);
            if (c.isMissing()) {
                return null;
            }
            BitVectorValue bv = (BitVectorValue) c;
            final long length = bv.length();
            int nrAttributes = getMetaData().getNrAttributes();
            if (length != nrAttributes) {
                // TODO indicate error message
                return null;
            }
            DataCell trueCell = new StringCell("1");
            DataCell falseCell = new StringCell("0");
            DataCell[] cells = new DataCell[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                cells[i] = bv.get(i) ? trueCell : falseCell;
            }
            return new DefaultRow(learnRow.getKey(), cells);
        case ByteVector:
            DataCell cell = learnRow.getCell(0);
            if (cell.isMissing()) {
                return null;
            }
            ByteVectorValue byteVector = (ByteVectorValue) cell;
            final long bvLength = byteVector.length();
            int nrAttr = getMetaData().getNrAttributes();
            if (bvLength != nrAttr) {
                return null;
            }
            DataCell[] bvCells = new DataCell[nrAttr];
            for (int i = 0; i < nrAttr; i++) {
                bvCells[i] = new IntCell(byteVector.get(i));
            }
            return new DefaultRow(learnRow.getKey(), bvCells);
        default:
            throw new IllegalStateException("Type unknown (not implemented): " + type);
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 28 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class TestDataGenerator method createNominalTargetColumn.

public static TreeTargetNominalColumnData createNominalTargetColumn(final String[] values) {
    DataColumnDomainCreator dc = new DataColumnDomainCreator(Arrays.stream(values).distinct().map(s -> new StringCell(s)).toArray(i -> new StringCell[i]));
    DataColumnSpecCreator specCreator = new DataColumnSpecCreator("test-target", StringCell.TYPE);
    specCreator.setDomain(dc.createDomain());
    DataColumnSpec targetSpec = specCreator.createSpec();
    TreeTargetColumnDataCreator targetCreator = new TreeTargetNominalColumnDataCreator(targetSpec);
    for (int i = 0; i < values.length; i++) {
        RowKey rowKey = RowKey.createRowKey((long) i);
        targetCreator.add(rowKey, new StringCell(values[i]));
    }
    return (TreeTargetNominalColumnData) targetCreator.createColumnData();
}
Also used : JDKRandomGenerator(org.apache.commons.math.random.JDKRandomGenerator) TreeType(org.knime.base.node.mine.treeensemble2.model.AbstractTreeEnsembleModel.TreeType) Arrays(java.util.Arrays) RandomData(org.apache.commons.math.random.RandomData) RowKey(org.knime.core.data.RowKey) RandomDataImpl(org.apache.commons.math.random.RandomDataImpl) DoubleCell(org.knime.core.data.def.DoubleCell) Lists(com.google.common.collect.Lists) 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) MissingCell(org.knime.core.data.MissingCell) Doubles(com.google.common.primitives.Doubles) StringCell(org.knime.core.data.def.StringCell) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) RowKey(org.knime.core.data.RowKey) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 29 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class TestDataGenerator method createNominalAttributeColumn.

public TreeNominalColumnData createNominalAttributeColumn(final String[] values, final String name, final int attributeIndex) {
    DataColumnSpec colSpec = new DataColumnSpecCreator(name, StringCell.TYPE).createSpec();
    TreeNominalColumnDataCreator colCreator = new TreeNominalColumnDataCreator(colSpec);
    for (int i = 0; i < values.length; i++) {
        RowKey rowKey = RowKey.createRowKey((long) i);
        if (values[i].equals("?")) {
            colCreator.add(rowKey, new MissingCell(null));
        } else {
            colCreator.add(rowKey, new StringCell(values[i]));
        }
    }
    TreeNominalColumnData col = colCreator.createColumnData(0, m_config);
    col.getMetaData().setAttributeIndex(attributeIndex);
    return col;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) MissingCell(org.knime.core.data.MissingCell) StringCell(org.knime.core.data.def.StringCell)

Example 30 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class JoinedTableTest method getRandomRow.

private static final DataRow getRandomRow(final String id) {
    DataCell[] cells = new DataCell[3];
    cells[0] = new StringCell(id + "-" + RAND.nextInt(100));
    cells[1] = new IntCell(RAND.nextInt());
    cells[2] = new DoubleCell(RAND.nextDouble());
    return new DefaultRow(id, cells);
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Aggregations

StringCell (org.knime.core.data.def.StringCell)176 DataCell (org.knime.core.data.DataCell)130 DoubleCell (org.knime.core.data.def.DoubleCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)65 IntCell (org.knime.core.data.def.IntCell)55 DataRow (org.knime.core.data.DataRow)52 DataTableSpec (org.knime.core.data.DataTableSpec)49 ArrayList (java.util.ArrayList)41 DataColumnSpec (org.knime.core.data.DataColumnSpec)37 RowKey (org.knime.core.data.RowKey)36 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)26 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)26 DataType (org.knime.core.data.DataType)22 LinkedHashSet (java.util.LinkedHashSet)21 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)19 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)16 LinkedHashMap (java.util.LinkedHashMap)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)11