use of org.knime.core.data.DataTable in project knime-core by knime.
the class RankCorrelationComputeNodeView method modelChanged.
/**
* {@inheritDoc}
*/
@Override
protected void modelChanged() {
DataTable table = getNodeModel().getCorrelationTable();
TableContentModel cntModel = m_tableView.getContentModel();
cntModel.setDataTable(table);
changeRenderer(m_currentRendererID);
// must not call this on cntView as that would not affect the
// row header column
m_tableView.setRowHeight(16);
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class NodeOutputView method createPartControl.
/**
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
// Toolbar
IToolBarManager toolbarMGR = getViewSite().getActionBars().getToolBarManager();
// create button for stick with branch.
final RetargetAction lockAction = new RetargetAction("StayOnBranch", "Pin view to new node added to branch", IAction.AS_CHECK_BOX);
lockAction.setImageDescriptor(ImageDescriptor.createFromFile(this.getClass(), "icons/lock.png"));
lockAction.setChecked(m_branchLocked);
lockAction.setEnabled(m_pinned);
lockAction.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (lockAction.isChecked()) {
m_branchLocked = true;
m_selectionWhenLocked = m_lastSelection;
} else {
m_branchLocked = false;
selectionChanged(null, m_lastSelectionWhilePinned);
}
}
});
toolbarMGR.add(lockAction);
// create button which allows to "pin" selection:
m_pinButton = new RetargetAction("PinView", "Pin view to selected node", IAction.AS_CHECK_BOX);
m_pinButton.setImageDescriptor(ImageDescriptor.createFromFile(this.getClass(), "icons/pin.png"));
m_pinButton.setChecked(m_pinned);
m_pinButton.setEnabled(true);
m_pinButton.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (m_pinButton.isChecked()) {
m_pinned = true;
m_lastSelectionWhilePinned = m_lastSelection;
lockAction.setEnabled(true);
} else {
m_pinned = false;
selectionChanged(null, m_lastSelectionWhilePinned);
lockAction.setEnabled(false);
}
}
});
toolbarMGR.add(m_pinButton);
toolbarMGR.add(new Separator());
// configure drop down menu
IMenuManager dropDownMenu = getViewSite().getActionBars().getMenuManager();
// drop down menu entry for outport table:
final RetargetAction menuentrytable = new RetargetAction("OutputTable", "Show Output Table", IAction.AS_RADIO_BUTTON);
menuentrytable.setChecked(DISPLAYOPTIONS.TABLE.equals(m_choice));
menuentrytable.setEnabled(true);
menuentrytable.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentrytable.isChecked()) {
m_choice = DISPLAYOPTIONS.TABLE;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentrytable);
// drop down menu entry for node variables:
final RetargetAction dropdownmenuvars = new RetargetAction("NodeVariables", "Show Variables", IAction.AS_RADIO_BUTTON);
dropdownmenuvars.setChecked(DISPLAYOPTIONS.VARS.equals(m_choice));
dropdownmenuvars.setEnabled(true);
dropdownmenuvars.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (dropdownmenuvars.isChecked()) {
m_choice = DISPLAYOPTIONS.VARS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(dropdownmenuvars);
// drop down menu entry for configuration/settings:
final RetargetAction menuentrysettings = new RetargetAction("NodeConf", "Show Configuration", IAction.AS_RADIO_BUTTON);
menuentrysettings.setChecked(DISPLAYOPTIONS.SETTINGS.equals(m_choice));
menuentrysettings.setEnabled(true);
menuentrysettings.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentrysettings.isChecked()) {
m_choice = DISPLAYOPTIONS.SETTINGS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentrysettings);
// drop down menu entry for configuration/settings:
final RetargetAction menuentryallsettings = new RetargetAction("NodeConfAll", "Show Entire Configuration", IAction.AS_RADIO_BUTTON);
menuentryallsettings.setChecked(DISPLAYOPTIONS.ALLSETTINGS.equals(m_choice));
menuentryallsettings.setEnabled(true);
menuentryallsettings.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentryallsettings.isChecked()) {
m_choice = DISPLAYOPTIONS.ALLSETTINGS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentryallsettings);
// drop down menu entry for node graph annotations
final RetargetAction menuentrygraphannotations = new RetargetAction("NodeGraphAnno", "Show Graph Annotations", IAction.AS_RADIO_BUTTON);
menuentrygraphannotations.setChecked(DISPLAYOPTIONS.GRAPHANNOTATIONS.equals(m_choice));
menuentrygraphannotations.setEnabled(true);
menuentrygraphannotations.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (menuentrygraphannotations.isChecked()) {
m_choice = DISPLAYOPTIONS.GRAPHANNOTATIONS;
updateNodeContainerInfo(m_lastNode);
}
}
});
dropDownMenu.add(menuentrygraphannotations);
// Content
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);
// Node Title:
Label titlelabel = new Label(parent, SWT.NONE);
titlelabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
titlelabel.setText("Node: ");
m_title = new Text(parent, SWT.BORDER);
m_title.setEditable(false);
m_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
m_title.setText("n/a.");
// Panel for currently displayed information (some information
// providers will add more elements to this):
Composite infoPanel = new Composite(parent, SWT.NONE);
GridData infoGrid = new GridData(SWT.FILL, SWT.TOP, true, false);
infoGrid.horizontalSpan = 2;
infoPanel.setLayoutData(infoGrid);
GridLayoutFactory.swtDefaults().numColumns(3).applyTo(infoPanel);
m_info = new Label(infoPanel, SWT.NONE);
m_info.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
m_info.setText("n/a. ");
m_portIndex = new ComboViewer(infoPanel);
m_portIndex.add(new String[] { "port 0", "port 1", "port 2" });
m_portIndex.getCombo().setEnabled(false);
m_portIndex.getCombo().setSelection(new Point(m_portIndexInit, m_portIndexInit));
m_portIndex.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
ISelection sel = event.getSelection();
try {
int newIndex = Integer.parseInt(sel.toString().substring(5).replace(']', ' ').trim());
NodeContainer node;
if (m_workflow.containsNodeContainer(m_lastNode)) {
node = m_workflow.getNodeContainer(m_lastNode);
updateDataTable(node, newIndex);
}
} catch (NumberFormatException nfe) {
// ignore.
}
}
});
// Table:
// stack panel switches between KNIME data table view and SWT table for other info
m_stackPanel = new Composite(parent, SWT.NONE);
m_stackPanel.setLayout(new StackLayout());
GridData tableGrid = new GridData(SWT.FILL, SWT.FILL, true, true);
m_stackPanel.setLayoutData(tableGrid);
// DataTable view wrapped in AWT-SWT bridge
m_tableView = new TableView();
m_tableViewPanel = new Panel2CompositeWrapper(m_stackPanel, m_tableView, SWT.NONE);
m_errorLabel = new Label(m_stackPanel, SWT.NONE);
// SWT Table for the other info
m_table = new Table(m_stackPanel, SWT.MULTI | SWT.BORDER);
m_table.setLinesVisible(true);
m_table.setHeaderVisible(true);
tableGrid.horizontalSpan = 2;
m_table.setLayoutData(tableGrid);
String[] titles = { "Name", "Value" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText(titles[i]);
}
for (int i = 0; i < titles.length; i++) {
m_table.getColumn(i).pack();
}
m_lastNode = null;
getViewSite().getPage().addSelectionListener(this);
if (m_choice.equals(DISPLAYOPTIONS.TABLE)) {
((StackLayout) m_stackPanel.getLayout()).topControl = m_tableViewPanel;
m_stackPanel.layout();
} else {
((StackLayout) m_stackPanel.getLayout()).topControl = m_table;
m_stackPanel.layout();
}
m_stackPanel.layout();
selectionChanged(null, m_lastSelection);
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class PMCCNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable in = (BufferedDataTable) inData[0];
// floating point operation
final double rC = in.getRowCount();
int[] includes = getIncludes(in.getDataTableSpec());
String[] includeNames = m_columnIncludesList.getIncludeList().toArray(new String[0]);
double progNormalize = 0.3;
double progDetermine = 0.65;
double progFinish = 1.0 - progNormalize - progDetermine;
exec.setMessage("Normalizing data");
final ExecutionMonitor normProg = exec.createSubProgress(progNormalize);
FilterColumnTable filterTable = new FilterColumnTable(in, includes);
final int l = includes.length;
int nomCount = (l - 1) * l / 2;
final HalfDoubleMatrix nominatorMatrix = new HalfDoubleMatrix(includes.length, /*withDiagonal*/
false);
nominatorMatrix.fill(Double.NaN);
@SuppressWarnings("unchecked") final LinkedHashMap<DataCell, Integer>[] possibleValues = new LinkedHashMap[l];
DataTableSpec filterTableSpec = filterTable.getDataTableSpec();
for (int i = 0; i < l; i++) {
DataColumnSpec cs = filterTableSpec.getColumnSpec(i);
if (cs.getType().isCompatible(NominalValue.class)) {
possibleValues[i] = new LinkedHashMap<DataCell, Integer>();
}
}
final int possValueUpperBound = m_maxPossValueCountModel.getIntValue();
// determines possible values. We can't use those from the domain
// as the domain can also contain values not present in the data
// but in the contingency table we need rows/columns to have at least
// one cell with a value >= 1
StatisticsTable statTable = new StatisticsTable(filterTable) {
// that is sort of the constructor in this derived class
{
calculateAllMoments(in.getRowCount(), normProg);
}
@Override
protected void calculateMomentInSubClass(final DataRow row) {
for (int i = 0; i < l; i++) {
if (possibleValues[i] != null) {
DataCell c = row.getCell(i);
// note: also take missing value as possible value
possibleValues[i].put(c, null);
if (possibleValues[i].size() > possValueUpperBound) {
possibleValues[i] = null;
}
}
}
}
};
for (LinkedHashMap<DataCell, Integer> map : possibleValues) {
if (map != null) {
int index = 0;
for (Map.Entry<DataCell, Integer> entry : map.entrySet()) {
entry.setValue(index++);
}
}
}
// stores all pair-wise contingency tables,
// contingencyTables[i] == null <--> either column of the corresponding
// pair is non-categorical.
// What is a contingency table?
// http://en.wikipedia.org/wiki/Contingency_table
int[][][] contingencyTables = new int[nomCount][][];
// column which only contain one value - no correlation available
LinkedHashSet<String> constantColumns = new LinkedHashSet<String>();
int valIndex = 0;
for (int i = 0; i < l; i++) {
for (int j = i + 1; j < l; j++) {
if (possibleValues[i] != null && possibleValues[j] != null) {
int iSize = possibleValues[i].size();
int jSize = possibleValues[j].size();
contingencyTables[valIndex] = new int[iSize][jSize];
}
DataColumnSpec colSpecI = filterTableSpec.getColumnSpec(i);
DataColumnSpec colSpecJ = filterTableSpec.getColumnSpec(j);
DataType ti = colSpecI.getType();
DataType tj = colSpecJ.getType();
if (ti.isCompatible(DoubleValue.class) && tj.isCompatible(DoubleValue.class)) {
// one of the two columns contains only one value
if (statTable.getVariance(i) < PMCCPortObjectAndSpec.ROUND_ERROR_OK) {
constantColumns.add(colSpecI.getName());
nominatorMatrix.set(i, j, Double.NaN);
} else if (statTable.getVariance(j) < PMCCPortObjectAndSpec.ROUND_ERROR_OK) {
constantColumns.add(colSpecJ.getName());
nominatorMatrix.set(i, j, Double.NaN);
} else {
nominatorMatrix.set(i, j, 0.0);
}
}
valIndex++;
}
}
// to other column (will be a missing value)
if (!constantColumns.isEmpty()) {
String[] constantColumnNames = constantColumns.toArray(new String[constantColumns.size()]);
NodeLogger.getLogger(getClass()).info("The following numeric " + "columns contain only one distinct value or have " + "otherwise a low standard deviation: " + Arrays.toString(constantColumnNames));
int maxLength = 4;
if (constantColumns.size() > maxLength) {
constantColumnNames = Arrays.copyOf(constantColumnNames, maxLength);
constantColumnNames[maxLength - 1] = "...";
}
setWarningMessage("Some columns contain only one distinct value: " + Arrays.toString(constantColumnNames));
}
DataTable att;
if (statTable.getNrRows() > 0) {
att = new Normalizer(statTable, includeNames).doZScoreNorm(// no iteration needed
exec.createSubProgress(0.0));
} else {
att = statTable;
}
normProg.setProgress(1.0);
exec.setMessage("Calculating correlation measure");
ExecutionMonitor detProg = exec.createSubProgress(progDetermine);
int rowIndex = 0;
double[] buf = new double[l];
DataCell[] catBuf = new DataCell[l];
boolean containsMissing = false;
for (DataRow r : att) {
detProg.checkCanceled();
for (int i = 0; i < l; i++) {
catBuf[i] = null;
buf[i] = Double.NaN;
DataCell c = r.getCell(i);
// missing value is also a possible value here
if (possibleValues[i] != null) {
catBuf[i] = c;
} else if (c.isMissing()) {
containsMissing = true;
} else if (filterTableSpec.getColumnSpec(i).getType().isCompatible(DoubleValue.class)) {
buf[i] = ((DoubleValue) c).getDoubleValue();
}
}
valIndex = 0;
for (int i = 0; i < l; i++) {
for (int j = i + 1; j < l; j++) {
double b1 = buf[i];
double b2 = buf[j];
if (!Double.isNaN(b1) && !Double.isNaN(b2)) {
double old = nominatorMatrix.get(i, j);
nominatorMatrix.set(i, j, old + b1 * b2);
} else if (catBuf[i] != null && catBuf[j] != null) {
int iIndex = possibleValues[i].get(catBuf[i]);
assert iIndex >= 0 : "Value unknown in value list " + "of column " + includeNames[i] + ": " + catBuf[i];
int jIndex = possibleValues[j].get(catBuf[j]);
assert jIndex >= 0 : "Value unknown in value list " + "of column " + includeNames[j] + ": " + catBuf[j];
contingencyTables[valIndex][iIndex][jIndex]++;
}
valIndex++;
}
}
rowIndex++;
detProg.setProgress(rowIndex / rC, "Processing row " + rowIndex + " (\"" + r.getKey() + "\")");
}
if (containsMissing) {
setWarningMessage("Some row(s) contained missing values.");
}
detProg.setProgress(1.0);
double normalizer = 1.0 / (rC - 1.0);
valIndex = 0;
for (int i = 0; i < l; i++) {
for (int j = i + 1; j < l; j++) {
if (contingencyTables[valIndex] != null) {
nominatorMatrix.set(i, j, computeCramersV(contingencyTables[valIndex]));
} else if (!Double.isNaN(nominatorMatrix.get(i, j))) {
double old = nominatorMatrix.get(i, j);
nominatorMatrix.set(i, j, old * normalizer);
}
// else pair of columns is double - string (for instance)
valIndex++;
}
}
normProg.setProgress(progDetermine);
PMCCPortObjectAndSpec pmccModel = new PMCCPortObjectAndSpec(includeNames, nominatorMatrix);
ExecutionContext subExec = exec.createSubExecutionContext(progFinish);
BufferedDataTable out = pmccModel.createCorrelationMatrix(subExec);
m_correlationTable = out;
return new PortObject[] { out, pmccModel };
}
use of org.knime.core.data.DataTable in project knime-core by knime.
the class ScorerNodeView method modelChanged.
/**
* Call this function to tell the view that the model has changed.
*
* @see NodeView#modelChanged()
*/
@Override
public void modelChanged() {
ScorerNodeModel model = (ScorerNodeModel) getNodeModel();
/*
* get the new scorer table and compute the numbers we display
*/
DataTable scoreTable = model.getScorerTable();
if (scoreTable == null) {
// model is not executed yet, or was reset.
m_tableView.setDataTable(null);
m_correct.setText(" n/a ");
m_wrong.setText(" n/a ");
m_error.setText(" n/a ");
return;
}
// now set the values in the components to get them displayed
m_tableView.setDataTable(scoreTable);
m_correct.setText(String.valueOf(model.getCorrectCount()));
m_wrong.setText(String.valueOf(model.getFalseCount()));
m_error.setText(String.valueOf(model.getError()));
}
Aggregations