use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class MissingValuePanel method getSettings.
/**
* Get the settings currently entered in the dialog.
*
* @return the current settings
*/
public ColSetting getSettings() {
int method;
if (m_nothingButton.isSelected()) {
method = ColSetting.METHOD_NO_HANDLING;
} else if (m_removeButton.isSelected()) {
method = ColSetting.METHOD_IGNORE_ROWS;
} else if (m_fixButton != null && m_fixButton.isSelected()) {
method = ColSetting.METHOD_FIX_VAL;
DataCell cell;
switch(m_setting.getType()) {
case ColSetting.TYPE_INT:
Object value = ((JFormattedTextField) m_fixText).getValue();
cell = new IntCell(((Number) value).intValue());
break;
case ColSetting.TYPE_DOUBLE:
value = ((JFormattedTextField) m_fixText).getValue();
cell = new DoubleCell(((Number) value).doubleValue());
break;
case ColSetting.TYPE_STRING:
value = ((JComboBox) m_fixText).getEditor().getItem();
cell = new StringCell(value.toString());
break;
default:
throw new RuntimeException("You shouldn't have come here.");
}
m_setting.setFixCell(cell);
} else if (m_maxButton != null && m_maxButton.isSelected()) {
method = ColSetting.METHOD_MAX;
} else if (m_minButton != null && m_minButton.isSelected()) {
method = ColSetting.METHOD_MIN;
} else if (m_meanButton != null && m_meanButton.isSelected()) {
method = ColSetting.METHOD_MEAN;
} else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
method = ColSetting.METHOD_MOST_FREQUENT;
} else {
assert false : "One button must be selected.";
method = ColSetting.METHOD_NO_HANDLING;
}
m_setting.setMethod(method);
return m_setting;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class BatchExecutor method setNodeOptions.
private static void setNodeOptions(final Collection<Option> options, final WorkflowManager wfm) throws InvalidSettingsException, IllegalOptionException {
for (Option o : options) {
int[] idPath = o.m_nodeIDs;
NodeID subID = new NodeID(wfm.getID(), idPath[0]);
NodeContainer cont = null;
try {
cont = wfm.getNodeContainer(subID);
for (int i = 1; i < idPath.length; i++) {
if (cont instanceof WorkflowManager) {
WorkflowManager subWM = (WorkflowManager) cont;
subID = new NodeID(subID, idPath[i]);
cont = subWM.getNodeContainer(subID);
} else {
cont = null;
}
}
} catch (IllegalArgumentException ex) {
// throw by getNodeContainer if no node with the id exists
cont = null;
}
if (cont == null) {
LOGGER.warn("No node with id " + Arrays.toString(idPath) + " found.");
} else {
WorkflowManager parent = cont.getParent();
NodeSettings settings = new NodeSettings("something");
parent.saveNodeSettings(cont.getID(), settings);
NodeSettings model = settings.getNodeSettings(Node.CFG_MODEL);
String[] splitName = o.m_name.split("/");
String name = splitName[splitName.length - 1];
String[] pathElements = new String[splitName.length - 1];
System.arraycopy(splitName, 0, pathElements, 0, pathElements.length);
for (String s : pathElements) {
model = model.getNodeSettings(s);
}
if ("int".equals(o.m_type)) {
model.addInt(name, Integer.parseInt(o.m_value));
} else if ("long".equals(o.m_type)) {
model.addLong(name, Long.parseLong(o.m_value));
} else if ("short".equals(o.m_type)) {
model.addShort(name, Short.parseShort(o.m_value));
} else if ("byte".equals(o.m_type)) {
model.addByte(name, Byte.parseByte(o.m_value));
} else if ("boolean".equals(o.m_type)) {
model.addBoolean(name, Boolean.parseBoolean(o.m_value));
} else if ("char".equals(o.m_type)) {
model.addChar(name, o.m_value.charAt(0));
} else if ("float".equals(o.m_type) || ("double".equals(o.m_type))) {
model.addDouble(name, Double.parseDouble(o.m_value));
} else if ("String".equals(o.m_type)) {
model.addString(name, o.m_value);
} else if ("StringCell".equals(o.m_type)) {
model.addDataCell(name, new StringCell(o.m_value));
} else if ("DoubleCell".equals(o.m_type)) {
double d = Double.parseDouble(o.m_value);
model.addDataCell(name, new DoubleCell(d));
} else if ("IntCell".equals(o.m_type)) {
int i = Integer.parseInt(o.m_value);
model.addDataCell(name, new IntCell(i));
} else if ("LongCell".equals(o.m_type)) {
long i = Long.parseLong(o.m_value);
model.addDataCell(name, new LongCell(i));
} else {
throw new IllegalOptionException("Unknown option type for " + o.m_name + ": " + o.m_type);
}
parent.loadNodeSettings(cont.getID(), settings);
}
}
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class BootstrapNodeModel method sampleChunk.
/**
* Puts samples, for the chunk of rows, in the bootstrap container and unused ones in the holdout container.
*
* @param iterator Iterator over a set of rows. Must at least have chunkSize rows left
* @param chunkSize The number of rows that will be processed
* @param numberOfSamples The number of samples that should be generated
* @param bootstrap The container for the bootstrap samples
* @param holdout The container for the unused samples
* @param random A random for selection of rows
* @param progress A progress object that will be incremented for each processed row
* @throws CanceledExecutionException If execution has been canceled
*/
private void sampleChunk(final CloseableRowIterator iterator, final int chunkSize, final int numberOfSamples, final BufferedDataContainer bootstrap, final BufferedDataContainer holdout, final Random random, final Progress progress) throws CanceledExecutionException {
// Array holding the amount of copies that will go into the bootstrap samples for each row
int[] sampled = new int[chunkSize];
// Init all with 0
for (int i = 0; i < sampled.length; i++) {
sampled[i] = 0;
}
// Increment randomly until amount of samples has been selected
for (int i = 0; i < numberOfSamples; i++) {
sampled[random.nextInt(sampled.length)]++;
}
// Iterate through as many rows as this chunk is big
for (int i = 0; i < chunkSize; i++) {
DataRow row = iterator.next();
// Check if row will go into the bootstrap or holdout table
if (sampled[i] == 0) {
// Add the unchanged row to the holdout table
holdout.addRowToTable(row);
} else {
// Add the row to the bootstrap table as many times as it has been selected
for (int j = 0; j < sampled[i]; j++) {
DataRow newRow;
if (m_configuration.getAppendOccurrences() || m_configuration.getAppendOriginalRowId()) {
int appendedColumns = 0;
if (m_configuration.getAppendOccurrences()) {
appendedColumns++;
}
if (m_configuration.getAppendOriginalRowId()) {
appendedColumns++;
}
// Add occurrences column to the row
DataCell[] cells = new DataCell[row.getNumCells() + appendedColumns];
int k;
for (k = 0; k < row.getNumCells(); k++) {
cells[k] = row.getCell(k);
}
if (m_configuration.getAppendOccurrences()) {
cells[k++] = new IntCell(sampled[i]);
}
if (m_configuration.getAppendOriginalRowId()) {
cells[k++] = new StringCell(row.getKey().toString());
}
newRow = new DefaultRow(row.getKey() + m_configuration.getRowIdSeparator() + j, cells);
} else {
// Only change the row ID of the original row
newRow = new DefaultRow(row.getKey() + m_configuration.getRowIdSeparator() + j, row);
}
// Add row to the bootstrap table
bootstrap.addRowToTable(newRow);
}
}
// Update progress
progress.increment();
}
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class AverageInterpolationStatisticMB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(m_colIdx);
if (cell.isMissing()) {
m_numMissing++;
} else {
DataCell res;
if (m_previous.isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round((prev + next) / 2);
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) m_previous).getDoubleValue();
double next = val.getDoubleValue();
double lin = (prev + next) / 2;
if (m_previous instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (m_previous instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
for (int i = 0; i < m_numMissing; i++) {
m_values.add(res);
}
m_previous = cell;
m_numMissing = 0;
}
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class SubsetMatcherNodeModel method createRunnable.
private Runnable createRunnable(final ExecutionMonitor exec, final long noOfSets, final DataCell setIDCell, final CollectionDataValue setCell, final boolean appendSetCol, final Comparator<DataCell> comparator, final SubsetMatcher[] sortedMatcher, final int maxMismatches) {
return new Runnable() {
@Override
public void run() {
try {
// check cancel prior updating the global counter!!!
exec.checkCanceled();
final long transCounter = m_setCounter.incrementAndGet();
exec.setMessage(setIDCell.toString() + " (" + transCounter + " of " + noOfSets + ")");
if (setCell.size() < 1) {
// skip empty collections
exec.setProgress(transCounter / (double) noOfSets);
m_skipCounter.incrementAndGet();
return;
}
final DataCell[] sortedItems = collectionCell2SortedArray(setCell, comparator);
// try to match the sorted transaction items and the sorted
// matcher until all items or all matchers are processed
int matcherStartIdx = 0;
int itemIdx = 0;
final Collection<SetMissmatches> matchingSets = new LinkedList<>();
while (itemIdx < sortedItems.length && matcherStartIdx < sortedMatcher.length) {
final DataCell subItem = sortedItems[itemIdx];
// match the current item with all remaining matchers
for (int i = matcherStartIdx; i < sortedMatcher.length; i++) {
final SubsetMatcher matcher = sortedMatcher[i];
final int result = matcher.compare(subItem);
if (result > 0 && maxMismatches == 0) {
// the next item
break;
}
// this matcher matches the item (result == 0)
// or
// the item is bigger than the matcher
// since we may allow for mismatches we have to
// check if subsequent matchers of the matcher
// match the current item
matcher.match(sortedItems, itemIdx, matchingSets, new LinkedList<DataCell>(), new MismatchCounter(maxMismatches));
matcherStartIdx++;
}
// go to the next index
itemIdx++;
}
if (matchingSets.size() < 1) {
exec.setProgress(transCounter / (double) noOfSets);
m_skipCounter.incrementAndGet();
return;
}
for (final SetMissmatches matchingSet : matchingSets) {
exec.checkCanceled();
// create for each matching subset a result row
final List<DataCell> cells = new LinkedList<>();
cells.add(setIDCell);
if (appendSetCol) {
cells.add((DataCell) setCell);
}
// the subset column
cells.add(matchingSet.getSet());
if (maxMismatches > 0) {
// append the mismatch counter if mismatches allowed
cells.add(new IntCell(matchingSet.getMismatchCounter()));
}
final RowKey rowKey = RowKey.createRowKey(m_rowId.getAndIncrement());
final DefaultRow row = new DefaultRow(rowKey, cells);
synchronized (m_dc) {
exec.checkCanceled();
m_dc.addRowToTable(row);
}
}
exec.setProgress(transCounter / (double) noOfSets);
} catch (final CanceledExecutionException e) {
// ignore this just exit the run method
} catch (final Exception e) {
LOGGER.error("Exception while matching sub sets: " + e.getMessage());
}
}
};
}
Aggregations