use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class Statistics3Table method createNominalValueTable.
/**
* Create nominal value table containing all possible values together with their occurrences.
*
* @param nominal value output table
* @return data table with nominal values for each column
*/
public DataTable createNominalValueTable(final List<String> nominal) {
DataTableSpec outSpec = createOutSpecNominal(m_spec, nominal);
@SuppressWarnings("unchecked") Iterator<Entry<DataCell, Integer>>[] it = new Iterator[(outSpec.getNumColumns() / 3)];
long[] totals = new long[it.length];
for (int i = 0, index = 0; i < m_nominalValues.size(); i++) {
Map<DataCell, Integer> currentMap = m_nominalValues.get(i);
if (currentMap != null) {
it[index] = currentMap.entrySet().iterator();
totals[index] = currentMap.values().stream().collect(Collectors.summingLong(Integer::valueOf));
index += 1;
}
}
DataContainer cont = new DataContainer(outSpec, true);
int rowIndex = 0;
do {
boolean addEnd = true;
DataCell[] cells = new DataCell[3 * it.length];
for (int i = 0; i < it.length; i++) {
if (it[i].hasNext()) {
Map.Entry<DataCell, Integer> e = it[i].next();
cells[3 * i] = e.getKey();
int count = e.getValue().intValue();
cells[3 * i + 1] = new IntCell(count);
cells[3 * i + 2] = new DoubleCell((double) count / totals[i]);
addEnd = false;
} else {
cells[3 * i] = DataType.getMissingCell();
cells[3 * i + 1] = DataType.getMissingCell();
cells[3 * i + 2] = DataType.getMissingCell();
}
}
if (addEnd) {
break;
}
cont.addRowToTable(new DefaultRow(RowKey.createRowKey(rowIndex++), cells));
} while (true);
cont.close();
return cont.getTable();
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class AppendVariableToTable2NodeModel method createColumnRearranger.
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
ColumnRearranger arranger = new ColumnRearranger(spec);
Set<String> nameHash = new HashSet<String>();
for (DataColumnSpec c : spec) {
nameHash.add(c.getName());
}
List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
if (vars.isEmpty()) {
throw new InvalidSettingsException("No variables selected");
}
DataColumnSpec[] specs = new DataColumnSpec[vars.size()];
final DataCell[] values = new DataCell[vars.size()];
for (int i = 0; i < vars.size(); i++) {
Pair<String, FlowVariable.Type> c = vars.get(i);
String name = c.getFirst();
final DataType type;
switch(c.getSecond()) {
case DOUBLE:
type = DoubleCell.TYPE;
try {
double dValue = peekFlowVariableDouble(name);
values[i] = new DoubleCell(dValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type double): " + name);
}
break;
case INTEGER:
type = IntCell.TYPE;
try {
int iValue = peekFlowVariableInt(name);
values[i] = new IntCell(iValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type int): " + name);
}
break;
case STRING:
type = StringCell.TYPE;
try {
String sValue = peekFlowVariableString(name);
sValue = sValue == null ? "" : sValue;
values[i] = new StringCell(sValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type String): " + name);
}
break;
default:
throw new InvalidSettingsException("Unsupported variable type: " + c.getSecond());
}
if (nameHash.contains(name) && !name.toLowerCase().endsWith("(variable)")) {
name = name.concat(" (variable)");
}
String newName = name;
int uniquifier = 1;
while (!nameHash.add(newName)) {
newName = name + " (#" + (uniquifier++) + ")";
}
specs[i] = new DataColumnSpecCreator(newName, type).createSpec();
}
arranger.append(new AbstractCellFactory(specs) {
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
return values;
}
});
return arranger;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class PercentOperator method getResultInternal.
/**
* {@inheritDoc}
*/
@Override
protected DataCell getResultInternal() {
final long itemCount = getGlobalSettings().getNoOfItems();
if (itemCount == 0) {
return ZERO_PERCENTAGE;
}
final IntCell resultInternal = (IntCell) super.getResultInternal();
final double percentage = resultInternal.getDoubleValue() / itemCount * 100;
return new DoubleCell(percentage);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class SumOperator method getResultInternal.
/**
* {@inheritDoc}
*/
@Override
protected DataCell getResultInternal() {
if (!m_valid) {
return DataType.getMissingCell();
}
if (IntCell.TYPE.equals(m_type)) {
// check if the double value is to big for an integer
if (m_sum > Integer.MAX_VALUE) {
setSkipped(true);
setSkipMessage("Sum > maximum int value. " + "Convert column to long.");
return DataType.getMissingCell();
}
return new IntCell((int) m_sum);
} else if (LongCell.TYPE.equals(m_type)) {
// check if the double value is to big for a long
if (m_sum > Long.MAX_VALUE) {
setSkipped(true);
setSkipMessage("Sum > maximum long value. " + "Convert column to double.");
return DataType.getMissingCell();
}
return new LongCell((long) m_sum);
}
return new DoubleCell(m_sum);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class LogisticRegressionContent method createModelStatisticsTable.
BufferedDataTable createModelStatisticsTable(final ExecutionContext exec) {
BufferedDataContainer container = exec.createDataContainer(createModelStatisticsTableSpec());
DataCell[] cells = new DataCell[] { new IntCell(getIterationCount()), new DoubleCell(getEstimatedLikelihood()) };
DataRow row = new DefaultRow(RowKey.createRowKey(0L), cells);
container.addRowToTable(row);
container.close();
return container.getTable();
}
Aggregations