use of org.knime.core.data.def.FuzzyIntervalCell in project knime-core by knime.
the class Rule2DPlotter method updatePaintModel.
/**
* {@inheritDoc}
*/
@Override
protected void updatePaintModel() {
super.updatePaintModel();
if (m_rules != null) {
Rule2DDrawingPane drawingPane = getDrawingPane();
drawingPane.setOriginalRuleTable(m_rules);
String xName = getXColName();
String yName = getYColName();
int xIdx = -1;
int yIdx = -1;
if (xName != null && yName != null) {
xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
}
if (xIdx >= 0 && yIdx >= 0) {
Coordinate x = getColHeader().getCoordinate();
Coordinate y = getRowHeader().getCoordinate();
// check if the coordinates are valid
if (x == null || y == null) {
return;
}
// calculate the coordinates of the rules here
// List<DataRow> rows = new ArrayList<DataRow>();
DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col1 = creator.createSpec();
creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col2 = creator.createSpec();
DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
DataContainer rows = new DataContainer(spec);
for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
DataRow currRow = itr.next();
DataCell[] newCells = new DataCell[2];
for (int cell = 0; cell < currRow.getNumCells(); cell++) {
// if (!m_rules.getDataTableSpec().getColumnSpec(cell)
// .getType().isCompatible(
// FuzzyIntervalValue.class)) {
// continue;
// }
Rectangle rect = calculateDrawingRectangle();
double a;
double b;
double c;
double d;
if (cell == xIdx) {
if (currRow.getCell(cell).isMissing()) {
// normalize xValues
a = getXmin();
b = getXmin();
c = getXmax();
d = getXmax();
} else {
// normalize xValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
newCells[0] = newInterval;
}
if (cell == yIdx) {
if (currRow.getCell(cell).isMissing()) {
a = getYmin();
b = getYmin();
c = getYmax();
d = getYmax();
} else {
// normalize yValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
newCells[1] = newInterval;
}
}
// create new row out of the normalized cells
rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
}
rows.close();
drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
}
super.updatePaintModel();
}
}
use of org.knime.core.data.def.FuzzyIntervalCell in project knime-core by knime.
the class NodeSettingsTest method testDataCell.
/**
* Test write/read of DataCells.
*
* @throws Exception Should not happen.
*/
@Test
public void testDataCell() throws Exception {
StringCell s = new StringCell("stringi");
m_settings.addDataCell("string", s);
assertTrue(m_settings.containsKey("string"));
assertTrue(m_settings.getDataCell("string").equals(s));
DoubleCell d = new DoubleCell(45.42);
m_settings.addDataCell("double", d);
assertTrue(m_settings.containsKey("double"));
assertTrue(m_settings.getDataCell("double").equals(d));
IntCell i = new IntCell(11);
m_settings.addDataCell("int", i);
assertTrue(m_settings.containsKey("int"));
assertTrue(m_settings.getDataCell("int").equals(i));
DataCell m = DataType.getMissingCell();
m_settings.addDataCell("missing", m);
assertTrue(m_settings.containsKey("missing"));
assertTrue(m_settings.getDataCell("missing").equals(m));
ComplexNumberCell c = new ComplexNumberCell(5.4, 4.5);
m_settings.addDataCell("complex", c);
assertTrue(m_settings.containsKey("complex"));
assertTrue(m_settings.getDataCell("complex").equals(c));
FuzzyNumberCell n = new FuzzyNumberCell(1, 2, 4);
m_settings.addDataCell("fnumber", n);
assertTrue(m_settings.containsKey("fnumber"));
assertTrue(m_settings.getDataCell("fnumber").equals(n));
FuzzyIntervalCell f = new FuzzyIntervalCell(1, 2, 3, 4);
m_settings.addDataCell("finterval", f);
assertTrue(m_settings.containsKey("finterval"));
assertTrue(m_settings.getDataCell("finterval").equals(f));
DataCell unknownCell = new UnknownCell();
m_settings.addDataCell("unknownCell", unknownCell);
assertTrue(m_settings.containsKey("unknownCell"));
assertTrue(m_settings.getDataCell("unknownCell").equals(unknownCell));
}
Aggregations