Search in sources :

Example 1 with FuzzyIntervalCell

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();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) Rectangle(java.awt.Rectangle) DataRow(org.knime.core.data.DataRow) FuzzyIntervalCell(org.knime.core.data.def.FuzzyIntervalCell) DataContainer(org.knime.core.data.container.DataContainer) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 2 with FuzzyIntervalCell

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));
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) ComplexNumberCell(org.knime.core.data.def.ComplexNumberCell) DataCell(org.knime.core.data.DataCell) FuzzyNumberCell(org.knime.core.data.def.FuzzyNumberCell) FuzzyIntervalCell(org.knime.core.data.def.FuzzyIntervalCell) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Aggregations

DataCell (org.knime.core.data.DataCell)2 DoubleCell (org.knime.core.data.def.DoubleCell)2 FuzzyIntervalCell (org.knime.core.data.def.FuzzyIntervalCell)2 Rectangle (java.awt.Rectangle)1 Test (org.junit.Test)1 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)1 Coordinate (org.knime.base.util.coordinate.Coordinate)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DataRow (org.knime.core.data.DataRow)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowIterator (org.knime.core.data.RowIterator)1 DataContainer (org.knime.core.data.container.DataContainer)1 ComplexNumberCell (org.knime.core.data.def.ComplexNumberCell)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 FuzzyNumberCell (org.knime.core.data.def.FuzzyNumberCell)1 IntCell (org.knime.core.data.def.IntCell)1 StringCell (org.knime.core.data.def.StringCell)1