use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class ListFilesNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
ListFiles lister = new ListFiles(m_settings);
BufferedDataTable table = lister.search(exec);
return new BufferedDataTable[] { table };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class ColumnListLoopStartNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
ColumnRearranger crea = createRearranger(inData[0].getDataTableSpec());
m_currentColIndex++;
if (m_settings.iterateAllColumns()) {
m_lastIteration = m_currentColIndex >= inData[0].getDataTableSpec().getNumColumns();
} else {
m_lastIteration = m_currentColIndex >= m_settings.iterateOverColumns().size();
}
pushFlowVariableInt("currentIteration", m_iteration);
// increment counter for next iteration
m_iteration++;
return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[0], crea, exec) };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
LOGGER.debug("Entering execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
// check input data
assert (inData != null && inData.length == 2 && inData[DATA_IN_PORT] != null && inData[MODEL_IN_PORT] != null);
final PortObject dataObject = inData[DATA_IN_PORT];
if (!(dataObject instanceof BufferedDataTable)) {
throw new IllegalArgumentException("Invalid input data");
}
final BufferedDataTable data = (BufferedDataTable) dataObject;
final PortObject modelObject = inData[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObject)) {
throw new IllegalArgumentException("Invalid input data");
}
final NaiveBayesModel model = ((NaiveBayesPortObject) modelObject).getModel();
exec.setMessage("Classifying rows...");
if (model == null) {
throw new Exception("Node not properly configured. " + "No Naive Bayes Model available.");
}
final double laplaceCorrector = m_laplaceCorrector.getDoubleValue();
final NaiveBayesCellFactory appender = new NaiveBayesCellFactory(model, data.getDataTableSpec(), m_inclProbVals.getBooleanValue(), laplaceCorrector);
final ColumnRearranger rearranger = new ColumnRearranger(data.getDataTableSpec());
rearranger.append(appender);
final BufferedDataTable returnVal = exec.createColumnRearrangeTable(data, rearranger, exec);
LOGGER.debug("Exiting execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
return new PortObject[] { returnVal };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class DecTreePredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
public PortObject[] execute(final PortObject[] inPorts, final ExecutionContext exec) throws CanceledExecutionException, Exception {
exec.setMessage("Decision Tree Predictor: Loading predictor...");
PMMLPortObject port = (PMMLPortObject) inPorts[INMODELPORT];
List<Node> models = port.getPMMLValue().getModels(PMMLModelType.TreeModel);
if (models.isEmpty()) {
String msg = "Decision Tree evaluation failed: " + "No tree model found.";
LOGGER.error(msg);
throw new RuntimeException(msg);
}
PMMLDecisionTreeTranslator trans = new PMMLDecisionTreeTranslator();
port.initializeModelTranslator(trans);
DecisionTree decTree = trans.getDecisionTree();
decTree.resetColorInformation();
BufferedDataTable inData = (BufferedDataTable) inPorts[INDATAPORT];
// get column with color information
String colorColumn = null;
for (DataColumnSpec s : inData.getDataTableSpec()) {
if (s.getColorHandler() != null) {
colorColumn = s.getName();
break;
}
}
decTree.setColorColumn(colorColumn);
exec.setMessage("Decision Tree Predictor: start execution.");
PortObjectSpec[] inSpecs = new PortObjectSpec[] { inPorts[0].getSpec(), inPorts[1].getSpec() };
DataTableSpec outSpec = createOutTableSpec(inSpecs);
BufferedDataContainer outData = exec.createDataContainer(outSpec);
long coveredPattern = 0;
long nrPattern = 0;
long rowCount = 0;
long numberRows = inData.size();
exec.setMessage("Classifying...");
for (DataRow thisRow : inData) {
DataCell cl = null;
LinkedHashMap<String, Double> classDistrib = null;
try {
Pair<DataCell, LinkedHashMap<DataCell, Double>> pair = decTree.getWinnerAndClasscounts(thisRow, inData.getDataTableSpec());
cl = pair.getFirst();
LinkedHashMap<DataCell, Double> classCounts = pair.getSecond();
classDistrib = getDistribution(classCounts);
if (coveredPattern < m_maxNumCoveredPattern.getIntValue()) {
// remember this one for HiLite support
decTree.addCoveredPattern(thisRow, inData.getDataTableSpec());
coveredPattern++;
} else {
// too many patterns for HiLite - at least remember color
decTree.addCoveredColor(thisRow, inData.getDataTableSpec());
}
nrPattern++;
} catch (Exception e) {
LOGGER.error("Decision Tree evaluation failed: " + e.getMessage());
throw e;
}
if (cl == null) {
LOGGER.error("Decision Tree evaluation failed: result empty");
throw new Exception("Decision Tree evaluation failed.");
}
DataCell[] newCells = new DataCell[outSpec.getNumColumns()];
int numInCells = thisRow.getNumCells();
for (int i = 0; i < numInCells; i++) {
newCells[i] = thisRow.getCell(i);
}
if (m_showDistribution.getBooleanValue()) {
for (int i = numInCells; i < newCells.length - 1; i++) {
String predClass = outSpec.getColumnSpec(i).getName();
if (classDistrib != null && classDistrib.get(predClass) != null) {
newCells[i] = new DoubleCell(classDistrib.get(predClass));
} else {
newCells[i] = new DoubleCell(0.0);
}
}
}
newCells[newCells.length - 1] = cl;
outData.addRowToTable(new DefaultRow(thisRow.getKey(), newCells));
rowCount++;
if (rowCount % 100 == 0) {
exec.setProgress(rowCount / (double) numberRows, "Classifying... Row " + rowCount + " of " + numberRows);
}
exec.checkCanceled();
}
if (coveredPattern < nrPattern) {
// let the user know that we did not store all available pattern
// for HiLiting.
this.setWarningMessage("Tree only stored first " + m_maxNumCoveredPattern.getIntValue() + " (of " + nrPattern + ") rows for HiLiting!");
}
outData.close();
m_decTree = decTree;
exec.setMessage("Decision Tree Predictor: end execution.");
return new BufferedDataTable[] { outData.getTable() };
}
use of org.knime.core.node.BufferedDataTable in project knime-core by knime.
the class MLPPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
public PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable testdata = (BufferedDataTable) inData[1];
PMMLPortObject pmmlPort = (PMMLPortObject) inData[0];
List<Node> models = pmmlPort.getPMMLValue().getModels(PMMLModelType.NeuralNetwork);
if (models.isEmpty()) {
String msg = "Neural network evaluation failed: " + "No neural network model found.";
LOGGER.error(msg);
throw new RuntimeException(msg);
}
PMMLNeuralNetworkTranslator trans = new PMMLNeuralNetworkTranslator();
pmmlPort.initializeModelTranslator(trans);
m_mlp = trans.getMLP();
m_columns = getLearningColumnIndices(testdata.getDataTableSpec(), pmmlPort.getSpec());
DataColumnSpec targetCol = pmmlPort.getSpec().getTargetCols().iterator().next();
MLPClassificationFactory mymlp;
/*
* Regression
*/
if (m_mlp.getMode() == MultiLayerPerceptron.REGRESSION_MODE) {
mymlp = new MLPClassificationFactory(true, m_columns, targetCol);
} else if (m_mlp.getMode() == MultiLayerPerceptron.CLASSIFICATION_MODE) {
/*
* Classification
*/
mymlp = new MLPClassificationFactory(false, m_columns, targetCol);
} else {
throw new Exception("Unsupported Mode: " + m_mlp.getMode());
}
ColumnRearranger colre = new ColumnRearranger(testdata.getDataTableSpec());
colre.append(mymlp);
BufferedDataTable bdt = exec.createColumnRearrangeTable(testdata, colre, exec);
return new BufferedDataTable[] { bdt };
}
Aggregations