Search in sources :

Example 81 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class BitVectorAttributeModel method createDataRows.

/**
 * {@inheritDoc}
 */
@Override
void createDataRows(final ExecutionMonitor exec, final BufferedDataContainer dc, final boolean ignoreMissing, final AtomicInteger rowId) throws CanceledExecutionException {
    final List<String> sortedClassVal = AttributeModel.sortCollection(m_classValues.keySet());
    if (sortedClassVal == null) {
        return;
    }
    final StringCell attributeCell = new StringCell(getAttributeName());
    final int vectorLength = getVectorLength();
    for (int pos = 0; pos < vectorLength; pos++) {
        createRowsForPosition(dc, ignoreMissing, sortedClassVal, attributeCell, pos, rowId);
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell)

Example 82 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class NumericalAttributeModel method createDataRows.

/**
 * {@inheritDoc}
 */
@Override
void createDataRows(final ExecutionMonitor exec, final BufferedDataContainer dc, final boolean ignoreMissing, final AtomicInteger rowId) throws CanceledExecutionException {
    final List<String> sortedClassVal = AttributeModel.sortCollection(m_classValues.keySet());
    if (sortedClassVal == null) {
        return;
    }
    final StringCell attributeCell = new StringCell(getAttributeName());
    for (final String classVal : sortedClassVal) {
        final List<DataCell> cells = new LinkedList<>();
        cells.add(attributeCell);
        cells.add(DataType.getMissingCell());
        cells.add(new StringCell(classVal));
        final NumericalClassValue classValue = m_classValues.get(classVal);
        cells.add(new IntCell(classValue.getNoOfNotMissingRows()));
        if (!ignoreMissing) {
            cells.add(new IntCell(classValue.getNoOfMissingValueRecs()));
        }
        cells.add(new DoubleCell(classValue.getMean()));
        cells.add(new DoubleCell(classValue.getStdDeviation()));
        dc.addRowToTable(new DefaultRow(RowKey.createRowKey(rowId.getAndIncrement()), cells.toArray(new DataCell[0])));
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) LinkedList(java.util.LinkedList) IntCell(org.knime.core.data.def.IntCell)

Example 83 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class Statistics3Table method createRow.

/**
 * Creates a row for the transposed table.
 *
 * @param name The name of the column.
 * @param colIdx The index of column in the computed values.
 * @return The cells according to {@link #STATISTICS_SPECIFICATION}.
 */
private DataCell[] createRow(final String name, final int colIdx) {
    final DataCell[] ret = new DataCell[getStatisticsSpecification().getNumColumns()];
    int i = 0;
    ret[i++] = new StringCell(name);
    ret[i++] = m_minCells[colIdx];
    ret[i++] = m_maxCells[colIdx];
    ret[i++] = new DoubleCell(m_meanValues[colIdx]);
    ret[i++] = new DoubleCell(Math.sqrt(m_varianceValues[colIdx]));
    ret[i++] = new DoubleCell(m_varianceValues[colIdx]);
    ret[i++] = new DoubleCell(m_skewness[colIdx]);
    ret[i++] = new DoubleCell(m_kurtosis[colIdx]);
    ret[i++] = new DoubleCell(m_sum[colIdx]);
    ret[i++] = new IntCell(m_missingValueCnt[colIdx]);
    ret[i++] = new IntCell(m_nanValueCnt[colIdx]);
    ret[i++] = new IntCell(m_posInfinityValueCnt[colIdx]);
    ret[i++] = new IntCell(m_negInfinityValueCnt[colIdx]);
    ret[i++] = Double.isNaN(m_median[colIdx]) ? DataType.getMissingCell() : new DoubleCell(m_median[colIdx]);
    ret[i++] = new IntCell(m_rowCount);
    return ret;
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) IntCell(org.knime.core.data.def.IntCell)

Example 84 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class MultiLayerPerceptron method loadPredictorParams.

/**
 * @param predParams the ConfigObject containing the model of the mlp
 * @return a new MultiLayerPerceptron based on the config
 * @throws InvalidSettingsException if settings are incorrect
 */
public static MultiLayerPerceptron loadPredictorParams(final ModelContentRO predParams) throws InvalidSettingsException {
    MultiLayerPerceptron mlp;
    Layer predecessorLayer = null;
    Layer actLayer;
    ModelContentRO alllayers = predParams.getModelContent(ALLLAYERS_KEY);
    Layer[] allLayers = new Layer[alllayers.keySet().size()];
    HashMap<DataCell, Integer> myclassmap = new HashMap<DataCell, Integer>();
    HashMap<String, Integer> myinputmap = new HashMap<String, Integer>();
    int l = 0;
    for (String layerKey : alllayers.keySet()) {
        ModelContentRO neuronsconf = alllayers.getModelContent(layerKey);
        if (l == 0) {
            // Input Layer
            InputPerceptron[] inputs = new InputPerceptron[neuronsconf.keySet().size()];
            int n = 0;
            for (String neuron : neuronsconf.keySet()) {
                ModelContentRO inpneurconf = neuronsconf.getModelContent(neuron);
                inputs[n] = new InputPerceptron(inpneurconf.getDouble(INPUT_KEY));
                if (inpneurconf.containsKey(CLASSVALUE_KEY)) {
                    inputs[n].setClassValue(inpneurconf.getString(CLASSVALUE_KEY));
                    myinputmap.put(inpneurconf.getString(CLASSVALUE_KEY), n);
                }
                n++;
            }
            actLayer = new InputLayer(inputs);
            allLayers[l] = actLayer;
            predecessorLayer = actLayer;
        } else {
            Perceptron[] neuronodes = new Perceptron[neuronsconf.keySet().size()];
            int n = 0;
            for (String neuron : neuronsconf.keySet()) {
                ModelContentRO neurconf = neuronsconf.getModelContent(neuron);
                // TODO: save neuron type in config, create new neuron
                // accordingly?
                neuronodes[n] = new SigmoidPerceptron(neurconf.getDoubleArray(WEIGHT_KEY), predecessorLayer.getPerceptrons());
                neuronodes[n].setThreshold(neurconf.getDouble(THRESHOLD_KEY));
                if (neurconf.containsKey(CLASSVALUE_KEY)) {
                    neuronodes[n].setClassValue(neurconf.getString(CLASSVALUE_KEY));
                    myclassmap.put(new StringCell(neurconf.getString(CLASSVALUE_KEY)), n);
                }
                n++;
            }
            actLayer = new HiddenLayer(predecessorLayer, neuronodes);
            allLayers[l] = actLayer;
            predecessorLayer = actLayer;
        }
        l++;
    }
    int mode = predParams.getInt(MODE_KEY);
    mlp = new MultiLayerPerceptron(allLayers);
    Architecture myarch = new Architecture(allLayers[0].getPerceptrons().length, allLayers.length - 1, allLayers[allLayers.length - 2].getPerceptrons().length, allLayers[allLayers.length - 1].getPerceptrons().length);
    mlp.setArchitecture(myarch);
    mlp.setClassMapping(myclassmap);
    mlp.setInputMapping(myinputmap);
    mlp.setMode(mode);
    return mlp;
}
Also used : ModelContentRO(org.knime.core.node.ModelContentRO) HashMap(java.util.HashMap) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 85 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class VariableToTable2NodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec spec = createOutSpec();
    BufferedDataContainer cont = exec.createDataContainer(spec);
    List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
    DataCell[] specs = new DataCell[vars.size()];
    List<String> lostVariables = new ArrayList<String>();
    for (int i = 0; i < vars.size(); i++) {
        Pair<String, FlowVariable.Type> c = vars.get(i);
        String name = c.getFirst();
        // fallback
        DataCell cell = DataType.getMissingCell();
        switch(c.getSecond()) {
            case DOUBLE:
                try {
                    double dValue = peekFlowVariableDouble(c.getFirst());
                    cell = new DoubleCell(dValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (Double)");
                }
                break;
            case INTEGER:
                try {
                    int iValue = peekFlowVariableInt(c.getFirst());
                    cell = new IntCell(iValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (Integer)");
                }
                break;
            case STRING:
                try {
                    String sValue = peekFlowVariableString(c.getFirst());
                    sValue = sValue == null ? "" : sValue;
                    cell = new StringCell(sValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (String)");
                }
                break;
        }
        specs[i] = cell;
    }
    cont.addRowToTable(new DefaultRow(m_rowID.getStringValue(), specs));
    cont.close();
    return new BufferedDataTable[] { cont.getTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) IntCell(org.knime.core.data.def.IntCell) PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) NoSuchElementException(java.util.NoSuchElementException) Pair(org.knime.core.util.Pair) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

StringCell (org.knime.core.data.def.StringCell)176 DataCell (org.knime.core.data.DataCell)130 DoubleCell (org.knime.core.data.def.DoubleCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)65 IntCell (org.knime.core.data.def.IntCell)55 DataRow (org.knime.core.data.DataRow)52 DataTableSpec (org.knime.core.data.DataTableSpec)49 ArrayList (java.util.ArrayList)41 DataColumnSpec (org.knime.core.data.DataColumnSpec)37 RowKey (org.knime.core.data.RowKey)36 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)26 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)26 DataType (org.knime.core.data.DataType)22 LinkedHashSet (java.util.LinkedHashSet)21 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)19 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)16 LinkedHashMap (java.util.LinkedHashMap)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)11