Search in sources :

Example 51 with RowIterator

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.");
    }
}
Also used : Random(java.util.Random) RowIterator(org.knime.core.data.RowIterator) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DataRow(org.knime.core.data.DataRow)

Example 52 with RowIterator

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);
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataRow(org.knime.core.data.DataRow)

Example 53 with RowIterator

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.");
    }
}
Also used : Random(java.util.Random) DataPoint(org.knime.base.node.mine.mds.DataPoint) RowIterator(org.knime.core.data.RowIterator) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DataRow(org.knime.core.data.DataRow) DataPoint(org.knime.base.node.mine.mds.DataPoint)

Example 54 with RowIterator

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();
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataRow(org.knime.core.data.DataRow)

Example 55 with RowIterator

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);
            }
        }
    }
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataRow(org.knime.core.data.DataRow)

Aggregations

RowIterator (org.knime.core.data.RowIterator)77 DataRow (org.knime.core.data.DataRow)62 DataCell (org.knime.core.data.DataCell)28 DataTableSpec (org.knime.core.data.DataTableSpec)20 RowKey (org.knime.core.data.RowKey)16 DoubleValue (org.knime.core.data.DoubleValue)14 BufferedDataTable (org.knime.core.node.BufferedDataTable)13 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ArrayList (java.util.ArrayList)9 DefaultRow (org.knime.core.data.def.DefaultRow)8 PreparedStatement (java.sql.PreparedStatement)7 DataType (org.knime.core.data.DataType)6 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)6 HashSet (java.util.HashSet)5 Random (java.util.Random)5 TimeZone (java.util.TimeZone)5 DataTable (org.knime.core.data.DataTable)5 DoubleCell (org.knime.core.data.def.DoubleCell)5 StringCell (org.knime.core.data.def.StringCell)5 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)5