Search in sources :

Example 41 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class EntropyNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    DataTable reference = inData[INPORT_REFERENCE];
    DataTable clustering = inData[INPORT_CLUSTERING];
    int referenceColIndex = reference.getDataTableSpec().findColumnIndex(m_referenceCol);
    int clusteringColIndex = clustering.getDataTableSpec().findColumnIndex(m_clusteringCol);
    m_calculator = new EntropyCalculator(reference, clustering, referenceColIndex, clusteringColIndex, exec);
    Map<RowKey, Set<RowKey>> map = m_calculator.getClusteringMap();
    m_translator.setMapper(new DefaultHiLiteMapper(map));
    if (getNrOutPorts() > 0) {
        BufferedDataTable out = exec.createBufferedDataTable(m_calculator.getScoreTable(), exec);
        return new BufferedDataTable[] { out };
    }
    return new BufferedDataTable[0];
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Example 42 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class MDSNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    int rowsToUse = m_rowsModel.getIntValue();
    if (m_useRowsModel.getBooleanValue()) {
        rowsToUse = inData[0].getRowCount();
    }
    // Warn if number of rows is greater than chosen number of rows
    if (inData[0].getRowCount() > rowsToUse) {
        setWarningMessage("Maximal number of rows to report is less than number of rows in input data table !");
    }
    final DataTableSpec inSpec = inData[0].getSpec();
    final ColumnRearranger colFilter = new ColumnRearranger(inSpec);
    if (m_includeList != null) {
        colFilter.keepOnly(m_includeList.toArray(new String[m_includeList.size()]));
    }
    BufferedDataTable rowCutDataTable = exec.createColumnRearrangeTable(inData[0], colFilter, exec.createSilentSubProgress(0.0));
    // use only specified rows
    DataTable dataContainer = new DefaultDataArray(rowCutDataTable, 1, rowsToUse);
    // save BufferedDataTable with rows to use and ALL columns to generate
    // the output data table out of it.
    rowCutDataTable = exec.createBufferedDataTable(dataContainer, exec);
    // create MDS manager, init and train stuff
    m_manager = new MDSManager(m_outputDimModel.getIntValue(), m_distModel.getStringValue(), m_fuzzy, rowCutDataTable, exec);
    m_manager.init(m_seedModel.getIntValue());
    m_manager.train(m_epochsModel.getIntValue(), m_learnrateModel.getDoubleValue());
    // create BufferedDataTable out of mapped data.
    ColumnRearranger rearranger = createColumnRearranger(inSpec, new MDSCellFactory(m_manager.getDataPoints(), m_manager.getDimension()));
    return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[0], rearranger, exec.createSubProgress(0.1)) };
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 43 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class MDSProjectionNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final DataTableSpec inSpecData = inData[IN_DATA_INDEX].getSpec();
    final ColumnRearranger colFilter = new ColumnRearranger(inSpecData);
    if (m_includeList != null) {
        colFilter.keepOnly(m_includeList.toArray(new String[m_includeList.size()]));
    }
    BufferedDataTable rowCutDataTable = exec.createColumnRearrangeTable(inData[IN_DATA_INDEX], colFilter, exec.createSilentSubProgress(0.0));
    int rowsToUse = m_rowsModel.getIntValue();
    if (m_useRowsModel.getBooleanValue()) {
        rowsToUse = inData[IN_DATA_INDEX].getRowCount();
    }
    // Warn if number of rows is greater than chosen number of rows
    if (inData[IN_DATA_INDEX].getRowCount() > rowsToUse) {
        setWarningMessage("Maximal number of rows to report is less than number of rows in input data table !");
    }
    // use only specified rows
    DataTable dataContainer = new DefaultDataArray(rowCutDataTable, 1, rowsToUse);
    // create BufferedDataTable
    rowCutDataTable = exec.createBufferedDataTable(dataContainer, exec);
    // get the indices of the fixed mds columns
    List<String> fixedCols = m_fixedMdsColModel.getIncludeList();
    int[] fixedMdsColsIndicies = new int[fixedCols.size()];
    DataTableSpec spec = inData[FIXED_DATA_INDEX].getSpec();
    for (int i = 0; i < fixedCols.size(); i++) {
        fixedMdsColsIndicies[i] = spec.findColumnIndex(fixedCols.get(i));
    }
    // create MDS manager, init and train stuff
    m_manager = new MDSProjectionManager(m_outputDimModel.getIntValue(), m_distModel.getStringValue(), m_fuzzy, rowCutDataTable, inData[FIXED_DATA_INDEX], fixedMdsColsIndicies, exec);
    m_manager.setProjectOnly(m_projectOnly.getBooleanValue());
    m_manager.init(m_seedModel.getIntValue());
    m_manager.train(m_epochsModel.getIntValue(), m_learnrateModel.getDoubleValue());
    // create BufferedDataTable out of mapped data.
    ColumnRearranger rearranger = createColumnRearranger(inSpecData, new MDSCellFactory(m_manager.getDataPoints(), m_manager.getDimension()));
    return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[IN_DATA_INDEX], rearranger, exec.createSubProgress(0.1)) };
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) MDSCellFactory(org.knime.base.node.mine.mds.MDSCellFactory)

Example 44 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class SotaNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    if (!(inData[SotaNodeModel.INPORT] instanceof BufferedDataTable)) {
        throw new IllegalArgumentException("Given indata port object is " + " no BufferedDataTable!");
    }
    BufferedDataTable bdt = (BufferedDataTable) inData[SotaNodeModel.INPORT];
    final DataArray origRowContainer = new DefaultDataArray(bdt, 1, Integer.MAX_VALUE);
    DataTable dataTableToUse = bdt;
    int indexOfClassCol = -1;
    // get index of column containing class information
    indexOfClassCol = dataTableToUse.getDataTableSpec().findColumnIndex(m_classCol.getStringValue());
    m_sota.initializeTree(dataTableToUse, origRowContainer, exec, indexOfClassCol);
    m_sota.doTraining();
    if (m_withOutPort) {
        return new PortObject[] { new SotaPortObject(m_sota, dataTableToUse.getDataTableSpec(), indexOfClassCol) };
    }
    return new PortObject[] {};
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) BufferedDataTable(org.knime.core.node.BufferedDataTable) PortObject(org.knime.core.node.port.PortObject) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) DataArray(org.knime.base.node.util.DataArray)

Example 45 with DataTable

use of org.knime.core.data.DataTable in project knime-core by knime.

the class DatabasePortObject method loadTablePreview.

private void loadTablePreview(final JComponent[] panels, final JPanel p, final JTextField cacheRows) {
    final AtomicInteger value = new AtomicInteger(100);
    try {
        int v = Integer.parseInt(cacheRows.getText().trim());
        value.set(v);
    } catch (NumberFormatException nfe) {
        cacheRows.setText(Integer.toString(value.get()));
    }
    panels[0].removeAll();
    panels[0].add(new JLabel("Fetching " + value.get() + " rows from database..."), BorderLayout.NORTH);
    panels[0].repaint();
    panels[0].revalidate();
    new SwingWorkerWithContext<DataTable, Void>() {

        /**
         * {@inheritDoc}
         */
        @Override
        protected DataTable doInBackgroundWithContext() throws Exception {
            return getDataTable(value.get());
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected void doneWithContext() {
            DataTable dt = null;
            try {
                dt = super.get();
            } catch (ExecutionException ee) {
                LOGGER.warn("Error during fetching data from " + "database, reason: " + ee.getMessage(), ee);
            } catch (InterruptedException ie) {
                LOGGER.warn("Error during fetching data from " + "database, reason: " + ie.getMessage(), ie);
            }
            @SuppressWarnings("serial") final BufferedDataTableView dataView2 = new BufferedDataTableView(dt) {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public String getName() {
                    return "Table Preview";
                }
            };
            dataView2.setName("Table Preview");
            panels[0].removeAll();
            panels[0].add(p, BorderLayout.NORTH);
            panels[0].add(dataView2, BorderLayout.CENTER);
            panels[0].setName(dataView2.getName());
            panels[0].repaint();
            panels[0].revalidate();
        }
    }.execute();
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) JLabel(javax.swing.JLabel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ExecutionException(java.util.concurrent.ExecutionException) BufferedDataTableView(org.knime.core.node.workflow.BufferedDataTableView)

Aggregations

DataTable (org.knime.core.data.DataTable)64 BufferedDataTable (org.knime.core.node.BufferedDataTable)33 DataRow (org.knime.core.data.DataRow)20 DataTableSpec (org.knime.core.data.DataTableSpec)19 RowKey (org.knime.core.data.RowKey)14 DataCell (org.knime.core.data.DataCell)12 DataColumnSpec (org.knime.core.data.DataColumnSpec)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 DefaultTable (org.knime.core.data.def.DefaultTable)10 DefaultRow (org.knime.core.data.def.DefaultRow)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)6 DataType (org.knime.core.data.DataType)6 PortObject (org.knime.core.node.port.PortObject)6 RowIterator (org.knime.core.data.RowIterator)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)5 ContainerTable (org.knime.core.data.container.ContainerTable)5 DataContainer (org.knime.core.data.container.DataContainer)5 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)5 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)5