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