use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.
the class PolyRegLearnerNodeModel method getCellFactory.
private CellFactory getCellFactory(final int dependentIndex) {
final int degree = m_settings.getDegree();
return new CellFactory() {
@Override
public DataCell[] getCells(final DataRow row) {
double sum = m_betas[0];
int betaCount = 1;
double y = 0;
for (int col = 0; col < row.getNumCells(); col++) {
if ((col != dependentIndex) && m_colSelected[col]) {
final double value = ((DoubleValue) row.getCell(col)).getDoubleValue();
double poly = 1;
for (int d = 1; d <= degree; d++) {
poly *= value;
sum += m_betas[betaCount++] * poly;
}
} else if (col == dependentIndex) {
y = ((DoubleValue) row.getCell(col)).getDoubleValue();
}
}
double err = Math.abs(sum - y);
m_squaredError += err * err;
return new DataCell[] { new DoubleCell(sum), new DoubleCell(err) };
}
@Override
public DataColumnSpec[] getColumnSpecs() {
DataColumnSpecCreator crea = new DataColumnSpecCreator("PolyReg prediction", DoubleCell.TYPE);
DataColumnSpec col1 = crea.createSpec();
crea = new DataColumnSpecCreator("Prediction Error", DoubleCell.TYPE);
DataColumnSpec col2 = crea.createSpec();
return new DataColumnSpec[] { col1, col2 };
}
@Override
public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor execMon) {
// do nothing
}
};
}
use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.
the class MissingValueHandling3Table method createMissingValueHandlingTable.
/**
* Does missing value handling to the argument table given the col settings in an array and also reports progress.
*
* @param table the table to do missing value handling on
* @param colSettings the settings
* @param exec for progress/cancel and to create the buffered data table
* @param warningBuffer To which potential warning messages are added.
* @return a cache table, cleaned up
* @throws CanceledExecutionException if canceled
* @since 2.10
*/
public static BufferedDataTable createMissingValueHandlingTable(final BufferedDataTable table, final MissingValueHandling2ColSetting[] colSettings, final ExecutionContext exec, final StringBuilder warningBuffer) throws CanceledExecutionException {
MissingValueHandling2ColSetting[] colSetting;
try {
colSetting = getColSetting(table.getDataTableSpec(), colSettings, false, warningBuffer);
} catch (InvalidSettingsException ise) {
LOGGER.coding("getColSetting method is not supposed to throw an exception, ignoring settings", ise);
DataTableSpec s = table.getDataTableSpec();
colSetting = new MissingValueHandling2ColSetting[s.getNumColumns()];
for (int i = 0; i < s.getNumColumns(); i++) {
colSetting[i] = new MissingValueHandling2ColSetting(s.getColumnSpec(i));
colSetting[i].setMethod(MissingValueHandling2ColSetting.METHOD_NO_HANDLING);
}
}
boolean needStatistics = false;
final Set<Integer> mostFrequentColumns = new HashSet<Integer>();
for (int i = 0; i < colSetting.length; i++) {
MissingValueHandling2ColSetting c = colSetting[i];
switch(c.getMethod()) {
case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
mostFrequentColumns.add(i);
case MissingValueHandling2ColSetting.METHOD_MAX:
case MissingValueHandling2ColSetting.METHOD_MIN:
case MissingValueHandling2ColSetting.METHOD_MEAN:
needStatistics = true;
break;
default:
}
}
MyStatisticsTable myT;
ExecutionMonitor e;
if (needStatistics) {
// for creating statistics table
ExecutionContext subExec = exec.createSubExecutionContext(0.5);
myT = new MyStatisticsTable(table, subExec) {
// do not try to get this Iterable in the constructor, it will not work, as long as
// Statistics3Table does the statistical computation in the constructor.
@Override
protected Iterable<Integer> getMostFrequentColumns() {
return mostFrequentColumns;
}
};
if (myT.m_warningMessage != null) {
if (warningBuffer.length() > 0) {
warningBuffer.append('\n');
}
warningBuffer.append(myT.m_warningMessage);
}
// for the iterator
e = exec.createSubProgress(0.5);
} else {
myT = null;
e = exec;
}
MissingValueHandling3Table mvht = new MissingValueHandling3Table(table, myT, colSetting);
BufferedDataContainer container = exec.createDataContainer(mvht.getDataTableSpec());
e.setMessage("Adding rows...");
int count = 0;
try {
MissingValueHandling3TableIterator it = new MissingValueHandling3TableIterator(mvht, e);
while (it.hasNext()) {
DataRow next;
next = it.next();
e.setMessage("Adding row " + (count + 1) + " (\"" + next.getKey() + "\")");
container.addRowToTable(next);
count++;
}
} catch (MissingValueHandling3TableIterator.RuntimeCanceledExecutionException rcee) {
throw rcee.getCause();
} finally {
container.close();
}
return container.getTable();
}
use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.
the class DatabasePortObject method getDataTable.
/**
* @return underlying data
*/
private DataTable getDataTable(final int cacheNoRows) {
try {
DatabaseQueryConnectionSettings connSettings = getConnectionSettings(m_credentials);
DBReader load = connSettings.getUtility().getReader(connSettings);
return load.getTable(new ExecutionMonitor(), m_credentials, false, cacheNoRows);
} catch (Throwable t) {
LOGGER.error("Could not fetch data from database, reason: " + t.getMessage(), t);
return null;
}
}
use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.
the class AbstractTableSorter method sortInMemory.
private DataTable sortInMemory(final ExecutionMonitor exec) throws CanceledExecutionException {
final DataTable dataTable = m_inputTable;
List<DataRow> rowList = new ArrayList<DataRow>();
int progress = 0;
final long rowCount = m_rowsInInputTable;
exec.setMessage("Reading data");
ExecutionMonitor readExec = exec.createSubProgress(0.5);
for (final DataRow r : dataTable) {
readExec.checkCanceled();
if (rowCount > 0) {
readExec.setProgress(progress / (double) rowCount, r.getKey().getString());
} else {
readExec.setMessage(r.getKey() + " (row " + progress + ")");
}
rowList.add(r);
progress++;
}
// "rowCount" as it might not be set)
if (rowList.size() <= 1) {
return m_inputTable;
}
exec.setMessage("Sorting");
Collections.sort(rowList, m_rowComparator);
exec.setMessage("Creating sorted table");
final DataContainer dc = createDataContainer(dataTable.getDataTableSpec(), false);
ExecutionMonitor writeExec = exec.createSubProgress(0.5);
progress = 0;
for (DataRow r : rowList) {
exec.checkCanceled();
if (rowCount > 0) {
writeExec.setProgress(progress / (double) rowCount, r.getKey().getString());
} else {
writeExec.setMessage(r.getKey() + " (row " + progress + ")");
}
dc.addRowToTable(r);
progress++;
}
dc.close();
return dc.getTable();
}
use of org.knime.core.node.ExecutionMonitor in project knime-core by knime.
the class SandboxedNodeCreator method copyIntoSandboxContainerRecursive.
/**
* @param sourceWFM
* @param targetWFM
* @param wfmResult
* @param progressMon
* @param copyDataIntoNewContext
* @throws CanceledExecutionException
* @throws IOException
*/
private static void copyIntoSandboxContainerRecursive(final WorkflowManager sourceWFM, final WorkflowManager targetWFM, final WorkflowExecutionResult wfmResult, final ExecutionMonitor progressMon, final boolean copyDataIntoNewContext) throws CanceledExecutionException, IOException {
assert wfmResult.getBaseID().equals(sourceWFM.getID());
Map<NodeID, NodeContainerExecutionResult> resultMap = wfmResult.getExecutionResultMap();
for (Map.Entry<NodeID, NodeContainerExecutionResult> e : resultMap.entrySet()) {
ExecutionMonitor sub = progressMon.createSubProgress(1.0 / resultMap.size());
NodeID sourceID = e.getKey();
NodeContainerExecutionResult r = e.getValue();
NodeID targetID = new NodeID(targetWFM.getID(), sourceID.getIndex());
NodeContainer nextTarget = targetWFM.getNodeContainer(targetID);
NodeContainer nextSource = sourceWFM.getNodeContainer(sourceID);
progressMon.setMessage(nextSource.getNameWithID());
copyExistingTablesIntoSandboxContainer(r, nextSource, nextTarget, sub, copyDataIntoNewContext);
sub.setProgress(1.0);
}
}
Aggregations