Search in sources :

Example 96 with BufferedDataTable

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

the class SampleDataNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] data, final ExecutionContext exec) throws Exception {
    DataTableSpec[] outSpecs = configure(new DataTableSpec[2]);
    DataTableSpec dataSpec = outSpecs[0];
    DataTableSpec clusterSpec = outSpecs[1];
    BufferedDataTableRowOutput dataOut = new BufferedDataTableRowOutput(exec.createDataContainer(dataSpec));
    BufferedDataTableRowOutput clusterOut = new BufferedDataTableRowOutput(exec.createDataContainer(clusterSpec));
    run(dataSpec, dataOut, clusterSpec, clusterOut, exec);
    return new BufferedDataTable[] { dataOut.getDataTable(), clusterOut.getDataTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 97 with BufferedDataTable

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

the class ShapeManagerNodeModel method execute.

/**
 * Is invoked during the node's execution to make the shape settings.
 *
 * @param data the input data array
 * @param exec the execution monitor
 * @return the same input data table with assigned shapes to one column
 * @throws CanceledExecutionException if user canceled execution
 *
 * @see NodeModel#execute(BufferedDataTable[],ExecutionContext)
 */
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws CanceledExecutionException {
    BufferedDataTable inData = (BufferedDataTable) data[INPORT];
    ShapeHandler shapeHandler = new ShapeHandler(new ShapeModelNominal(m_map));
    final DataTableSpec newSpec = appendShapeHandler(inData.getSpec(), m_column, shapeHandler);
    BufferedDataTable changedSpecTable = exec.createSpecReplacerTable(inData, newSpec);
    DataTableSpec modelSpec = new DataTableSpec(newSpec.getColumnSpec(m_column));
    ShapeHandlerPortObject viewPort = new ShapeHandlerPortObject(modelSpec, shapeHandler.toString() + " based on column \"" + m_column + "\"");
    return new PortObject[] { changedSpecTable, viewPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) ShapeHandler(org.knime.core.data.property.ShapeHandler) ShapeHandlerPortObject(org.knime.core.node.port.viewproperty.ShapeHandlerPortObject) ShapeHandlerPortObject(org.knime.core.node.port.viewproperty.ShapeHandlerPortObject) PortObject(org.knime.core.node.port.PortObject) ShapeModelNominal(org.knime.core.data.property.ShapeModelNominal)

Example 98 with BufferedDataTable

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

the class SizeManager2NodeModel method execute.

/**
 * Is invoked during the node's execution to make the size settings.
 *
 * @param data the input data array
 * @param exec the execution monitor
 * @return the same input data table whereby the DataTableSpec contains
 *         additional size infos
 * @throws CanceledExecutionException if user canceled execution
 *
 * @see NodeModel#execute(BufferedDataTable[],ExecutionContext)
 */
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws CanceledExecutionException {
    final DataTableSpec inSpec = (DataTableSpec) data[INPORT].getSpec();
    final String columnName = m_column.getStringValue();
    final DataColumnSpec cspec = inSpec.getColumnSpec(columnName);
    SizeHandler sizeHandler = createSizeHandler(cspec);
    final DataTableSpec newSpec = appendSizeHandler(inSpec, columnName, sizeHandler);
    BufferedDataTable changedSpecTable = exec.createSpecReplacerTable((BufferedDataTable) data[INPORT], newSpec);
    DataTableSpec modelSpec = new DataTableSpec(newSpec.getColumnSpec(m_column.getStringValue()));
    SizeHandlerPortObject viewPort = new SizeHandlerPortObject(modelSpec, sizeHandler.toString() + " based on column \"" + m_column.getStringValue() + "\"");
    return new PortObject[] { changedSpecTable, viewPort };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) SizeHandler(org.knime.core.data.property.SizeHandler) BufferedDataTable(org.knime.core.node.BufferedDataTable) SizeHandlerPortObject(org.knime.core.node.port.viewproperty.SizeHandlerPortObject) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SizeHandlerPortObject(org.knime.core.node.port.viewproperty.SizeHandlerPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 99 with BufferedDataTable

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

the class LiftChartNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    ConvenienceMethods.checkTableSize(inData[0]);
    int predColIndex = inData[0].getDataTableSpec().findColumnIndex(m_responseColumn.getStringValue());
    List<String> inclList = new LinkedList<String>();
    inclList.add(m_probabilityColumn.getStringValue());
    boolean[] order = new boolean[] { false };
    SortedTable st = new SortedTable(inData[0], inclList, order, exec);
    long totalResponses = 0;
    double partWidth = Double.parseDouble(m_intervalWidth.getStringValue());
    int nrParts = (int) Math.ceil(100.0 / partWidth);
    List<Integer> positiveResponses = new LinkedList<Integer>();
    int rowIndex = 0;
    for (DataRow row : st) {
        if (row.getCell(predColIndex).isMissing()) {
            setWarningMessage("There are missing values." + " Please check your data.");
            continue;
        }
        String response = ((StringValue) row.getCell(predColIndex)).getStringValue().trim();
        if (response.equalsIgnoreCase(m_responseLabel.getStringValue())) {
            totalResponses++;
            positiveResponses.add(rowIndex);
        }
        rowIndex++;
    }
    int[] counter = new int[nrParts];
    int partWidthAbsolute = (int) Math.ceil(rowIndex / (double) nrParts);
    double avgResponse = (double) positiveResponses.size() / rowIndex;
    for (int rIndex : positiveResponses) {
        int index = rIndex / partWidthAbsolute;
        counter[index]++;
    }
    DataColumnSpec[] colSpec = new DataColumnSpec[3];
    colSpec[0] = new DataColumnSpecCreator("Lift", DoubleCell.TYPE).createSpec();
    colSpec[1] = new DataColumnSpecCreator("Baseline", DoubleCell.TYPE).createSpec();
    colSpec[2] = new DataColumnSpecCreator("Cumulative Lift", DoubleCell.TYPE).createSpec();
    DataTableSpec tableSpec = new DataTableSpec(colSpec);
    DataContainer cont = exec.createDataContainer(tableSpec);
    colSpec = new DataColumnSpec[2];
    colSpec[0] = new DataColumnSpecCreator("Actual", DoubleCell.TYPE).createSpec();
    colSpec[1] = new DataColumnSpecCreator("Baseline", DoubleCell.TYPE).createSpec();
    tableSpec = new DataTableSpec(colSpec);
    DataContainer responseCont = exec.createDataContainer(tableSpec);
    long cumulativeCounter = 0;
    responseCont.addRowToTable(new DefaultRow(new RowKey("0"), 0.0, 0.0));
    for (int i = 0; i < counter.length; i++) {
        cumulativeCounter += counter[i];
        double responseRate = (double) counter[i] / partWidthAbsolute;
        double lift = responseRate / avgResponse;
        double cumResponseRate = (double) cumulativeCounter / totalResponses;
        long number = partWidthAbsolute * (i + 1);
        // well.. rounding problems
        if (number > rowIndex) {
            number = rowIndex;
        }
        double cumulativeLift = // (double)cumulativeCounter / (partWidthAbsolute * (i + 1));
        (double) cumulativeCounter / number;
        cumulativeLift /= avgResponse;
        // cumulativeLift = lifts / (i+1);
        double rowKey = ((i + 1) * partWidth);
        if (rowKey > 100) {
            rowKey = 100;
        }
        cont.addRowToTable(new DefaultRow(new RowKey("" + rowKey), lift, 1.0, cumulativeLift));
        double cumBaseline = (i + 1) * partWidth;
        if (cumBaseline > 100) {
            cumBaseline = 100;
        }
        responseCont.addRowToTable(new DefaultRow(new RowKey("" + rowKey), cumResponseRate * 100, cumBaseline));
    }
    cont.close();
    responseCont.close();
    m_dataArray[0] = new DefaultDataArray(cont.getTable(), 1, (int) cont.size());
    m_dataArray[1] = new DefaultDataArray(responseCont.getTable(), 1, (int) responseCont.size());
    return new BufferedDataTable[] { st.getBufferedDataTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) RowKey(org.knime.core.data.RowKey) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) LinkedList(java.util.LinkedList) DataContainer(org.knime.core.data.container.DataContainer) DataColumnSpec(org.knime.core.data.DataColumnSpec) SortedTable(org.knime.base.data.sort.SortedTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 100 with BufferedDataTable

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

the class TableSorterTest method runMemoryTest.

private void runMemoryTest(final int numRows, final int maxNumRowsPerContainer, final int maxOpenContainers) throws CanceledExecutionException {
    // Create data with fields that consume a lot memory
    DataTable inputTable = new TestData(numRows, 1);
    BufferedDataTable bdt = m_exec.createBufferedDataTable(inputTable, m_exec);
    BufferedDataTableSorter sorter = new BufferedDataTableSorter(bdt, Arrays.asList("Index"), new boolean[] { true });
    sorter.setMaxOpenContainers(maxOpenContainers);
    BufferedDataTable defaultResult = sorter.sort(m_exec);
    sorter.setMaxRows(maxNumRowsPerContainer);
    // 10MB free memory
    long currentlyUsed = MemoryAlertSystem.getUsedMemory();
    double fraction = Math.min(1, (currentlyUsed + (10 << 20)) / (double) MemoryAlertSystem.getMaximumMemory());
    MemoryAlertSystem.getInstance().setFractionUsageThreshold(fraction);
    try {
        sorter.setMemService(MemoryAlertSystem.getInstance());
        // run again with change settings
        BufferedDataTable result = sorter.sort(m_exec);
        // Check if column is sorted in ascending order
        int prevValue = Integer.MIN_VALUE;
        for (DataRow row : result) {
            int thisValue = ((IntValue) row.getCell(0)).getIntValue();
            Assert.assertTrue(thisValue >= prevValue);
        }
        // Check if it has the same results as defaultResult
        Assert.assertTrue(defaultResult.getRowCount() == result.getRowCount());
        RowIterator defaultIter = defaultResult.iterator();
        RowIterator iter = result.iterator();
        while (defaultIter.hasNext()) {
            DataRow defaultRow = defaultIter.next();
            DataRow row = iter.next();
            Assert.assertTrue(defaultRow.getKey().getString().equals(row.getKey().getString()));
            Iterator<DataCell> defaultCellIter = defaultRow.iterator();
            Iterator<DataCell> cellIter = row.iterator();
            while (defaultCellIter.hasNext()) {
                Assert.assertTrue(defaultCellIter.next().equals(cellIter.next()));
            }
        }
    } finally {
        MemoryAlertSystem.getInstance().setFractionUsageThreshold(MemoryAlertSystem.DEFAULT_USAGE_THRESHOLD);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) IntValue(org.knime.core.data.IntValue)

Aggregations

BufferedDataTable (org.knime.core.node.BufferedDataTable)425 DataTableSpec (org.knime.core.data.DataTableSpec)213 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)148 DataRow (org.knime.core.data.DataRow)118 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)97 PortObject (org.knime.core.node.port.PortObject)96 DataCell (org.knime.core.data.DataCell)85 DataColumnSpec (org.knime.core.data.DataColumnSpec)61 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)60 DefaultRow (org.knime.core.data.def.DefaultRow)56 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)54 RowKey (org.knime.core.data.RowKey)52 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)50 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)47 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)43 IOException (java.io.IOException)41 ExecutionContext (org.knime.core.node.ExecutionContext)40 ArrayList (java.util.ArrayList)33 LinkedHashMap (java.util.LinkedHashMap)31 DoubleValue (org.knime.core.data.DoubleValue)29