use of org.knime.core.data.vector.doublevector.DoubleVectorValue 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.doublevector.DoubleVectorValue in project knime-core by knime.
the class DoubleVectorValueRenderer method setValue.
/**
* Formats the object using the cell's toString method.
*/
@Override
protected void setValue(final Object value) {
Object newValue;
if (value instanceof DoubleVectorValue) {
DoubleVectorValue cell = (DoubleVectorValue) value;
newValue = cell.toString();
} else {
// missing data cells will also end up here
newValue = value;
}
super.setValue(newValue);
}
use of org.knime.core.data.vector.doublevector.DoubleVectorValue in project knime-core by knime.
the class TreeDoubleVectorNumericColumnDataCreator method add.
/**
* {@inheritDoc}
*/
@Override
public void add(final RowKey rowKey, final DataCell cell) {
if (cell.isMissing()) {
throw new IllegalStateException("Missing values not supported");
}
final DoubleVectorValue v = (DoubleVectorValue) cell;
final long lengthLong = v.getLength();
if (lengthLong > Integer.MAX_VALUE) {
throw new IllegalStateException("Sparse double vectors not supported");
}
final int length = (int) lengthLong;
if (m_doubleTupleLists == null) {
m_doubleTupleLists = new ArrayList[length];
m_missingCounts = new int[length];
for (int i = 0; i < length; i++) {
m_doubleTupleLists[i] = new ArrayList<DoubleTuple>();
}
} else if (m_doubleTupleLists.length != length) {
throw new IllegalArgumentException("Double vectors in table have different length, expected " + m_doubleTupleLists.length + " Doubles but got " + length + " Doubles in row \"" + rowKey + "\"");
}
for (int attrIndex = 0; attrIndex < length; attrIndex++) {
double val = v.getValue(attrIndex);
DoubleTuple tuple = new DoubleTuple(val, m_index);
m_doubleTupleLists[attrIndex].add(tuple);
if (val == Double.NaN) {
m_missingCounts[attrIndex]++;
}
}
m_index++;
}
use of org.knime.core.data.vector.doublevector.DoubleVectorValue in project knime-core by knime.
the class AbstractTreeEnsembleModel method createDoubleVectorPredictorRecord.
private PredictorRecord createDoubleVectorPredictorRecord(final DataRow filterRow) {
assert filterRow.getNumCells() == 1 : "Expected one cell as double vector data";
final DataCell c = filterRow.getCell(0);
if (c.isMissing()) {
return null;
}
final DoubleVectorValue dv = (DoubleVectorValue) c;
final int length = dv.getLength();
if (length != getMetaData().getNrAttributes()) {
throw new IllegalArgumentException("The double-vector in " + filterRow.getKey().getString() + " has the wrong length. (" + length + " instead of " + getMetaData().getNrAttributes() + ")");
}
final Map<String, Object> valueMap = new LinkedHashMap<String, Object>((int) (length / 0.75 + 1.0));
for (int i = 0; i < length; i++) {
double val = dv.getValue(i);
String attributeName = TreeNumericColumnMetaData.getAttributeNameDouble(i);
if (Double.isNaN(val)) {
// treat NaNs as missing values
valueMap.put(attributeName, PredictorRecord.NULL);
} else {
valueMap.put(attributeName, Double.valueOf(val));
}
}
return new PredictorRecord(valueMap);
}
Aggregations