Search in sources :

Example 86 with BufferedDataTable

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]);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable)

Example 87 with BufferedDataTable

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());
}
Also used : CacheNodeFactory(org.knime.base.node.util.cache.CacheNodeFactory) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) CacheNodeFactory(org.knime.base.node.util.cache.CacheNodeFactory) RuntimeNodeFactory(org.knime.testing.node.runtime.RuntimeNodeFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestEvaluationException(org.knime.testing.node.differNode.TestEvaluationException) DataTableDiffer(org.knime.testing.node.differNode.DataTableDiffer) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) ExecutionContext(org.knime.core.node.ExecutionContext) RuntimeNodeModel(org.knime.testing.node.runtime.RuntimeNodeModel) BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeID(org.knime.core.node.workflow.NodeID) RuntimeNodeFactory(org.knime.testing.node.runtime.RuntimeNodeFactory)

Example 88 with BufferedDataTable

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);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) Test(org.junit.Test)

Example 89 with BufferedDataTable

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);
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) Test(org.junit.Test)

Example 90 with BufferedDataTable

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);
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) Test(org.junit.Test)

Aggregations

BufferedDataTable (org.knime.core.node.BufferedDataTable)425 DataTableSpec (org.knime.core.data.DataTableSpec)213 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)148 DataRow (org.knime.core.data.DataRow)118 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)97 PortObject (org.knime.core.node.port.PortObject)96 DataCell (org.knime.core.data.DataCell)85 DataColumnSpec (org.knime.core.data.DataColumnSpec)61 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)60 DefaultRow (org.knime.core.data.def.DefaultRow)56 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)54 RowKey (org.knime.core.data.RowKey)52 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)50 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)47 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)43 IOException (java.io.IOException)41 ExecutionContext (org.knime.core.node.ExecutionContext)40 ArrayList (java.util.ArrayList)33 LinkedHashMap (java.util.LinkedHashMap)31 DoubleValue (org.knime.core.data.DoubleValue)29