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;
}
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++;
}
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);
}
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);
}
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;
}
Aggregations