use of org.knime.core.data.vector.bytevector.ByteVectorValue in project knime-core by knime.
the class TreeEnsembleModel 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.getAttributeName(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 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;
}
use of org.knime.core.data.vector.bytevector.ByteVectorValue in project knime-core by knime.
the class RegressionTrainingRow method getValue.
/**
* Gets the value from the {@code cell} with the {@code 0}-based {@code index} in case it was a collection.
*
* @param cell A {@link DataCell}, probably a collection of numbers/bytes/bits.
* @param index The index to select from a collection.
* @param missingHandling How to handle missing values.
* @return The number at the specified position.
* @since 3.1
*/
public static double getValue(final DataCell cell, final int index, final MissingHandling missingHandling) {
if (cell instanceof BitVectorValue) {
final BitVectorValue bvv = (BitVectorValue) cell;
if (bvv.length() > index) {
return bvv.get(index) ? 1d : 0d;
}
// TODO NaN, or 0?
return Double.NaN;
} else if (cell instanceof ByteVectorValue) {
final ByteVectorValue bvv = (ByteVectorValue) cell;
if (bvv.length() > index) {
return bvv.get(index);
}
// Maybe some other value?
return Double.NaN;
} else if (cell instanceof ListDataValue) {
final ListDataValue ldv = (ListDataValue) cell;
if (ldv.size() > index) {
DataCell dataCell = ldv.get(index);
if (dataCell instanceof DoubleValue) {
final DoubleValue dv = (DoubleValue) dataCell;
return dv.getDoubleValue();
}
missingHandling.isMissing(dataCell);
return Double.NaN;
}
}
throw new IllegalStateException("Not a missing, nor a vector value: " + cell);
}
Aggregations