use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class JoinerJoinAnyTest method testRunner.
private final void testRunner(final Joiner2Settings settings, final Integer[][] reference, final int numBitsInitial, final int numBitsMaximal) throws CanceledExecutionException, InvalidSettingsException {
// Create data with fields that consume a lot memory
DataTable leftInput = new IntegerTable(new String[] { "L1", "L2" }, new Integer[][] { new Integer[] { 0, 0 }, new Integer[] { 0, 1 }, new Integer[] { 1, 0 }, new Integer[] { 1, 1 }, new Integer[] { 2, 2 }, new Integer[] { 3, 3 }, new Integer[] { 4, 4 }, new Integer[] { 5, 5 }, new Integer[] { 6, 6 } });
DataTable rightInput = new IntegerTable(new String[] { "R1", "R2" }, new Integer[][] { new Integer[] { 0, 1 }, new Integer[] { 1, 0 }, new Integer[] { 1, 1 }, new Integer[] { 1, 2 }, new Integer[] { 2, 2 }, new Integer[] { 3, 3 }, new Integer[] { 10, 10 } });
BufferedDataTable bdtLeft = m_exec.createBufferedDataTable(leftInput, m_exec);
BufferedDataTable bdtRight = m_exec.createBufferedDataTable(rightInput, m_exec);
// run joiner
Joiner joiner = new Joiner(leftInput.getDataTableSpec(), rightInput.getDataTableSpec(), settings);
// force one bin only
joiner.setNumBitsInitial(numBitsInitial);
joiner.setNumBitsMaximal(numBitsMaximal);
BufferedDataTable output = joiner.computeJoinTable(bdtLeft, bdtRight, m_exec);
Integer[][] outputArray = toIntegerArray(output);
// Test for equality of the arrays
Assert.assertEquals(reference.length, outputArray.length);
for (int i = 0; i < reference.length; i++) {
Assert.assertArrayEquals(reference[i], outputArray[i]);
}
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class AbstractBlobsInWorkflowTest method setUp.
/**
* {@inheritDoc}
*/
@Override
protected void setUp() throws Exception {
m_wfmDir = FileUtil.createTempDir(getClass().getSimpleName());
WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
creationHelper.setWorkflowContext(new WorkflowContext.Factory(m_wfmDir).createContext());
WorkflowManager m = WorkflowManager.ROOT.createAndAddProject("Blob test", creationHelper);
RuntimeNodeModel createModel = new RuntimeNodeModel(0, 1) {
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
return new BufferedDataTable[] { createBDT(exec) };
}
};
NodeID createID = m.createAndAddNode(new RuntimeNodeFactory(createModel));
// add a sequence of cache nodes
NodeID[] cacheIDs = new NodeID[10];
CacheNodeFactory cacheNodeFactory = new CacheNodeFactory();
for (int i = 0; i < cacheIDs.length; i++) {
cacheIDs[i] = m.createAndAddNode(cacheNodeFactory);
if (i == 0) {
m.addConnection(createID, 1, cacheIDs[i], 1);
} else {
m.addConnection(cacheIDs[i - 1], 1, cacheIDs[i], 1);
}
}
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
RuntimeNodeModel checkModel = new RuntimeNodeModel(1, 0) {
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
try {
new DataTableDiffer().compare(inData[0], createBDT(exec));
} catch (TestEvaluationException tee) {
failure.set(tee);
throw tee;
}
return new BufferedDataTable[] {};
}
};
NodeID checkID = m.createAndAddNode(new RuntimeNodeFactory(checkModel));
m.addConnection(cacheIDs[cacheIDs.length - 1], 1, checkID, 1);
m_flow = m;
m.executeAllAndWaitUntilDone();
assertNull(failure.get());
assertTrue(m.getNodeContainerState().isExecuted());
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class LearnerTest method testPerformLowBirthWeightData.
/**
* Test method for {@link org.knime.base.node.mine.regression.logistic.learner.Learner#perform(BufferedDataTable, org.knime.core.node.ExecutionContext)}.
* @throws CanceledExecutionException
*/
@Test
public final void testPerformLowBirthWeightData() throws Exception {
final BufferedDataTable data = m_exec.createBufferedDataTable(new LowBirthWeightData(), m_exec);
PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(data.getDataTableSpec());
specCreator.setLearningColsNames(Arrays.asList(new String[] { "AGE", "LWT", "RACE", "FTV" }));
specCreator.setTargetColName("LOW");
final PMMLPortObjectSpec spec = specCreator.createSpec();
// done in KNIME thread pool, expected by code
Future<LogisticRegressionContent> callable = KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Callable<LogisticRegressionContent>() {
@Override
public LogisticRegressionContent call() throws Exception {
final Learner learner = new Learner(spec, null, true, true);
return learner.perform(data, m_exec);
}
});
LogisticRegressionContent content = callable.get();
// Reference results are published in the book:
// Applied Logistic Regression,
// David W. Hosmer and Stanley Lemeshow
// Wiley, 2000 (2nd. ed)
// The table of results are found on page 36
Assert.assertEquals(-111.286, content.getEstimatedLikelihood(), 0.001);
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class LearnerTest method testPerformChdAgeData.
/**
* Test method for {@link org.knime.base.node.mine.regression.logistic.learner.Learner#perform(BufferedDataTable, org.knime.core.node.ExecutionContext)}.
* @throws CanceledExecutionException
*/
@Test
public final void testPerformChdAgeData() throws Exception {
final BufferedDataTable data = m_exec.createBufferedDataTable(new ChdAgeData(), m_exec);
PMMLPortObjectSpecCreator specCreator = new PMMLPortObjectSpecCreator(data.getDataTableSpec());
specCreator.setLearningColsNames(Arrays.asList(new String[] { "Age" }));
specCreator.setTargetColName("Evidence of Coronary Heart Disease");
final PMMLPortObjectSpec spec = specCreator.createSpec();
// done in KNIME thread pool, expected by code
Future<LogisticRegressionContent> callable = KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Callable<LogisticRegressionContent>() {
@Override
public LogisticRegressionContent call() throws Exception {
final Learner learner = new Learner(spec, null, true, true);
return learner.perform(data, m_exec);
}
});
LogisticRegressionContent content = callable.get();
// Reference results are published in the book:
// Applied Logistic Regression,
// David W. Hosmer and Stanley Lemeshow
// Wiley, 2000 (2nd. ed)
// The table of results are found on page 10
Assert.assertEquals(-53.67656, content.getEstimatedLikelihood(), 0.001);
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class JoinerTest method testSkipPartitionsInnerJoin.
@Test
public final void testSkipPartitionsInnerJoin() throws Exception {
Joiner2Settings settingsRef = createReferenceSettings("Data");
Joiner2Settings settingsTest = createReferenceSettings("Data");
BufferedDataTable leftTable = m_exec.createBufferedDataTable(new TestData(100, 1), m_exec);
BufferedDataTable rightTable = m_exec.createBufferedDataTable(new TestData(200, 1), m_exec);
// run joiner with reference settings
Joiner joinerRef = new Joiner(leftTable.getDataTableSpec(), rightTable.getDataTableSpec(), settingsRef);
BufferedDataTable reference = joinerRef.computeJoinTable(leftTable, rightTable, m_exec);
// run joiner with test settings
Joiner joinerTest = new Joiner(leftTable.getDataTableSpec(), rightTable.getDataTableSpec(), settingsTest);
joinerTest.setRowsAddedBeforeOOM(10);
joinerTest.setNumBitsInitial(8);
BufferedDataTable test = joinerTest.computeJoinTable(leftTable, rightTable, m_exec);
compareTables(reference, test);
}
Aggregations