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;
}
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;
}
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()]));
}
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");
}
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() };
}
Aggregations