use of org.knime.core.node.ExecutionContext in project knime-core by knime.
the class TreeEnsembleClassificationPredictorNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
TreeEnsembleModelPortObject model = (TreeEnsembleModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final TreeEnsemblePredictor pred = new TreeEnsemblePredictor(modelSpec, model, dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
StreamableFunction func = rearranger.createStreamableFunction(1, 0);
func.runFinal(inputs, outputs, exec);
}
};
}
use of org.knime.core.node.ExecutionContext in project knime-core by knime.
the class GradientBoostingPMMLPredictorNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
PMMLPortObject model = (PMMLPortObject) ((PortObjectInput) inputs[0]).getPortObject();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
GradientBoostingModelPortObject gbt = importModel(model);
final GradientBoostingPredictor<?> pred = new GradientBoostingPredictor<>(gbt.getEnsembleModel(), gbt.getSpec(), dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
StreamableFunction func = rearranger.createStreamableFunction(1, 0);
func.runFinal(inputs, outputs, exec);
}
};
}
use of org.knime.core.node.ExecutionContext in project knime-core by knime.
the class RandomForestNearestNeighborNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
TreeEnsembleModelPortObject ensembleModel = (TreeEnsembleModelPortObject) inObjects[0];
boolean optionalTable = inObjects[2] != null;
BufferedDataTable[] tables = new BufferedDataTable[optionalTable ? 2 : 1];
tables[0] = (BufferedDataTable) inObjects[1];
if (optionalTable) {
tables[1] = (BufferedDataTable) inObjects[2];
}
ExecutionContext proxExec = exec.createSubExecutionContext(0.6);
ExecutionContext nnExec = exec.createSubExecutionContext(0.4);
exec.setMessage("Calculating");
ProximityMatrix proximityMatrix = Proximity.calcProximities(tables, ensembleModel, proxExec);
ProximityMeasure proximityMeasure = ProximityMeasure.valueOf(m_proximityMeasure.getStringValue());
switch(proximityMeasure) {
case Proximity:
proximityMatrix = Proximity.calcProximities(tables, ensembleModel, proxExec);
break;
case PathProximity:
proximityMatrix = new PathProximity(tables, ensembleModel).calculatePathProximities(proxExec);
break;
default:
throw new IllegalStateException("Encountered unknown proximity measure.");
}
exec.setMessage("Calculating nearest neighbors");
int k = m_numNearestNeighbors.getIntValue();
return proximityMatrix.getNearestNeighbors(nnExec, k);
}
use of org.knime.core.node.ExecutionContext in project knime-core by knime.
the class TableSorterTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
NodeFactory<NodeModel> dummyFactory = (NodeFactory) new VirtualParallelizedChunkPortObjectInNodeFactory(new PortType[0]);
m_exec = new ExecutionContext(new DefaultNodeProgressMonitor(), new Node(dummyFactory), SingleNodeContainer.MemoryPolicy.CacheOnDisc, new HashMap<Integer, ContainerTable>());
}
use of org.knime.core.node.ExecutionContext in project knime-core by knime.
the class RankCorrelationComputeNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable in = (BufferedDataTable) inData[0];
final DataTableSpec inSpec = in.getDataTableSpec();
ColumnRearranger filteredTableRearranger = new ColumnRearranger(inSpec);
String[] includeNames = m_columnFilterModel.applyTo(inSpec).getIncludes();
filteredTableRearranger.keepOnly(includeNames);
final BufferedDataTable filteredTable = exec.createColumnRearrangeTable(in, filteredTableRearranger, exec.createSilentSubExecutionContext(0.0));
final BufferedDataTable noMissTable = filterMissings(filteredTable, exec);
if (noMissTable.getRowCount() < filteredTable.getRowCount()) {
setWarningMessage("Rows containing missing values are filtered. Please resolve them" + " with the Missing Value node.");
}
double progStep1 = 0.48;
double progStep2 = 0.48;
double progFinish = 1.0 - progStep1 - progStep2;
SortedCorrelationComputer calculator = new SortedCorrelationComputer();
exec.setMessage("Generate ranking");
ExecutionContext execStep1 = exec.createSubExecutionContext(progStep1);
calculator.generateRank(noMissTable, execStep1);
execStep1.setProgress(1.0);
exec.setMessage("Calculating correlation values");
ExecutionContext execStep2 = exec.createSubExecutionContext(progStep2);
HalfDoubleMatrix correlationMatrix;
if (m_corrType.getStringValue().equals(CFG_SPEARMAN)) {
correlationMatrix = calculator.calculateSpearman(execStep2);
} else {
correlationMatrix = calculator.calculateKendallInMemory(m_corrType.getStringValue(), execStep2);
}
execStep2.setProgress(1.0);
exec.setMessage("Assembling output");
ExecutionContext execFinish = exec.createSubExecutionContext(progFinish);
PMCCPortObjectAndSpec pmccModel = new PMCCPortObjectAndSpec(includeNames, correlationMatrix);
BufferedDataTable out = pmccModel.createCorrelationMatrix(execFinish);
m_correlationTable = out;
if (in.getRowCount() == 0) {
setWarningMessage("Empty input table! Generating missing values as correlation values.");
}
return new PortObject[] { out, pmccModel, calculator.getRankTable() };
}
Aggregations