Search in sources :

Example 76 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class AffineTransRowIterator method next.

/**
 * {@inheritDoc}
 */
@Override
public DataRow next() {
    AffineTransConfiguration config = m_transtable.getConfiguration();
    int[] indices = m_transtable.getIndicesInConfiguration();
    double[] scales = config.getScales();
    double[] translations = config.getTranslations();
    double[] min = config.getMin();
    double[] max = config.getMax();
    final DataRow in = m_it.next();
    final DataCell[] cells = new DataCell[in.getNumCells()];
    for (int i = 0; i < cells.length; i++) {
        final DataCell oldCell = in.getCell(i);
        if (oldCell.isMissing() || indices[i] == -1) {
            cells[i] = oldCell;
        } else {
            int index = indices[i];
            double interval = max[index] - min[index];
            double oldDouble = ((DoubleValue) oldCell).getDoubleValue();
            double newDouble = scales[index] * oldDouble + translations[index];
            if (!Double.isNaN(min[index])) {
                if (newDouble < min[index]) {
                    if ((min[index] - newDouble) / interval < AffineTransTable.VERY_SMALL) {
                        newDouble = min[index];
                    } else {
                        m_transtable.setErrorMessage("Normalized value is out of bounds." + " Original value: " + oldDouble + " Transformed value: " + newDouble + " Lower Bound: " + min[index]);
                    }
                }
            }
            if (!Double.isNaN(max[index])) {
                if (newDouble > max[index]) {
                    if ((newDouble - max[index]) / interval < AffineTransTable.VERY_SMALL) {
                        newDouble = max[index];
                    } else {
                        m_transtable.setErrorMessage("Normalized value is out of bounds." + " Original value: " + oldDouble + " Transformed value: " + newDouble + " Upper Bound: " + max[index]);
                    }
                }
            }
            cells[i] = new DoubleCell(newDouble);
        }
    }
    return new DefaultRow(in.getKey(), cells);
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Example 77 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class TableToVariableNodeModel method pushVariables.

/**
 * Pushes the variable as given by the row argument onto the stack.
 * @param variablesSpec The spec (for names and types)
 * @param currentVariables The values of the variables.
 * @throws Exception if the node is supposed to fail on missing values or empty table
 */
protected void pushVariables(final DataTableSpec variablesSpec, final DataRow currentVariables) throws Exception {
    // push also the rowID onto the stack
    final String rowIDVarName = "RowID";
    final boolean fail = m_onMV.getStringValue().equals(MissingValuePolicy.FAIL.getName());
    final boolean defaults = m_onMV.getStringValue().equals(MissingValuePolicy.DEFAULT.getName());
    pushFlowVariableString(rowIDVarName, currentVariables == null ? "" : currentVariables.getKey().getString());
    final DataCell[] defaultCells = createDefaultCells(variablesSpec);
    // column names starting with "knime." are uniquified as they represent global constants
    final HashSet<String> variableNames = new HashSet<String>();
    variableNames.add(rowIDVarName);
    final int colCount = variablesSpec.getNumColumns();
    for (int i = colCount; --i >= 0; ) {
        DataColumnSpec spec = variablesSpec.getColumnSpec(i);
        DataType type = spec.getType();
        String name = spec.getName();
        if (name.equals("knime.")) {
            name = "column_" + i;
        } else if (name.startsWith("knime.")) {
            name = name.substring("knime.".length());
        }
        int uniquifier = 1;
        String basename = name;
        while (!variableNames.add(name)) {
            name = basename + "(#" + (uniquifier++) + ")";
        }
        final DataCell cell;
        if (currentVariables == null) {
            if (fail) {
                throw new Exception("No rows in input table");
            } else if (defaults) {
                cell = defaultCells[i];
            } else {
                // omit
                cell = null;
            }
        } else if (currentVariables.getCell(i).isMissing()) {
            if (fail) {
                throw new Exception(String.format("Missing Values not allowed as variable values -- " + "in row with ID \"%s\", column \"%s\" (index %d)", currentVariables.getKey(), variablesSpec.getColumnSpec(i).getName(), i));
            } else if (defaults) {
                cell = defaultCells[i];
            } else {
                // omit
                cell = null;
            }
        } else {
            // take the value from the input table row
            cell = currentVariables.getCell(i);
        }
        if (cell != null) {
            if (type.isCompatible(IntValue.class)) {
                pushFlowVariableInt(name, ((IntValue) cell).getIntValue());
            } else if (type.isCompatible(DoubleValue.class)) {
                pushFlowVariableDouble(name, ((DoubleValue) cell).getDoubleValue());
            } else if (type.isCompatible(StringValue.class)) {
                pushFlowVariableString(name, ((StringValue) cell).getStringValue());
            }
        }
    }
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 78 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class Numeric2BitVectorThresholdCellFactory method getCell.

/**
 * {@inheritDoc}
 */
@Override
public DataCell getCell(final DataRow row) {
    incrementNrOfRows();
    org.knime.core.data.vector.bitvector.BitVectorCellFactory<? extends DataCell> factory = m_vectorType.getCellFactory(m_colIdxs.length);
    for (int i = 0; i < m_colIdxs.length; i++) {
        final DataCell cell = row.getCell(m_colIdxs[i]);
        if (cell.isMissing()) {
            m_totalNrOf0s++;
            continue;
        }
        if (cell instanceof DoubleValue) {
            double currValue = ((DoubleValue) cell).getDoubleValue();
            if (currValue >= m_threshold) {
                factory.set(i);
                m_totalNrOf1s++;
            } else {
                m_totalNrOf0s++;
            }
        } else {
            printError(LOGGER, row, "Incompatible type found.");
            return DataType.getMissingCell();
        }
    }
    return factory.createDataCell();
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell)

Example 79 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class DoubleCellFilterRowGenerator method isIn.

/**
 * Checks if the given row lies within the define interval borders.
 *
 * @param row the row which should be checked for being inside the interval
 * @return <code>true</code> if inside the define interval
 * @throws NullPointerException if the given row is <code>null</code>
 * @throws ClassCastException if the row's cell is not of type
 *             {@link org.knime.core.data.def.DoubleCell}
 */
@Override
public boolean isIn(final DataRow row) {
    DataCell cell = row.getCell(m_columnIndex);
    if (cell.isMissing()) {
        return false;
    }
    // retrieve double value at column index
    double dbl = ((DoubleValue) cell).getDoubleValue();
    // if single border
    if (m_mask[1] == EMPTY_MASK) {
        return check(dbl, 0);
    } else {
        // if closed intervall
        if ((m_mask[0] & RIGHT) == RIGHT && (m_mask[1] & LEFT) == LEFT) {
            // has to be betweem both borders
            return check(dbl, 0) && check(dbl, 1);
        } else {
            // has to be at exactly one
            return check(dbl, 0) ^ check(dbl, 1);
        }
    }
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell)

Example 80 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class MissingValuePanel method getFixTextField.

/*
     * Helper in constructor, generates the text field to enter the replacement
     * value.
     */
private static JComponent getFixTextField(final ColSetting setting, final DataColumnSpec spec) {
    JComponent fixText;
    // FIX text field
    DataCell fixCell = setting.getFixCell();
    switch(setting.getType()) {
        case ColSetting.TYPE_DOUBLE:
            fixText = new JFormattedTextField();
            ((JFormattedTextField) fixText).setColumns(8);
            Double doubel;
            if (fixCell == null) {
                doubel = new Double(0.0);
            } else {
                double d = ((DoubleValue) fixCell).getDoubleValue();
                doubel = new Double(d);
            }
            ((JFormattedTextField) fixText).setValue(doubel);
            break;
        case ColSetting.TYPE_INT:
            fixText = new JFormattedTextField();
            ((JFormattedTextField) fixText).setColumns(8);
            Integer integer;
            if (fixCell == null) {
                integer = new Integer(0);
            } else {
                int i = ((IntValue) fixCell).getIntValue();
                integer = new Integer(i);
            }
            ((JFormattedTextField) fixText).setValue(integer);
            break;
        case ColSetting.TYPE_STRING:
            DataCell[] vals;
            if (spec != null && spec.getDomain().hasValues()) {
                vals = spec.getDomain().getValues().toArray(new DataCell[0]);
            } else {
                vals = new DataCell[0];
            }
            DefaultComboBoxModel model = new DefaultComboBoxModel(vals);
            fixText = new JComboBox(model);
            ((JComboBox) fixText).setPrototypeDisplayValue("#########");
            ((JComboBox) fixText).setEditable(true);
            ((JComboBox) fixText).setRenderer(new DefaultListCellRenderer() {

                /**
                 * Overridden to set tooltip text properly.
                 * @see DefaultListCellRenderer#getListCellRendererComponent(
                 * JList, Object, int, boolean, boolean)
                 */
                @Override
                public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
                    Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if (c instanceof JComponent) {
                        ((JComponent) c).setToolTipText(value.toString());
                    }
                    return c;
                }
            });
            String string;
            if (fixCell == null) {
                string = "";
            } else {
                string = ((StringValue) fixCell).getStringValue();
            }
            model.setSelectedItem(string);
            break;
        default:
            throw new InternalError("No such type");
    }
    return fixText;
}
Also used : JComboBox(javax.swing.JComboBox) JComponent(javax.swing.JComponent) JFormattedTextField(javax.swing.JFormattedTextField) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DoubleValue(org.knime.core.data.DoubleValue) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) DataCell(org.knime.core.data.DataCell) JComponent(javax.swing.JComponent) Component(java.awt.Component) IntValue(org.knime.core.data.IntValue) JList(javax.swing.JList)

Aggregations

DoubleValue (org.knime.core.data.DoubleValue)154 DataCell (org.knime.core.data.DataCell)103 DataRow (org.knime.core.data.DataRow)71 DataColumnSpec (org.knime.core.data.DataColumnSpec)38 DataTableSpec (org.knime.core.data.DataTableSpec)38 DoubleCell (org.knime.core.data.def.DoubleCell)32 ArrayList (java.util.ArrayList)26 BufferedDataTable (org.knime.core.node.BufferedDataTable)26 DataType (org.knime.core.data.DataType)23 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)21 LinkedHashMap (java.util.LinkedHashMap)18 IntValue (org.knime.core.data.IntValue)15 HashMap (java.util.HashMap)14 RowIterator (org.knime.core.data.RowIterator)14 RowKey (org.knime.core.data.RowKey)13 DefaultRow (org.knime.core.data.def.DefaultRow)13 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 LongValue (org.knime.core.data.LongValue)10 StringValue (org.knime.core.data.StringValue)10 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)10