Search in sources :

Example 1 with DoubleVectorValue

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);
    }
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue) DoubleCell(org.knime.core.data.def.DoubleCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) IntCell(org.knime.core.data.def.IntCell) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 2 with DoubleVectorValue

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);
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue)

Example 3 with DoubleVectorValue

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++;
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue)

Example 4 with DoubleVectorValue

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);
}
Also used : DoubleVectorValue(org.knime.core.data.vector.doublevector.DoubleVectorValue) PredictorRecord(org.knime.base.node.mine.treeensemble2.data.PredictorRecord) DataCell(org.knime.core.data.DataCell) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DoubleVectorValue (org.knime.core.data.vector.doublevector.DoubleVectorValue)4 DataCell (org.knime.core.data.DataCell)2 LinkedHashMap (java.util.LinkedHashMap)1 PredictorRecord (org.knime.base.node.mine.treeensemble2.data.PredictorRecord)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 IntCell (org.knime.core.data.def.IntCell)1 StringCell (org.knime.core.data.def.StringCell)1 BitVectorValue (org.knime.core.data.vector.bitvector.BitVectorValue)1 ByteVectorValue (org.knime.core.data.vector.bytevector.ByteVectorValue)1