use of org.knime.core.data.RowIterator in project knime-core by knime.
the class MDSManager method init.
/**
* Initializes the lower dimensional data points randomly.
*
* @param seed The random seed to use.
* @throws CanceledExecutionException If execution was canceled by the user.
*/
public void init(final long seed) throws CanceledExecutionException {
m_isInit = true;
Random rand = new Random(seed);
ExecutionMonitor exec = m_exec.createSubProgress(0.1);
// init all data points
RowIterator it = m_inData.iterator();
while (it.hasNext()) {
exec.checkCanceled();
DataRow row = it.next();
DataPoint p = new DataPoint(m_dimension);
for (int j = 0; j < m_dimension; j++) {
p.setElementAt(j, rand.nextDouble());
}
m_points.put(row.getKey(), p);
exec.setProgress("Initialising data points.");
}
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class MDSManager method doEpoch.
private void doEpoch(final int epoch, final ExecutionMonitor exec) throws CanceledExecutionException {
// through all data points
RowIterator it1 = m_inData.iterator();
while (it1.hasNext()) {
DataRow r1 = it1.next();
DataPoint p1 = m_points.get(r1.getKey());
// through all data points again
RowIterator it2 = m_inData.iterator();
while (it2.hasNext()) {
exec.checkCanceled();
DataRow r2 = it2.next();
DataPoint p2 = m_points.get(r2.getKey());
adjustDataPoint(p1, p2, r1, r2);
}
}
adjustLearningRate(epoch);
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class MDSProjectionManager method init.
/**
* Initializes the lower dimensional data points randomly.
*
* @param seed The random seed to use.
* @throws CanceledExecutionException If execution was canceled by the user.
*/
public void init(final long seed) throws CanceledExecutionException {
m_isInit = true;
Random rand = new Random(seed);
ExecutionMonitor exec = m_exec.createSubProgress(0.1);
// init all data points
RowIterator it = m_inData.iterator();
while (it.hasNext()) {
exec.checkCanceled();
DataRow row = it.next();
DataPoint p = new DataPoint(m_dimension);
for (int j = 0; j < m_dimension; j++) {
p.setElementAt(j, rand.nextDouble());
}
m_points.put(row.getKey(), p);
exec.setProgress("Initialising data points.");
}
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class ReadTableNodeModel method execute.
void execute(final ContainerTable table, final RowOutput output, final ExecutionContext exec) throws Exception {
long limit = m_limitCheckerModel.getBooleanValue() ? m_limitSpinnerModel.getIntValue() : Long.MAX_VALUE;
final long rowCount = Math.min(limit, table.size());
long row = 0L;
for (RowIterator it = table.iterator(); it.hasNext() && row < limit; row++) {
final DataRow next = it.next();
final long rowFinal = row;
exec.setProgress(row / (double) rowCount, () -> String.format("Row %,d/%,d (%s)", rowFinal + 1, rowCount, next.getKey()));
exec.checkCanceled();
output.push(next);
}
output.close();
}
use of org.knime.core.data.RowIterator in project knime-core by knime.
the class Smoter method smote.
/**
* Oversample the class <code>name</code> such that <code>count</code>
* new rows are inserted. The <code>kNN</code> nearest neighbors are
* chosen as reference.
*
* @param name the class name
* @param count add this amount of new rows
* @param kNN k nearest neighbor parameter
* @param exec monitor to get canceled status from
* (may be <code>null</code>)
* @throws CanceledExecutionException if execution is canceled
*/
public void smote(final DataCell name, final int count, final int kNN, final ExecutionMonitor exec) throws CanceledExecutionException {
int origCount = getCount(name);
if (origCount < 0) {
throw new IllegalArgumentException("No such value: " + name);
}
// how often each input record is used at least as reference
int countAtLeast = count / origCount;
assert countAtLeast * origCount <= count;
int[] fixedPart = new int[countAtLeast * origCount];
for (int i = 0; i < fixedPart.length; i++) {
fixedPart[i] = i % origCount;
}
int[] shuffleMe = new int[origCount];
for (int i = 0; i < shuffleMe.length; i++) {
shuffleMe[i] = i;
}
// guess from the name what this line does.
shuffleMe = shuffle(shuffleMe);
int[] indexesToUse = new int[count];
System.arraycopy(fixedPart, 0, indexesToUse, 0, fixedPart.length);
// number of cells that have the luck to serve one extra time as
// reference
int lucky = count - fixedPart.length;
System.arraycopy(shuffleMe, 0, indexesToUse, fixedPart.length, lucky);
Arrays.sort(indexesToUse);
// the counter in the input table for this particular class value
int classCounter = -1;
int pointer = 0;
RowIterator it = m_inTable.iterator();
while (pointer < indexesToUse.length) {
checkCanceled(exec);
assert it.hasNext();
DataRow next = it.next();
if (!next.getCell(m_targetCol).equals(name)) {
continue;
}
classCounter++;
if (indexesToUse[pointer] == classCounter) {
DataRow[] neighbors = determineNeighbors(next, kNN, exec);
while (pointer < indexesToUse.length && indexesToUse[pointer] == classCounter) {
DataRow newRow = populate(next, neighbors);
m_container.addRowToTable(newRow);
pointer++;
exec.setProgress(pointer / (double) count);
}
}
}
}
Aggregations