Search in sources :

Example 31 with ExecutionMonitor

use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.

the class AbstractBlobsInWorkflowTest method testSize.

public void testSize() throws Exception {
    m_flow.save(m_wfmDir, new ExecutionMonitor(), true);
    long size = calculateSize(m_wfmDir);
    double sizeInMB = size / 1024 / 1024.0;
    long roughlyExpectedSize = getApproximateSize();
    double roughlyExpectedSizeInMB = roughlyExpectedSize / 1024 / 1024.0;
    String error = "Size of workflow out of range, expected ~" + roughlyExpectedSizeInMB + "MB, actual " + sizeInMB + "MB";
    assertTrue(error, size > 0.8 * roughlyExpectedSize);
    assertTrue(error, size < 1.2 * roughlyExpectedSize);
    NodeLogger.getLogger(getClass()).info("Test succeeds: expected size (in MB) is " + sizeInMB + ", expected " + roughlyExpectedSizeInMB + " -- which is ok");
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 32 with ExecutionMonitor

use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.

the class LogRegCoordinator method learn.

/**
 * Performs the learning task by creating the appropriate LogRegLearner and all other objects
 * necessary for a successful training.
 *
 * @param trainingData a DataTable that contains the data on which to learn the logistic regression model
 * @param exec the execution context of the corresponding KNIME node
 * @return the content of the logistic regression model
 * @throws InvalidSettingsException if the settings cause inconsistencies during training
 * @throws CanceledExecutionException if the training is canceled
 */
LogisticRegressionContent learn(final BufferedDataTable trainingData, final ExecutionContext exec) throws InvalidSettingsException, CanceledExecutionException {
    CheckUtils.checkArgument(trainingData.size() > 0, "The input table is empty. Please provide data to learn on.");
    CheckUtils.checkArgument(trainingData.size() <= Integer.MAX_VALUE, "The input table contains too many rows.");
    LogRegLearner learner;
    if (m_settings.getSolver() == Solver.IRLS) {
        learner = new IrlsLearner(m_settings.getMaxEpoch(), m_settings.getEpsilon(), m_settings.isCalcCovMatrix());
    } else {
        learner = new SagLogRegLearner(m_settings);
    }
    double calcDomainTime = 1.0 / (5.0 * 2.0 + 1.0);
    exec.setMessage("Analyzing categorical data");
    BufferedDataTable dataTable = recalcDomainForTargetAndLearningFields(trainingData, exec.createSubExecutionContext(calcDomainTime));
    checkConstantLearningFields(dataTable);
    exec.setMessage("Building logistic regression model");
    ExecutionMonitor trainExec = exec.createSubProgress(1.0 - calcDomainTime);
    LogRegLearnerResult result;
    TrainingRowBuilder<ClassificationTrainingRow> rowBuilder = new SparseClassificationTrainingRowBuilder(dataTable, m_pmmlOutSpec, m_settings.getTargetReferenceCategory(), m_settings.getSortTargetCategories(), m_settings.getSortIncludesCategories());
    TrainingData<ClassificationTrainingRow> data;
    Long seed = m_settings.getSeed();
    if (m_settings.isInMemory()) {
        data = new InMemoryData<ClassificationTrainingRow>(dataTable, seed, rowBuilder);
    } else {
        data = new DataTableTrainingData<ClassificationTrainingRow>(trainingData, seed, rowBuilder, m_settings.getChunkSize(), exec.createSilentSubExecutionContext(0.0));
    }
    checkShapeCompatibility(data);
    result = learner.learn(data, trainExec);
    LogisticRegressionContent content = createContentFromLearnerResult(result, rowBuilder, trainingData.getDataTableSpec());
    addToWarning(learner.getWarningMessage());
    return content;
}
Also used : ClassificationTrainingRow(org.knime.base.node.mine.regression.logistic.learner4.data.ClassificationTrainingRow) SparseClassificationTrainingRowBuilder(org.knime.base.node.mine.regression.logistic.learner4.data.SparseClassificationTrainingRowBuilder) SagLogRegLearner(org.knime.base.node.mine.regression.logistic.learner4.sg.SagLogRegLearner) SagLogRegLearner(org.knime.base.node.mine.regression.logistic.learner4.sg.SagLogRegLearner) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 33 with ExecutionMonitor

use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.

the class HistogramNodeModel method createHistogramModel.

/**
 * {@inheritDoc}
 */
@Override
protected void createHistogramModel(final ExecutionContext exec, final int noOfRows, final BufferedDataTable data) throws CanceledExecutionException {
    LOGGER.debug("Entering createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
    if (noOfRows == 0) {
        m_model = null;
        return;
    }
    if (exec == null) {
        throw new NullPointerException("exec must not be null");
    }
    if (data == null) {
        throw new IllegalArgumentException("Table shouldn't be null");
    }
    ExecutionMonitor subExec = exec.createSubProgress(0.5);
    exec.setMessage("Adding rows to histogram model...");
    final DataArray dataArray = new DefaultDataArray(data, 1, noOfRows, subExec);
    exec.setMessage("Adding row color to histogram...");
    final SortedSet<Color> colorSet = new TreeSet<Color>(HSBColorComparator.getInstance());
    subExec = exec.createSubProgress(0.5);
    final double progressPerRow = 1.0 / noOfRows;
    double progress = 0.0;
    final CloseableRowIterator rowIterator = data.iterator();
    try {
        for (int i = 0; i < noOfRows && rowIterator.hasNext(); i++) {
            final DataRow row = rowIterator.next();
            final Color color = data.getDataTableSpec().getRowColor(row).getColor(false, false);
            if (!colorSet.contains(color)) {
                colorSet.add(color);
            }
            progress += progressPerRow;
            subExec.setProgress(progress, "Adding data rows to histogram...");
            subExec.checkCanceled();
        }
    } finally {
        if (rowIterator != null) {
            rowIterator.close();
        }
    }
    exec.setProgress(1.0, "Histogram finished.");
    m_model = new InteractiveHistogramDataModel(dataArray, new ArrayList<Color>(colorSet));
    LOGGER.debug("Exiting createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
}
Also used : DefaultDataArray(org.knime.base.node.util.DefaultDataArray) InteractiveHistogramDataModel(org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramDataModel) Color(java.awt.Color) ArrayList(java.util.ArrayList) CloseableRowIterator(org.knime.core.data.container.CloseableRowIterator) DataRow(org.knime.core.data.DataRow) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) DataArray(org.knime.base.node.util.DataArray) TreeSet(java.util.TreeSet) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 34 with ExecutionMonitor

use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.

the class TableNodeView method writeToCSV.

/**
 * Called by the JMenu item "Write to CVS", it write the table as shown in
 * table view to a CSV file.
 *
 * @param file the file to write to
 */
private void writeToCSV(final File file) {
    // CSV Writer supports ExecutionMonitor. Some table may be big.
    DefaultNodeProgressMonitor progMon = new DefaultNodeProgressMonitor();
    ExecutionMonitor e = new ExecutionMonitor(progMon);
    // Frame of m_tableView (if any)
    Frame f = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, m_tableView);
    final NodeProgressMonitorView progView = new NodeProgressMonitorView(f, progMon);
    // CSV Writer does not support 1-100 progress (unknown row count)
    progView.setShowProgress(false);
    // Writing is done in a thread (allows repainting of GUI)
    final CSVWriterThread t = new CSVWriterThread(file, e);
    t.start();
    // A thread that waits for t to finish and then disposes the prog view
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                t.join();
            } catch (InterruptedException ie) {
            // do nothing. Only dispose the view
            } finally {
                progView.dispose();
            }
        }
    }).start();
    progView.pack();
    progView.setLocationRelativeTo(m_tableView);
    progView.setVisible(true);
}
Also used : Frame(java.awt.Frame) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) NodeProgressMonitorView(org.knime.core.node.NodeProgressMonitorView)

Example 35 with ExecutionMonitor

use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.

the class ExpandVectorNodeModel method createRearranger.

/**
 * Creates the {@link ColumnRearranger} to perform the computation.
 *
 * @param table The input table.
 * @param exec An {@link ExecutionMonitor}.
 * @return The {@link ColumnRearranger}.
 * @throws CanceledExecutionException Execution cancelled.
 */
private ColumnRearranger createRearranger(final BufferedDataTable table, final ExecutionMonitor exec) throws CanceledExecutionException {
    DataTableSpec spec = table.getSpec();
    final ColumnRearranger ret = new ColumnRearranger(spec);
    ExecutionMonitor subRead = exec.createSubProgress(.25);
    int maxOutput = 0;
    String inputColumnName = findInputColumnName(spec);
    final int colIndex = spec.findColumnIndex(inputColumnName);
    for (DataRow dataRow : table) {
        subRead.checkCanceled();
        DataCell cell = dataRow.getCell(colIndex);
        long length = getCellLength(cell);
        if (length > m_maxNewColumns.getIntValue()) {
            length = m_maxNewColumns.getIntValue();
        }
        maxOutput = Math.max(maxOutput, (int) length);
    }
    final String[] colNames = new String[maxOutput];
    final DataColumnSpec inputSpec = spec.getColumnSpec(inputColumnName);
    final int namedColumns;
    if (useNames()) {
        String[] origNames = inputSpec.getElementNames().toArray(new String[0]);
        System.arraycopy(origNames, 0, colNames, 0, Math.min(maxOutput, origNames.length));
        namedColumns = origNames.length;
    } else {
        namedColumns = 0;
    }
    for (int i = namedColumns; i < maxOutput; ++i) {
        colNames[i] = m_outputPrefix.getStringValue() + (i - namedColumns + m_startIndex.getIntValue());
    }
    DataColumnSpec[] outputColumns = new DataColumnSpec[maxOutput];
    DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator("Dummy", IntCell.TYPE);
    for (int idx = 0; idx < colNames.length; ++idx) {
        dataColumnSpecCreator.setName(DataTableSpec.getUniqueColumnName(spec, colNames[idx]));
        outputColumns[idx] = dataColumnSpecCreator.createSpec();
    }
    ret.append(createCellFactory(colNames, outputColumns, colIndex));
    if (m_removeOriginal.getBooleanValue()) {
        ret.remove(inputColumnName);
    }
    return ret;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DataRow(org.knime.core.data.DataRow)

Aggregations

ExecutionMonitor (org.knime.core.node.ExecutionMonitor)160 BufferedDataTable (org.knime.core.node.BufferedDataTable)50 DataTableSpec (org.knime.core.data.DataTableSpec)43 DataRow (org.knime.core.data.DataRow)39 DataCell (org.knime.core.data.DataCell)35 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)35 Test (org.junit.Test)33 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)33 File (java.io.File)29 IOException (java.io.IOException)25 PortObject (org.knime.core.node.port.PortObject)25 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)23 DataColumnSpec (org.knime.core.data.DataColumnSpec)21 RowKey (org.knime.core.data.RowKey)20 ArrayList (java.util.ArrayList)19 WorkflowLoadResult (org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)17 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)16 ExecutionException (java.util.concurrent.ExecutionException)14 ExecutionContext (org.knime.core.node.ExecutionContext)13 FileOutputStream (java.io.FileOutputStream)12