Search in sources :

Example 91 with ExecutionContext

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);
        }
    };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictor) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 92 with ExecutionContext

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);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) GradientBoostingModelPortObject(org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 93 with ExecutionContext

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);
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) ExecutionContext(org.knime.core.node.ExecutionContext) BufferedDataTable(org.knime.core.node.BufferedDataTable) ProximityMatrix(org.knime.base.node.mine.treeensemble2.node.proximity.ProximityMatrix) ProximityMeasure(org.knime.base.node.mine.treeensemble2.node.proximity.RandomForestProximityNodeModel.ProximityMeasure) PathProximity(org.knime.base.node.mine.treeensemble2.node.proximity.PathProximity)

Example 94 with ExecutionContext

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>());
}
Also used : NodeModel(org.knime.core.node.NodeModel) ExecutionContext(org.knime.core.node.ExecutionContext) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) NodeFactory(org.knime.core.node.NodeFactory) HashMap(java.util.HashMap) VirtualParallelizedChunkPortObjectInNodeFactory(org.knime.core.node.workflow.virtual.parchunk.VirtualParallelizedChunkPortObjectInNodeFactory) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) Node(org.knime.core.node.Node) PortType(org.knime.core.node.port.PortType) Before(org.junit.Before)

Example 95 with ExecutionContext

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() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ExecutionContext(org.knime.core.node.ExecutionContext) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PortObject(org.knime.core.node.port.PortObject)

Aggregations

ExecutionContext (org.knime.core.node.ExecutionContext)107 DataTableSpec (org.knime.core.data.DataTableSpec)61 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)45 BufferedDataTable (org.knime.core.node.BufferedDataTable)44 DataRow (org.knime.core.data.DataRow)35 RowInput (org.knime.core.node.streamable.RowInput)26 RowOutput (org.knime.core.node.streamable.RowOutput)24 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)23 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)20 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)20 DataColumnSpec (org.knime.core.data.DataColumnSpec)19 DataCell (org.knime.core.data.DataCell)18 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)15 NodeModel (org.knime.core.node.NodeModel)14 PortObject (org.knime.core.node.port.PortObject)14 RowKey (org.knime.core.data.RowKey)13 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)13 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)13 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)12