Search in sources :

Example 16 with BitVectorValue

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

the class BitVectorXOrOperator method computeInternal.

/**
 * {@inheritDoc}
 */
@Override
protected boolean computeInternal(final DataCell cell) {
    if (cell instanceof BitVectorValue) {
        final BitVectorValue val = (BitVectorValue) cell;
        if (m_v == null) {
            m_v = new DenseBitVectorCellFactory(val.length());
            m_allSetBits = new DenseBitVectorCellFactory(val.length());
        }
        long nextSetBit = val.nextSetBit(0);
        while (nextSetBit >= 0) {
            if (!m_allSetBits.get(nextSetBit)) {
                m_v.set(nextSetBit);
            } else {
                m_v.set(nextSetBit, false);
            }
            m_allSetBits.set(nextSetBit);
            nextSetBit = val.nextSetBit(nextSetBit + 1);
        }
    }
    return false;
}
Also used : BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DenseBitVectorCellFactory(org.knime.core.data.vector.bitvector.DenseBitVectorCellFactory)

Example 17 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 18 with BitVectorValue

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

the class RegressionTreeModel method createBitVectorPredictorRecord.

private PredictorRecord createBitVectorPredictorRecord(final DataRow filterRow) {
    assert filterRow.getNumCells() == 1 : "Expected one cell as bit vector data";
    DataCell c = filterRow.getCell(0);
    if (c.isMissing()) {
        return null;
    }
    BitVectorValue bv = (BitVectorValue) c;
    final long length = bv.length();
    if (length != getMetaData().getNrAttributes()) {
        throw new IllegalArgumentException("The bit-vector in " + filterRow.getKey().getString() + " has an invalid length (" + length + " instead of " + getMetaData().getNrAttributes() + ").");
    }
    Map<String, Object> valueMap = new LinkedHashMap<String, Object>((int) (length / 0.75 + 1.0));
    for (int i = 0; i < length; i++) {
        valueMap.put(TreeBitColumnMetaData.getAttributeName(i), Boolean.valueOf(bv.get(i)));
    }
    return new PredictorRecord(valueMap);
}
Also used : PredictorRecord(org.knime.base.node.mine.treeensemble.data.PredictorRecord) DataCell(org.knime.core.data.DataCell) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with BitVectorValue

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

the class TreeEnsembleModel method createBitVectorPredictorRecord.

private PredictorRecord createBitVectorPredictorRecord(final DataRow filterRow) {
    assert filterRow.getNumCells() == 1 : "Expected one cell as bit vector data";
    DataCell c = filterRow.getCell(0);
    if (c.isMissing()) {
        return null;
    }
    BitVectorValue bv = (BitVectorValue) c;
    final long length = bv.length();
    if (length != getMetaData().getNrAttributes()) {
        throw new IllegalArgumentException("The bit-vector in " + filterRow.getKey().getString() + " has the wrong length. (" + length + " instead of " + getMetaData().getNrAttributes() + ")");
    }
    Map<String, Object> valueMap = new LinkedHashMap<String, Object>((int) (length / 0.75 + 1.0));
    for (int i = 0; i < length; i++) {
        valueMap.put(TreeBitColumnMetaData.getAttributeName(i), Boolean.valueOf(bv.get(i)));
    }
    return new PredictorRecord(valueMap);
}
Also used : PredictorRecord(org.knime.base.node.mine.treeensemble.data.PredictorRecord) DataCell(org.knime.core.data.DataCell) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with BitVectorValue

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

the class RegressionTrainingData method maxLength.

/**
 * @param data
 * @param i
 * @param missingValueHandling
 * @param lengthConstraint
 * @return
 * @throws InvalidSettingsException
 */
private long maxLength(final BufferedDataTable data, final int i, final SameLengthVectors lengthConstraint, final AllowMissing missingValueHandling) throws InvalidSettingsException {
    long maxLength = 0;
    for (final DataRow dataRow : data) {
        final DataCell cell = dataRow.getCell(i);
        if (cell.isMissing()) {
            switch(missingValueHandling) {
                case NoMissing:
                    throw new InvalidSettingsException("There are missing values in the column with index (from 1): " + (i + 1));
                case SkipMissing:
                    // the loop
                    continue;
                default:
                    throw new UnsupportedOperationException("Not supported missing value handling: " + missingValueHandling);
            }
        }
        long vectorLength;
        if (cell instanceof BitVectorValue) {
            BitVectorValue bvv = (BitVectorValue) cell;
            vectorLength = bvv.length();
        } else if (cell instanceof ByteVectorValue) {
            ByteVectorValue bvv = (ByteVectorValue) cell;
            vectorLength = bvv.length();
        } else if (cell instanceof ListDataValue) {
            ListDataValue ldv = (ListDataValue) cell;
            vectorLength = ldv.size();
        } else {
            throw new IllegalStateException("Wrong type of value in the column with index (from 1): " + (i + 1) + " : " + cell.getType());
        }
        switch(lengthConstraint) {
            case BoundedLength:
                maxLength = Math.max(maxLength, vectorLength);
                break;
            case SameLength:
                if (maxLength == 0) {
                    maxLength = vectorLength;
                } else if (maxLength != vectorLength) {
                    throw new InvalidSettingsException("There are different length vectors in the column with index (from 1): " + (i + 1) + " which are: " + maxLength + " and " + vectorLength);
                }
                break;
            default:
                throw new UnsupportedOperationException("Not supported length constraint: " + lengthConstraint);
        }
    }
    return maxLength;
}
Also used : ListDataValue(org.knime.core.data.collection.ListDataValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DataRow(org.knime.core.data.DataRow)

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