Search in sources :

Example 21 with StreamableFunction

use of org.knime.core.node.streamable.StreamableFunction 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 22 with StreamableFunction

use of org.knime.core.node.streamable.StreamableFunction in project knime-core by knime.

the class PMMLRuleSetPredictorNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec preSpec = (DataTableSpec) inSpecs[DATA_INDEX];
    return new StreamableOperator() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final PortObjectInput modelPort = (PortObjectInput) inputs[MODEL_INDEX];
            final ColumnRearranger rearranger = createRearranger((PMMLPortObject) modelPort.getPortObject(), preSpec, m_doReplaceColumn.getBooleanValue(), m_doReplaceColumn.getBooleanValue() ? m_replaceColumn.getStringValue() : DataTableSpec.getUniqueColumnName(preSpec, m_outputColumn.getStringValue()), m_addConfidence.getBooleanValue(), m_confidenceColumn.getStringValue(), /*no validation column*/
            -1, /* no statistics computed, so concurrent processing is allowed*/
            true);
            final DataTableSpec tableSpec = rearranger.createSpec();
            if (m_doReplaceColumn.getBooleanValue()) {
                DataColumnSpec[] columns = new DataColumnSpec[preSpec.getNumColumns()];
                for (int i = columns.length; i-- > 0; ) {
                    columns[i] = preSpec.getColumnSpec(i);
                }
                int columnIndex = preSpec.findColumnIndex(m_replaceColumn.getStringValue());
                if (m_addConfidence.getBooleanValue()) {
                    // Move confidence to the end
                    rearranger.move(columnIndex, tableSpec.getNumColumns());
                    // Move the result to its place
                    rearranger.move(tableSpec.getNumColumns() - 2, columnIndex);
                }
            }
            final StreamableFunction function = rearranger.createStreamableFunction(DATA_INDEX, 0);
            function.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) DataColumnSpec(org.knime.core.data.DataColumnSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) PortObjectInput(org.knime.core.node.streamable.PortObjectInput)

Example 23 with StreamableFunction

use of org.knime.core.node.streamable.StreamableFunction in project knime-core by knime.

the class AbstractConditionalStreamingNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        private SimpleStreamableOperatorInternals m_internals;

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (SimpleStreamableOperatorInternals) internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            RowInput rowInput = (RowInput) inputs[0];
            while (rowInput.poll() != null) {
                count++;
            }
            m_internals.getConfig().addLong(CFG_ROW_COUNT, count);
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            long rowCount = -1;
            if (m_internals.getConfig().containsKey(CFG_ROW_COUNT)) {
                rowCount = m_internals.getConfig().getLong(CFG_ROW_COUNT);
            }
            StreamableFunction func = createColumnRearranger((DataTableSpec) inSpecs[0], rowCount).createStreamableFunction();
            func.runFinal(inputs, outputs, exec);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_internals;
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) RowInput(org.knime.core.node.streamable.RowInput) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Aggregations

ExecutionContext (org.knime.core.node.ExecutionContext)23 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)23 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)23 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)21 DataTableSpec (org.knime.core.data.DataTableSpec)16 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)7 RowInput (org.knime.core.node.streamable.RowInput)5 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)4 GradientBoostingModelPortObject (org.knime.base.node.mine.treeensemble2.model.GradientBoostingModelPortObject)3 GradientBoostingPredictor (org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 RowOutput (org.knime.core.node.streamable.RowOutput)3 TreeEnsembleModelPortObject (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject)2 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec)2 TreeEnsemblePredictor (org.knime.base.node.mine.treeensemble.node.predictor.TreeEnsemblePredictor)2 TreeEnsembleModelPortObject (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject)2 TreeEnsemblePredictor (org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictor)2 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)2 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)2 IOException (java.io.IOException)1