use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class PCAApplyNodeModel method execute.
/**
* Performs the PCA.
*
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final PCAModelPortObject model = (PCAModelPortObject) inData[MODEL_INPORT];
final int dimensions = m_dimSelection.getNeededDimensions();
if (dimensions == -1) {
throw new IllegalArgumentException("Number of dimensions not correct configured");
}
if (m_failOnMissingValues.getBooleanValue()) {
for (final DataRow row : (DataTable) inData[DATA_INPORT]) {
for (int i = 0; i < m_inputColumnIndices.length; i++) {
if (row.getCell(m_inputColumnIndices[i]).isMissing()) {
throw new IllegalArgumentException("data table contains missing values");
}
}
}
}
final Matrix eigenvectors = EigenValue.getSortedEigenVectors(model.getEigenVectors(), model.getEigenvalues(), dimensions);
final DataColumnSpec[] specs = PCANodeModel.createAddTableSpec((DataTableSpec) inData[DATA_INPORT].getSpec(), dimensions);
final int dim = dimensions;
final CellFactory fac = new CellFactory() {
@Override
public DataCell[] getCells(final DataRow row) {
return PCANodeModel.convertInputRow(eigenvectors, row, model.getCenter(), m_inputColumnIndices, dim, m_failOnMissingValues.getBooleanValue());
}
@Override
public DataColumnSpec[] getColumnSpecs() {
return specs;
}
@Override
public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor texec) {
texec.setProgress((double) curRowNr / rowCount, "converting input row " + curRowNr + " of " + rowCount);
}
};
final ColumnRearranger cr = new ColumnRearranger((DataTableSpec) inData[DATA_INPORT].getSpec());
cr.append(fac);
if (m_removeOriginalCols.getBooleanValue()) {
cr.remove(m_inputColumnNames);
}
final BufferedDataTable result = exec.createColumnRearrangeTable((BufferedDataTable) inData[DATA_INPORT], cr, exec);
final PortObject[] out = { result };
return out;
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class PMMLKNNNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inPorts, final ExecutionContext exec) throws Exception {
BufferedDataTable inTable = (BufferedDataTable) inPorts[0];
if (m_limitRows.getBooleanValue() && inTable.size() > m_maxNumRows.getIntValue()) {
setWarningMessage("The number of records in the table (" + inTable.size() + ") exceeds the maximum record number of " + m_maxNumRows.getIntValue());
}
PMMLPortObject outPort = new PMMLPortObject(createSpec(inTable.getDataTableSpec()));
// -1 means that rows are not limited at all
int maxRows = -1;
if (m_limitRows.getBooleanValue()) {
maxRows = m_maxNumRows.getIntValue();
}
String[] includes = m_learningColumns.applyTo(inTable.getDataTableSpec()).getIncludes();
if (includes.length == 0) {
throw new InvalidSettingsException("No learning columns are selected.");
}
outPort.addModelTranslater(new PMMLKNNTranslator(inTable, maxRows, m_numNeighbors.getIntValue(), includes));
return new PortObject[] { outPort };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class CategoryToNumberNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec inSpec = (DataTableSpec) inObjects[0].getSpec();
ColumnRearranger rearranger = createRearranger(inSpec);
BufferedDataTable outTable = exec.createColumnRearrangeTable(inData, rearranger, exec);
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inObjects[1] : null;
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, rearranger.createSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
for (CategoryToNumberCellFactory factory : m_factories) {
PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
}
return new PortObject[] { outTable, outPMMLPort };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class CategoryToNumberApplyNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
PMMLPortObject model = (PMMLPortObject) inData[0];
BufferedDataTable table = (BufferedDataTable) inData[1];
ColumnRearranger rearranger = createRearranger(table.getDataTableSpec(), model);
if (null == rearranger) {
throw new IllegalArgumentException("No map values configuration found.");
}
BufferedDataTable outTable = exec.createColumnRearrangeTable(table, rearranger, exec);
return new PortObject[] { model, outTable };
}
use of org.knime.core.node.port.PortObject in project knime-core by knime.
the class NumberToCategoryApplyNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
PMMLPortObject model = (PMMLPortObject) inData[0];
BufferedDataTable table = (BufferedDataTable) inData[1];
ColumnRearranger rearranger = createRearranger(table.getDataTableSpec(), model);
if (null == rearranger) {
throw new IllegalArgumentException("No map values configuration found.");
}
BufferedDataTable outTable = exec.createColumnRearrangeTable(table, rearranger, exec);
return new PortObject[] { model, outTable };
}
Aggregations