Search in sources :

Example 31 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class TwoSampleTTest method execute.

public TwoSampleTTestStatistics[] execute(final BufferedDataTable table, final ExecutionContext exec) throws InvalidSettingsException, CanceledExecutionException {
    DataTableSpec spec = table.getDataTableSpec();
    int groupingIndex = spec.findColumnIndex(m_grouping.getColumn());
    if (groupingIndex == -1) {
        throw new InvalidSettingsException("Grouping column not found.");
    }
    int[] testColumnsIndex = new int[m_testColumns.length];
    for (int i = 0; i < testColumnsIndex.length; i++) {
        testColumnsIndex[i] = spec.findColumnIndex(m_testColumns[i]);
    }
    int testColumnCount = m_testColumns.length;
    TwoSampleTTestStatistics[] result = new TwoSampleTTestStatistics[testColumnCount];
    for (int i = 0; i < testColumnCount; i++) {
        result[i] = new TwoSampleTTestStatistics(m_testColumns[i], m_grouping.getGroupLabels(), m_confidenceIntervalProb);
    }
    final int rowCount = table.getRowCount();
    int rowIndex = 0;
    for (DataRow row : table) {
        exec.checkCanceled();
        exec.setProgress(rowIndex++ / (double) rowCount, rowIndex + "/" + rowCount + " (\"" + row.getKey() + "\")");
        DataCell groupCell = row.getCell(groupingIndex);
        Group group = m_grouping.getGroup(groupCell);
        for (int i = 0; i < testColumnCount; i++) {
            if (group == null) {
                if (groupCell.isMissing()) {
                    result[i].addMissingGroup();
                } else {
                    result[i].addIgnoredGroup();
                }
                continue;
            }
            DataCell cell = row.getCell(testColumnsIndex[i]);
            if (!cell.isMissing()) {
                DoubleValue value = (DoubleValue) cell;
                result[i].addValue(value.getDoubleValue(), group);
            } else {
                result[i].addMissing(group);
            }
        }
    }
    return result;
}
Also used : Group(org.knime.base.node.stats.testing.ttest.Grouping.Group) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 32 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class OldToNewTimeNodeModel method createColumnRearranger.

/**
 * @param inSpec Current input spec
 * @return The CR describing the output, can be null if called by configure
 */
private ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final DataRow row) {
    final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
    final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
    final int[] includeIndexes = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
    final DataColumnSpec[] newColumnSpecs = getNewIncludedColumnSpecs(inSpec, row);
    // if called by configure and automatic type detection is activated, it can be null
    if (newColumnSpecs == null) {
        return null;
    }
    int i = 0;
    for (String includedCol : includeList) {
        if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
            ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(newColumnSpecs[i], i, includeIndexes[i++]);
            rearranger.replace(cellFac, includedCol);
        } else {
            final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(newColumnSpecs[i].getName() + m_suffix.getStringValue(), newColumnSpecs[i].getType());
            ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColSpec, i, includeIndexes[i++]);
            rearranger.append(cellFac);
        }
    }
    return rearranger;
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTimeCellFactory(org.knime.core.data.time.localdatetime.LocalDateTimeCellFactory) DataColumnSpec(org.knime.core.data.DataColumnSpec) LocalTime(java.time.LocalTime) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) NodeModel(org.knime.core.node.NodeModel) LocalDateCell(org.knime.core.data.time.localdate.LocalDateCell) ZoneId(java.time.ZoneId) BufferedDataTable(org.knime.core.node.BufferedDataTable) InputPortRole(org.knime.core.node.streamable.InputPortRole) LocalDate(java.time.LocalDate) Config(org.knime.core.node.config.Config) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) LocalDateTimeCell(org.knime.core.data.time.localdatetime.LocalDateTimeCell) RowOutput(org.knime.core.node.streamable.RowOutput) DataTableSpec(org.knime.core.data.DataTableSpec) ZonedDateTimeCell(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCell) LocalDateTime(java.time.LocalDateTime) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow) ExecutionContext(org.knime.core.node.ExecutionContext) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) ZonedDateTimeCellFactory(org.knime.core.data.time.zoneddatetime.ZonedDateTimeCellFactory) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DateTimeType(org.knime.time.util.DateTimeType) DataCell(org.knime.core.data.DataCell) LocalDateCellFactory(org.knime.core.data.time.localdate.LocalDateCellFactory) LocalTimeCellFactory(org.knime.core.data.time.localtime.LocalTimeCellFactory) RowInput(org.knime.core.node.streamable.RowInput) LocalTimeCell(org.knime.core.data.time.localtime.LocalTimeCell) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) OutputPortRole(org.knime.core.node.streamable.OutputPortRole) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) File(java.io.File) DataRow(org.knime.core.data.DataRow) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PortOutput(org.knime.core.node.streamable.PortOutput) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) TimeUnit(java.util.concurrent.TimeUnit) MissingCell(org.knime.core.data.MissingCell) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataType(org.knime.core.data.DataType) MergeOperator(org.knime.core.node.streamable.MergeOperator) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 33 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class OneWayANOVANodeModel method getGroups.

private List<String> getGroups(final BufferedDataTable inData, final ExecutionMonitor exec) throws InvalidSettingsException, CanceledExecutionException {
    DataTableSpec spec = inData.getSpec();
    int gIndex = spec.findColumnIndex(m_settings.getGroupingColumn());
    LinkedHashSet<String> groups = new LinkedHashSet<String>();
    if (gIndex < 0) {
        throw new InvalidSettingsException("Grouping column not found.");
    }
    final int rowCount = inData.getRowCount();
    int rowIndex = 0;
    for (DataRow row : inData) {
        exec.checkCanceled();
        exec.setProgress(rowIndex++ / (double) rowCount, rowIndex + "/" + rowCount + " (\"" + row.getKey() + "\")");
        DataCell group = row.getCell(gIndex);
        if (!group.isMissing()) {
            groups.add(group.toString());
        }
    }
    return Arrays.asList(groups.toArray(new String[groups.size()]));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 34 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class NodeViewUtil method renderDataTable.

/**
 * Create HTML from the given table using column rowHeader as row headers.
 * @param table the table
 * @param rowHeader the column with row headers
 * @param exclude columns to exclude
 * @param colHeaders override column headers
 * @param buffer append to this buffer
 */
public static void renderDataTable(final BufferedDataTable table, final String rowHeader, final Collection<String> exclude, final Map<String, String> colHeaders, final StringBuilder buffer) {
    int rowHeaderI = table.getDataTableSpec().findColumnIndex(rowHeader);
    Set<Integer> excludeI = new HashSet<Integer>();
    for (String toExclude : exclude) {
        excludeI.add(table.getDataTableSpec().findColumnIndex(toExclude));
    }
    buffer.append("<table>\n");
    buffer.append("<tr>");
    buffer.append("<th class=\"left\"></th>");
    for (DataColumnSpec colSpec : table.getDataTableSpec()) {
        String colName = colSpec.getName();
        if (!exclude.contains(colName)) {
            String value = colHeaders.containsKey(colName) ? colHeaders.get(colName) : colName;
            buffer.append("<th>");
            buffer.append(escapeHtml(value));
            buffer.append("</th>");
        }
    }
    buffer.append("</tr>");
    int r = 0;
    for (Iterator<DataRow> it = table.iteratorFailProve(); it.hasNext(); ) {
        DataRow row = it.next();
        buffer.append("<tr class=\"");
        buffer.append(r % 2 == 0 ? "odd" : "even");
        buffer.append("\">");
        renderDataCell(row.getCell(rowHeaderI), buffer);
        for (int i = 0; i < row.getNumCells(); i++) {
            if (excludeI.contains(i)) {
                continue;
            }
            DataCell cell = row.getCell(i);
            renderDataCell(cell, buffer);
        }
        buffer.append("</tr>");
        r++;
    }
    buffer.append("</table>\n");
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) HashSet(java.util.HashSet)

Example 35 with DataRow

use of org.knime.core.data.DataRow in project knime-core by knime.

the class StandCronbachNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMCCPortObjectAndSpec model = (PMCCPortObjectAndSpec) inData[0];
    HalfDoubleMatrix mat = model.getCorrelationMatrix();
    double sum = 0;
    double count = 0;
    for (int i = 0; i < mat.getRowCount(); i++) {
        for (int j = i + 1; j < mat.getRowCount(); j++) {
            if (Double.isNaN(mat.get(i, j))) {
                throw new IOException("No NAN values supported for the calculation, " + "try using an alternative correlation meassure");
            }
            sum += mat.get(i, j);
            count++;
        }
    }
    double mean = sum / count;
    double cronbach = (mat.getRowCount() * mean) / (1 + (mat.getRowCount() - 1) * mean);
    BufferedDataContainer out = exec.createDataContainer(getDataTableSpec());
    RowKey k = new RowKey("Cronbach");
    DataRow r = new DefaultRow(k, new DoubleCell(cronbach));
    out.addRowToTable(r);
    out.close();
    return new BufferedDataTable[] { out.getTable() };
}
Also used : PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) BufferedDataTable(org.knime.core.node.BufferedDataTable) IOException(java.io.IOException) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Aggregations

DataRow (org.knime.core.data.DataRow)482 DataCell (org.knime.core.data.DataCell)268 DataTableSpec (org.knime.core.data.DataTableSpec)159 BufferedDataTable (org.knime.core.node.BufferedDataTable)125 DataColumnSpec (org.knime.core.data.DataColumnSpec)109 RowKey (org.knime.core.data.RowKey)88 DefaultRow (org.knime.core.data.def.DefaultRow)88 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)80 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)76 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)73 DoubleValue (org.knime.core.data.DoubleValue)72 ArrayList (java.util.ArrayList)65 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)65 RowIterator (org.knime.core.data.RowIterator)62 DataType (org.knime.core.data.DataType)61 DoubleCell (org.knime.core.data.def.DoubleCell)57 StringCell (org.knime.core.data.def.StringCell)53 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)48 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)44 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)43