use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class DendrogramPlotter method createViewModelFor.
/**
* Recursive method to convert the result of the hierachical clustering
* result represented by a
* {@link org.knime.base.node.viz.plotter.dendrogram.DendrogramNode} into a
* {@link org.knime.base.node.viz.plotter.dendrogram.BinaryTree} of
* {@link org.knime.base.node.viz.plotter.dendrogram.DendrogramPoint}s.
*
* @param node the node to convert
* @return the visual model of the passed
* {@link org.knime.base.node.viz.plotter.dendrogram.DendrogramNode}
*/
private BinaryTreeNode<DendrogramPoint> createViewModelFor(final DendrogramNode node) {
if (getXAxis() == null || getXAxis().getCoordinate() == null || getYAxis() == null || getYAxis().getCoordinate() == null) {
updatePaintModel();
}
BinaryTreeNode<DendrogramPoint> viewNode;
// distinction between cluster node and leaf:
int y = getMappedYValue(new DoubleCell(node.getDist()));
int x;
DendrogramPoint p;
if (!node.isLeaf()) {
x = getXPosition(node);
p = new DendrogramPoint(new Point(x, y), node.getDist());
} else {
DataRow row = node.getLeafDataPoint();
x = getMappedXValue(new StringCell(row.getKey().getString()));
p = new DendrogramPoint(new Point(x, y), node.getDist());
DataTableSpec spec = getDataProvider().getDataArray(1).getDataTableSpec();
p.setColor(spec.getRowColor(row));
p.setShape(spec.getRowShape(row));
p.setRelativeSize(spec.getRowSizeFactor(row));
p.setHilite(delegateIsHiLit(row.getKey()));
}
viewNode = new BinaryTreeNode<DendrogramPoint>(p);
Set<RowKey> keys = new LinkedHashSet<RowKey>();
getRowKeys(node, keys);
viewNode.getContent().addRows(keys);
viewNode.getContent().setSelected(m_selected.contains(viewNode.getContent()));
viewNode.getContent().setHilite(delegateIsHiLit(keys));
if (node.getFirstSubnode() != null) {
BinaryTreeNode<DendrogramPoint> leftNode = createViewModelFor(node.getFirstSubnode());
leftNode.setParent(viewNode);
viewNode.setLeftChild(leftNode);
}
if (node.getSecondSubnode() != null) {
BinaryTreeNode<DendrogramPoint> rightNode = createViewModelFor(node.getSecondSubnode());
rightNode.setParent(viewNode);
viewNode.setRightChild(rightNode);
}
return viewNode;
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class DataTableDomainCreatorTest method testBoundsDouble.
/**
* Check whether upper and lower bounds are computed correctly for double column (including infinity and NaN).
*/
@Test
public void testBoundsDouble() {
DataColumnSpecCreator colSpecCrea = new DataColumnSpecCreator("Double col", DoubleCell.TYPE);
DataTableSpec tableSpec = new DataTableSpec(colSpecCrea.createSpec());
RowKey rowKey = new RowKey("Row0");
DataTableDomainCreator domainCreator = new DataTableDomainCreator(tableSpec, false);
// initially bounds are null
DataColumnDomain colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is(nullValue()));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is(nullValue()));
// NaN values are ignored completely
domainCreator.updateDomain(new DefaultRow(rowKey, Double.NaN));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is(nullValue()));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is(nullValue()));
// missing cells are also ignored
domainCreator.updateDomain(new DefaultRow(rowKey, DataType.getMissingCell()));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is(nullValue()));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is(nullValue()));
// change lower and upper bound
domainCreator.updateDomain(new DefaultRow(rowKey, 0.0));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(0)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(0)));
// change upper bound
domainCreator.updateDomain(new DefaultRow(rowKey, 1.0));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(0)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(1)));
// change lower bound
domainCreator.updateDomain(new DefaultRow(rowKey, -1.0));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(-1)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(1)));
// ignore NaN (again)
domainCreator.updateDomain(new DefaultRow(rowKey, Double.NaN));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(-1)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(1)));
// ignore missing values (again)
domainCreator.updateDomain(new DefaultRow(rowKey, DataType.getMissingCell()));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(-1)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(1)));
// change lower bound to -Inf
domainCreator.updateDomain(new DefaultRow(rowKey, Double.NEGATIVE_INFINITY));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(Double.NEGATIVE_INFINITY)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(1)));
// change upper bound to +Inf
domainCreator.updateDomain(new DefaultRow(rowKey, Double.POSITIVE_INFINITY));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new DoubleCell(Double.NEGATIVE_INFINITY)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new DoubleCell(Double.POSITIVE_INFINITY)));
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class DataContainerTest method generateRows.
private static RowIterator generateRows(final int count) {
return new RowIterator() {
private int m_index = 0;
@Override
public DataRow next() {
DefaultRow r = new DefaultRow(RowKey.createRowKey(m_index), new StringCell("String " + m_index), new IntCell(m_index), new DoubleCell(m_index));
m_index++;
return r;
}
@Override
public boolean hasNext() {
return m_index < count;
}
};
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class DataContainerTest method testIncompatibleTypes.
/**
* method being tested: addRowToTable().
*/
public final void testIncompatibleTypes() {
String[] colNames = new String[] { "Column 1", "Column 2" };
DataType[] colTypes = new DataType[] { StringCell.TYPE, IntCell.TYPE };
DataTableSpec spec1 = new DataTableSpec(colNames, colTypes);
DataContainer c = new DataContainer(spec1);
RowKey r1Key = new RowKey("row 1");
DataCell r1Cell1 = new StringCell("Row 1, Cell 1");
DataCell r1Cell2 = new IntCell(12);
DataRow r1 = new DefaultRow(r1Key, new DataCell[] { r1Cell1, r1Cell2 });
RowKey r2Key = new RowKey("row 2");
DataCell r2Cell1 = new StringCell("Row 2, Cell 1");
DataCell r2Cell2 = new IntCell(22);
DataRow r2 = new DefaultRow(r2Key, new DataCell[] { r2Cell1, r2Cell2 });
RowKey r3Key = new RowKey("row 3");
DataCell r3Cell1 = new StringCell("Row 3, Cell 1");
DataCell r3Cell2 = new IntCell(32);
DataRow r3 = new DefaultRow(r3Key, new DataCell[] { r3Cell1, r3Cell2 });
c.addRowToTable(r1);
c.addRowToTable(r2);
c.addRowToTable(r3);
// add incompatible types
RowKey r4Key = new RowKey("row 4");
DataCell r4Cell1 = new StringCell("Row 4, Cell 1");
// not allowed
DataCell r4Cell2 = new DoubleCell(42.0);
DataRow r4 = new DefaultRow(r4Key, new DataCell[] { r4Cell1, r4Cell2 });
try {
c.addRowToTable(r4);
c.close();
fail("Expected " + DataContainerException.class + " not thrown");
} catch (DataContainerException e) {
if (!(e.getCause() instanceof IllegalArgumentException)) {
throw e;
} else {
NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getCause().getClass(), e.getCause());
}
} catch (IllegalArgumentException e) {
NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass(), e);
}
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class JavaToDataCellConversionTest method testToDoubleCell.
/**
* Test Double -> DoubleCell conversion.
*
* @throws Exception When something went wrong
*/
@Test
public void testToDoubleCell() throws Exception {
final DoubleCell cell = testSimpleConversion(Double.class, DoubleCell.TYPE, DoubleCell.class, new Double(Math.PI));
assertEquals(Math.PI, cell.getDoubleValue(), FUZZY_DOUBLE_TOLERANCE);
}
Aggregations