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];
}
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)) };
}
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)) };
}
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[] {};
}
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();
}
Aggregations