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);
}
}
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])));
}
}
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;
}
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;
}
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() };
}
Aggregations