Search in sources :

Example 31 with DataCell

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

the class PairedTTestStatistics method getTTestTable.

/**
 * Get the test result of the t-test.
 * @param exec the execution context
 * @return the t-test results
 */
public BufferedDataTable getTTestTable(final ExecutionContext exec) {
    DataTableSpec outSpec = getTableSpec();
    BufferedDataContainer cont = exec.createDataContainer(outSpec);
    int r = 0;
    for (List<DataCell> cells : getTTestCells()) {
        cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
        r++;
    }
    cont.close();
    BufferedDataTable outTable = cont.getTable();
    return outTable;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 32 with DataCell

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

the class PairedTTestStatistics method getDescStatsTable.

/**
 * Get descriptive statistics
 * @param exec the execution context
 * @return the descriptive statistics for each column of the pair
 */
public BufferedDataTable getDescStatsTable(final ExecutionContext exec) {
    DataTableSpec outSpec = getDescStatsSpec();
    BufferedDataContainer cont = exec.createDataContainer(outSpec);
    int r = 0;
    for (List<DataCell> cells : getDescStatsCells()) {
        cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
        r++;
    }
    cont.close();
    BufferedDataTable outTable = cont.getTable();
    return outTable;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 33 with DataCell

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

the class NewToOldTimeNodeModel method createStreamableOperator.

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

        @Override
        public StreamableOperatorInternals saveInternals() {
            return null;
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final RowInput in = (RowInput) inputs[0];
            final RowOutput out = (RowOutput) outputs[0];
            final DataTableSpec inSpec = in.getDataTableSpec();
            String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
            final int[] includeIndeces = Arrays.stream(includeList).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
            DataRow row;
            while ((row = in.poll()) != null) {
                exec.checkCanceled();
                DataCell[] datacells = new DataCell[includeIndeces.length];
                for (int i = 0; i < includeIndeces.length; i++) {
                    if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
                        final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], DateAndTimeCell.TYPE);
                        final ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
                        datacells[i] = cellFac.getCells(row)[0];
                    } else {
                        final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), DateAndTimeCell.TYPE);
                        final ConvertTimeCellFactory cellFac = new ConvertTimeCellFactory(dataColSpec, includeIndeces[i]);
                        datacells[i] = cellFac.getCells(row)[0];
                    }
                }
                if (m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE)) {
                    out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
                } else {
                    out.push(new AppendedColumnRow(row, datacells));
                }
            }
            in.close();
            out.close();
        }
    };
}
Also used : Arrays(java.util.Arrays) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ZonedDateTime(java.time.ZonedDateTime) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) LocalDateTime(java.time.LocalDateTime) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow) LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) ExecutionContext(org.knime.core.node.ExecutionContext) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) PortInput(org.knime.core.node.streamable.PortInput) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) RowInput(org.knime.core.node.streamable.RowInput) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) IOException(java.io.IOException) SettingsModelColumnFilter2(org.knime.core.node.defaultnodesettings.SettingsModelColumnFilter2) OutputPortRole(org.knime.core.node.streamable.OutputPortRole) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) NodeModel(org.knime.core.node.NodeModel) 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) BufferedDataTable(org.knime.core.node.BufferedDataTable) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) InputPortRole(org.knime.core.node.streamable.InputPortRole) LocalDate(java.time.LocalDate) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) RowOutput(org.knime.core.node.streamable.RowOutput) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) RowInput(org.knime.core.node.streamable.RowInput) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) DataRow(org.knime.core.data.DataRow) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) ReplacedColumnsDataRow(org.knime.base.data.replace.ReplacedColumnsDataRow) AppendedColumnRow(org.knime.core.data.append.AppendedColumnRow)

Example 34 with DataCell

use of org.knime.core.data.DataCell 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 35 with DataCell

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

the class TwoSampleTTestStatistics method getGroupStatistics.

/**
 * Get descriptive statistics for the given Group.
 * @param group the group
 * @return the
 */
public List<DataCell> getGroupStatistics(final Group group) {
    List<DataCell> cells = new ArrayList<DataCell>();
    cells.add(new StringCell(m_column));
    cells.add(new StringCell(m_groups.get(group)));
    SummaryStatistics stats = m_gstats.get(group);
    cells.add(new IntCell((int) stats.getN()));
    cells.add(new IntCell(m_missing.get(group).intValue()));
    cells.add(new IntCell(m_missingGroup.intValue()));
    cells.add(new IntCell(m_ignoredGroup.intValue()));
    cells.add(new DoubleCell(stats.getMean()));
    cells.add(new DoubleCell(stats.getStandardDeviation()));
    cells.add(new DoubleCell(StatsUtil.getStandardError(stats)));
    return cells;
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) IntCell(org.knime.core.data.def.IntCell)

Aggregations

DataCell (org.knime.core.data.DataCell)780 DataRow (org.knime.core.data.DataRow)268 DataTableSpec (org.knime.core.data.DataTableSpec)175 DataColumnSpec (org.knime.core.data.DataColumnSpec)170 DefaultRow (org.knime.core.data.def.DefaultRow)169 ArrayList (java.util.ArrayList)141 StringCell (org.knime.core.data.def.StringCell)131 DoubleCell (org.knime.core.data.def.DoubleCell)129 DoubleValue (org.knime.core.data.DoubleValue)111 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)109 DataType (org.knime.core.data.DataType)97 RowKey (org.knime.core.data.RowKey)94 BufferedDataTable (org.knime.core.node.BufferedDataTable)93 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)91 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)84 LinkedHashMap (java.util.LinkedHashMap)81 IntCell (org.knime.core.data.def.IntCell)79 HashMap (java.util.HashMap)60 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)56