Search in sources :

Example 1 with BitVectorValue

use of org.knime.core.data.vector.bitvector.BitVectorValue in project knime-core by knime.

the class AbstractTreeEnsembleModel method createLearnAttributeRow.

public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
    final TreeType type = getType();
    final DataCell c = learnRow.getCell(0);
    final int nrAttributes = getMetaData().getNrAttributes();
    switch(type) {
        case Ordinary:
            return learnRow;
        case BitVector:
            if (c.isMissing()) {
                return null;
            }
            BitVectorValue bv = (BitVectorValue) c;
            final long length = bv.length();
            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:
            if (c.isMissing()) {
                return null;
            }
            ByteVectorValue byteVector = (ByteVectorValue) c;
            final long bvLength = byteVector.length();
            if (bvLength != nrAttributes) {
                return null;
            }
            DataCell[] bvCells = new DataCell[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                bvCells[i] = new IntCell(byteVector.get(i));
            }
            return new DefaultRow(learnRow.getKey(), bvCells);
        case DoubleVector:
            if (c.isMissing()) {
                return null;
            }
            DoubleVectorValue doubleVector = (DoubleVectorValue) c;
            final int dvLength = doubleVector.getLength();
            if (dvLength != nrAttributes) {
                return null;
            }
            DataCell[] dvCells = new DataCell[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                dvCells[i] = new DoubleCell(doubleVector.getValue(i));
            }
            return new DefaultRow(learnRow.getKey(), dvCells);
        default:
            throw new IllegalStateException("Type unknown (not implemented): " + type);
    }
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue) DoubleCell(org.knime.core.data.def.DoubleCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) IntCell(org.knime.core.data.def.IntCell) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 2 with BitVectorValue

use of org.knime.core.data.vector.bitvector.BitVectorValue in project knime-core by knime.

the class TreeBitVectorColumnDataCreator method add.

/**
 * {@inheritDoc}
 */
@Override
public void add(final RowKey rowKey, final DataCell cell) {
    if (cell.isMissing()) {
        throw new IllegalStateException("Missing values not supported");
    }
    BitVectorValue v = (BitVectorValue) cell;
    final long lengthLong = v.length();
    if (lengthLong > Integer.MAX_VALUE) {
        throw new IllegalStateException("Sparse bit vectors not supported");
    }
    final int length = (int) lengthLong;
    if (m_bitSets == null) {
        m_bitSets = new BitSet[length];
        for (int i = 0; i < length; i++) {
            m_bitSets[i] = new BitSet();
        }
    } else if (m_bitSets.length != length) {
        throw new IllegalArgumentException("Bit vectors in table have different length, expected " + m_bitSets.length + " bits but got " + length + " bits in row \"" + rowKey + "\"");
    }
    for (int attrIndex = 0; attrIndex < length; attrIndex++) {
        m_bitSets[attrIndex].set(m_index, v.get(attrIndex));
    }
    m_index++;
}
Also used : BitSet(java.util.BitSet) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue)

Example 3 with BitVectorValue

use of org.knime.core.data.vector.bitvector.BitVectorValue 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 4 with BitVectorValue

use of org.knime.core.data.vector.bitvector.BitVectorValue 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 5 with BitVectorValue

use of org.knime.core.data.vector.bitvector.BitVectorValue in project knime-core by knime.

the class AbstractTrainingRowBuilder method getVectorLength.

private static long getVectorLength(final DataCell vectorCell) {
    DataType cellType = vectorCell.getType();
    long vectorLength = 0;
    if (cellType.isCompatible(BitVectorValue.class)) {
        BitVectorValue bv = (BitVectorValue) vectorCell;
        vectorLength = bv.length();
    } else if (cellType.isCompatible(ByteVectorValue.class)) {
        ByteVectorValue bv = (ByteVectorValue) vectorCell;
        vectorLength = bv.length();
    // uncomment once double vectors become compatible with PMML
    // } else if (cellType.isCompatible(DoubleVectorValue.class)) {
    // DoubleVectorValue dv = (DoubleVectorValue)vectorCell;
    // vectorLength = dv.getLength();
    // uncomment once double ists become compatible with PMML
    // } else if (vectorCell instanceof ListDataValue) {
    // ListDataValue ldv = (ListDataValue)vectorCell;
    // vectorLength = ldv.size();
    } else {
        throw new IllegalStateException("The provided cell is of unknown vector type \"" + vectorCell.getType() + "\".");
    }
    return vectorLength;
}
Also used : DataType(org.knime.core.data.DataType) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue)

Aggregations

BitVectorValue (org.knime.core.data.vector.bitvector.BitVectorValue)26 DataCell (org.knime.core.data.DataCell)14 ByteVectorValue (org.knime.core.data.vector.bytevector.ByteVectorValue)7 ArrayList (java.util.ArrayList)5 DataRow (org.knime.core.data.DataRow)5 StringCell (org.knime.core.data.def.StringCell)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 LinkedHashMap (java.util.LinkedHashMap)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 IntCell (org.knime.core.data.def.IntCell)3 DenseBitVectorCellFactory (org.knime.core.data.vector.bitvector.DenseBitVectorCellFactory)3 BitSet (java.util.BitSet)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PredictorRecord (org.knime.base.node.mine.treeensemble.data.PredictorRecord)2 DataType (org.knime.core.data.DataType)2 DoubleValue (org.knime.core.data.DoubleValue)2 RowKey (org.knime.core.data.RowKey)2 CollectionDataValue (org.knime.core.data.collection.CollectionDataValue)2