use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class StatisticCalculatorTest method createRandomTableWithMissingValues.
private static BufferedDataTable createRandomTableWithMissingValues(final int cols, final int rows) {
long currentTimeMillis = System.currentTimeMillis();
System.out.println("Using seed: " + currentTimeMillis);
Random random = new Random(currentTimeMillis);
DataTableSpecCreator creator = new DataTableSpecCreator();
for (int i = 0; i < cols; i++) {
creator.addColumns(new DataColumnSpecCreator("" + i, DoubleCell.TYPE).createSpec());
}
final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(creator.createSpec());
for (int i = 0; i < rows; i++) {
DataCell[] rowVals = new DataCell[cols];
for (int j = 0; j < cols; j++) {
rowVals[j] = random.nextDouble() > 0.66 ? new DoubleCell(random.nextDouble()) : DataType.getMissingCell();
}
container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
if (i % 1000 == 0) {
System.out.println("Added row: " + i);
}
}
container.close();
return container.getTable();
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class LogisticRegressionContent method createCoeffStatisticsTablePortObject.
/**
* Creates a BufferedDataTable with the
* @param exec The execution context
* @return a port object
*/
public BufferedDataTable createCoeffStatisticsTablePortObject(final ExecutionContext exec) {
DataTableSpec tableOutSpec = LogRegCoordinator.createCoeffStatisticsTableSpec();
BufferedDataContainer dc = exec.createDataContainer(tableOutSpec);
List<DataCell> logits = this.getLogits();
List<String> parameters = this.getParameters();
int c = 0;
for (DataCell logit : logits) {
Map<String, Double> coefficients = this.getCoefficients(logit);
Map<String, Double> stdErrs;
Map<String, Double> zScores;
Map<String, Double> pValues;
if (m_covMat == null) {
HashMap<String, Double> emptyMap = new HashMap<>();
stdErrs = emptyMap;
zScores = emptyMap;
pValues = emptyMap;
} else {
stdErrs = this.getStandardErrors(logit);
zScores = this.getZScores(logit);
pValues = this.getPValues(logit);
}
for (String parameter : parameters) {
List<DataCell> cells = new ArrayList<>();
cells.add(new StringCell(logit.toString()));
cells.add(new StringCell(parameter));
cells.add(new DoubleCell(coefficients.get(parameter)));
if (m_covMat != null) {
cells.add(new DoubleCell(stdErrs.get(parameter)));
cells.add(new DoubleCell(zScores.get(parameter)));
cells.add(new DoubleCell(pValues.get(parameter)));
} else {
cells.add(NOT_INVERTIBLE_MISSING);
cells.add(NOT_INVERTIBLE_MISSING);
cells.add(NOT_INVERTIBLE_MISSING);
}
c++;
dc.addRowToTable(new DefaultRow("Row" + c, cells));
}
List<DataCell> cells = new ArrayList<>();
cells.add(new StringCell(logit.toString()));
cells.add(new StringCell("Constant"));
cells.add(new DoubleCell(this.getIntercept(logit)));
if (m_covMat != null) {
cells.add(new DoubleCell(this.getInterceptStdErr(logit)));
cells.add(new DoubleCell(this.getInterceptZScore(logit)));
cells.add(new DoubleCell(this.getInterceptPValue(logit)));
} else {
cells.add(NOT_INVERTIBLE_MISSING);
cells.add(NOT_INVERTIBLE_MISSING);
cells.add(NOT_INVERTIBLE_MISSING);
}
c++;
dc.addRowToTable(new DefaultRow("Row" + c, cells));
}
dc.close();
return dc.getTable();
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class AbstractColumnTableSorterTest method setUp.
/**
* @throws java.lang.Exception
*/
@SuppressWarnings("rawtypes")
@Before
public void setUp() throws Exception {
@SuppressWarnings("unchecked") NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator(FEATURE1, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(FEATURE2, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(STRING_FEATURE, StringCell.TYPE).createSpec(), new DataColumnSpecCreator(CLASS, StringCell.TYPE).createSpec() };
DataTableSpec spec = new DataTableSpec(colSpecs);
final BufferedDataContainer container = m_exec.createDataContainer(spec);
int i = 0;
container.addRowToTable(creatRow(i++, 1, 8, "A", "AClass8"));
container.addRowToTable(creatRow(i++, 2, 2, "Z", "ZClass2"));
container.addRowToTable(creatRow(i++, 3, 5, "B", "BClass5"));
container.addRowToTable(creatRow(i++, 4, 0, "E", "EClass0"));
container.addRowToTable(creatRow(i++, 5, 1, "F", "FClass1"));
container.addRowToTable(creatRow(i++, 6, 7, "G", "GClass7"));
container.addRowToTable(creatRow(i++, 7, 9, "H", "HClass9"));
container.addRowToTable(creatRow(i++, 8, 8, null, "Class8"));
container.close();
testTable = container.getTable();
final BufferedDataContainer emptyContainer = m_exec.createDataContainer(spec);
emptyContainer.close();
emptyTestTable = emptyContainer.getTable();
MemoryAlertSystemTest.forceGC();
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class EndifNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] rawInData, final ExecutionContext exec) throws Exception {
if (m_enableHiliting) {
// create empty hilite translation map (so we correctly
// handle the internals even if we return with a IBPO:
Map<RowKey, Set<RowKey>> map = new HashMap<RowKey, Set<RowKey>>();
m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
}
if (rawInData[0] instanceof InactiveBranchPortObject) {
return new PortObject[] { rawInData[1] };
}
if (rawInData[1] instanceof InactiveBranchPortObject) {
return new PortObject[] { rawInData[0] };
}
// no inactive branch - check compatibility of specs - which in
// this case must be BFT Specs!
DataTableSpec spec0 = (DataTableSpec) (rawInData[0].getSpec());
DataTableSpec spec1 = (DataTableSpec) (rawInData[1].getSpec());
if (spec0.equalStructure(spec1)) {
// concatenate tables and return result
BufferedDataTable[] inData = new BufferedDataTable[2];
inData[0] = (BufferedDataTable) rawInData[0];
inData[1] = (BufferedDataTable) rawInData[1];
int totalRowCount = 0;
for (BufferedDataTable t : inData) {
totalRowCount += t.getRowCount();
}
AppendedRowsTable out = new AppendedRowsTable((m_isAppendSuffix ? m_suffix : null), inData);
// note, this iterator throws runtime exceptions when canceled.
AppendedRowsIterator it = out.iterator(exec, totalRowCount);
BufferedDataContainer c = exec.createDataContainer(out.getDataTableSpec());
try {
while (it.hasNext()) {
// may throw exception, also sets progress
c.addRowToTable(it.next());
}
} catch (AppendedRowsIterator.RuntimeCanceledExecutionException rcee) {
throw rcee.getCause();
} finally {
c.close();
}
if (it.getNrRowsSkipped() > 0) {
setWarningMessage("Filtered out " + it.getNrRowsSkipped() + " duplicate row id(s).");
}
if (m_enableHiliting) {
// create hilite translation map
Map<RowKey, Set<RowKey>> map = new HashMap<RowKey, Set<RowKey>>();
// map of all RowKeys and duplicate RowKeys in the resulting table
Map<RowKey, RowKey> dupMap = it.getDuplicateNameMap();
for (Map.Entry<RowKey, RowKey> e : dupMap.entrySet()) {
// if a duplicate key
if (!e.getKey().equals(e.getValue())) {
Set<RowKey> set = Collections.singleton(e.getValue());
// put duplicate key and original key into map
map.put(e.getKey(), set);
} else {
// skip duplicate keys
if (!dupMap.containsKey(new RowKey(e.getKey().getString() + m_suffix))) {
Set<RowKey> set = Collections.singleton(e.getValue());
map.put(e.getKey(), set);
}
}
}
m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
}
return new BufferedDataTable[] { c.getTable() };
}
throw new Exception("Both input ports have data but the tables " + "have incompatible specs");
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class AdapterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
if (getNrInPorts() == 0 && getNrOutPorts() == 1) {
// assume simple source node with one table output
BufferedDataContainer cnt = exec.createDataContainer(createDefaultOutputSpec());
cnt.addRowToTable(new DefaultRow(RowKey.createRowKey(0), new DataCell[] { new StringCell("Cell-1.1"), new IntCell(12), new DoubleCell(1.3) }));
cnt.addRowToTable(new DefaultRow(RowKey.createRowKey(1), new DataCell[] { new StringCell("Cell-2.1"), new IntCell(22), new DoubleCell(2.3) }));
cnt.addRowToTable(new DefaultRow(RowKey.createRowKey(2), new DataCell[] { new StringCell("Cell-3.1"), new IntCell(32), new DoubleCell(3.3) }));
cnt.close();
return new BufferedDataTable[] { cnt.getTable() };
}
return inObjects;
}
Aggregations