use of org.knime.core.data.vector.bytevector.ByteVectorValue in project knime-core by knime.
the class AbstractTreeEnsembleModel method createByteVectorPredictorRecord.
private PredictorRecord createByteVectorPredictorRecord(final DataRow filterRow) {
assert filterRow.getNumCells() == 1 : "Expected one cell as byte vector data";
DataCell c = filterRow.getCell(0);
if (c.isMissing()) {
return null;
}
ByteVectorValue bv = (ByteVectorValue) c;
final long length = bv.length();
if (length != getMetaData().getNrAttributes()) {
throw new IllegalArgumentException("The byte-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(TreeNumericColumnMetaData.getAttributeNameByte(i), Integer.valueOf(bv.get(i)));
}
return new PredictorRecord(valueMap);
}
use of org.knime.core.data.vector.bytevector.ByteVectorValue 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.bytevector.ByteVectorValue in project knime-core by knime.
the class TreeByteNumericColumnDataCreator method add.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked" })
@Override
public void add(final RowKey rowKey, final DataCell cell) {
if (cell.isMissing()) {
throw new IllegalStateException("Missing values not supported");
}
ByteVectorValue v = (ByteVectorValue) cell;
final long lengthLong = v.length();
if (lengthLong > Integer.MAX_VALUE) {
throw new IllegalStateException("Sparse byte vectors not supported");
}
final int length = (int) lengthLong;
if (m_byteTupleLists == null) {
m_byteTupleLists = new ArrayList[length];
for (int i = 0; i < length; i++) {
m_byteTupleLists[i] = new ArrayList<ByteTuple>();
}
} else if (m_byteTupleLists.length != length) {
throw new IllegalArgumentException("Byte vectors in table have different length, expected " + m_byteTupleLists.length + " bytes but got " + length + " bytes in row \"" + rowKey + "\"");
}
for (int attrIndex = 0; attrIndex < length; attrIndex++) {
ByteTuple tuple = new ByteTuple();
int val = v.get(attrIndex);
if (val > MAX_COUNT) {
throw new IllegalArgumentException("The value \"" + val + "\" is larger than the maximum value \"" + MAX_COUNT + "\".");
} else if (val < 0) {
throw new IllegalArgumentException("Negative values are not allowed.");
}
tuple.m_value = (byte) val;
tuple.m_indexInColumn = m_index;
m_byteTupleLists[attrIndex].add(tuple);
}
m_index++;
}
use of org.knime.core.data.vector.bytevector.ByteVectorValue 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.bytevector.ByteVectorValue 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);
}
}
Aggregations