use of org.knime.core.node.NodeSettingsWO in project knime-core by knime.
the class Sampler method createRandomNumberRowFilter.
/*
* Creates random number row filter that samples count rows from a table
* with overall allCount rows.
*/
private static final IRowFilter createRandomNumberRowFilter(final long count, final long allCount, final Random rand) {
Random random = rand != null ? rand : new Random();
if (allCount <= count) {
return new TrueRowFilter();
}
if (allCount <= Integer.MAX_VALUE) {
BitSet bitset = new BitSet((int) allCount);
// hm, I'm sure there is a better way to draw arbitrary bits
int[] vals = new int[(int) allCount];
for (int i = 0; i < vals.length; i++) {
vals[i] = i;
}
for (int i = vals.length; --i >= 0; ) {
int swapIndex = random.nextInt(i + 1);
int swap = vals[swapIndex];
vals[swapIndex] = vals[i];
vals[i] = swap;
}
for (int i = 0; i < count; i++) {
bitset.set(vals[i]);
}
return new RandomNumberRowFilter(bitset);
} else {
// Sampling based on Fan's selection rejection algorithm (1962)
return new AbstractRowFilter() {
private long m_i;
@Override
public boolean matches(final DataRow row, final long rowIndex) throws EndOfTableException, IncludeFromNowOn {
double p = (count - m_i) / (double) (allCount - rowIndex + 1);
if (random.nextDouble() <= p) {
m_i++;
return true;
}
return false;
}
@Override
protected void saveSettings(final NodeSettingsWO cfg) {
throw new UnsupportedOperationException();
}
@Override
public void loadSettingsFrom(final NodeSettingsRO cfg) throws InvalidSettingsException {
throw new UnsupportedOperationException();
}
@Override
public DataTableSpec configure(final DataTableSpec inSpec) throws InvalidSettingsException {
throw new UnsupportedOperationException();
}
};
}
}
use of org.knime.core.node.NodeSettingsWO in project knime-core by knime.
the class AutoHiLiteNodeFactory method createNodeModel.
/**
* {@inheritDoc}
*/
@Override
public NodeModel createNodeModel() {
return new NodeModel(1, 1) {
private SettingsModelBoolean m_smClearHiLites = createClearHilitesModel();
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
return inSpecs;
}
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
if (m_smClearHiLites.getBooleanValue()) {
getInHiLiteHandler(0).fireClearHiLiteEvent();
}
final Set<RowKey> keys = new HashSet<RowKey>();
final HiLiteHandler hlh = getInHiLiteHandler(0);
long counter = 0;
long numOfRows = inData[0].size();
for (final DataRow row : inData[0]) {
keys.add(row.getKey());
if (keys.size() == NUMBER_OF_ROWS_HILITED_AT_ONCE) {
exec.setProgress(++counter * NUMBER_OF_ROWS_HILITED_AT_ONCE / (double) numOfRows, "HiLiting all rows...");
hlh.fireHiLiteEvent(keys);
keys.clear();
}
}
hlh.fireHiLiteEvent(keys);
// wait for hilite to propagate
ViewUtils.invokeAndWaitInEDT(() -> {
});
return inData;
}
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
}
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
}
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) {
m_smClearHiLites.saveSettingsTo(settings);
}
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
m_smClearHiLites.validateSettings(settings);
}
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
m_smClearHiLites.loadSettingsFrom(settings);
}
@Override
protected void reset() {
// no op
}
};
}
use of org.knime.core.node.NodeSettingsWO in project knime-core by knime.
the class AccuracyScorerNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
NodeSettings set = new NodeSettings("scorer");
set.addInt("correctCount", m_viewData.getCorrectCount());
set.addInt("falseCount", m_viewData.getFalseCount());
set.addInt("nrRows", m_viewData.getNrRows());
set.addStringArray("values", m_viewData.getTargetValues());
final int targetValueCount = m_viewData.getTargetValues().length;
for (int i = 0; i < targetValueCount; i++) {
NodeSettingsWO sub = set.addNodeSettings(m_viewData.getTargetValues()[i]);
sub.addIntArray("scorerCount", m_viewData.getScorerCount()[i]);
NodeSettingsWO subSub = sub.addNodeSettings("hilightMap");
for (int j = 0; j < targetValueCount; j++) {
NodeSettingsWO sub3 = subSub.addNodeSettings(m_viewData.getTargetValues()[j]);
RowKey[] rowKeys = m_viewData.getKeyStore()[i][j].toArray(new RowKey[m_viewData.getKeyStore()[i][j].size()]);
sub3.addRowKeyArray("keyStore", rowKeys);
}
}
set.saveToXML(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(new File(internDir, "internals.xml.gz")))));
}
use of org.knime.core.node.NodeSettingsWO in project knime-core by knime.
the class EntropyCalculator method save.
/**
* Saves the structure of this objec to the target directory.
*
* @param dir to save to
* @param exec for progress/cancel
* @throws IOException if that fails
* @throws CanceledExecutionException if canceled
*/
public void save(final File dir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
File scorerFile = new File(dir, FILE_SCORER_TABLE);
DataContainer.writeToZip(m_scoreTable, scorerFile, exec);
File settingsFile = new File(dir, FILE_SETTINGS);
NodeSettings config = new NodeSettings(CFG_SETTINGS);
config.addDouble(CFG_ENTROPY, m_entropy);
config.addDouble(CFG_QUALITY, m_quality);
config.addInt(CFG_PAT_IN_CLUSTER, m_patternsInClusters);
config.addInt(CFG_PAT_IN_REFERENCE, m_patternsInReference);
config.addInt(CFG_NR_CLUSTER, m_nrClusters);
config.addInt(CFG_NR_REFERENCES, m_nrReference);
NodeSettingsWO subConfig = config.addNodeSettings(CFG_CLUSTERING_MAP);
for (Map.Entry<RowKey, Set<RowKey>> entry : m_clusteringMap.entrySet()) {
exec.checkCanceled();
RowKey key = entry.getKey();
Set<RowKey> values = entry.getValue();
NodeSettingsWO keySettings = subConfig.addNodeSettings(key.toString());
keySettings.addRowKey(key.toString(), key);
keySettings.addRowKeyArray(CFG_MAPPED_KEYS, values.toArray(new RowKey[values.size()]));
}
config.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(settingsFile))));
}
use of org.knime.core.node.NodeSettingsWO in project knime-core by knime.
the class AddEmptyRowsConfig method saveSettingsTo.
/**
* Saves current configuration.
*
* @param settings To save to.
*/
void saveSettingsTo(final NodeSettingsWO settings) {
settings.addBoolean("atLeastMode", m_atLeastMode);
settings.addInt("rowCount", m_rowCount);
settings.addString("newRowKeyPrefix", m_newRowKeyPrefix);
NodeSettingsWO doubleSet = settings.addNodeSettings("double");
doubleSet.addBoolean("useMissing", m_useMissingDouble);
doubleSet.addDouble("fillValue", m_fillValueDouble);
NodeSettingsWO intSet = settings.addNodeSettings("int");
intSet.addBoolean("useMissing", m_useMissingInt);
intSet.addInt("fillValue", m_fillValueInt);
NodeSettingsWO stringSet = settings.addNodeSettings("String");
stringSet.addBoolean("useMissing", m_useMissingString);
stringSet.addString("fillValue", m_fillValueString);
}
Aggregations