Search in sources :

Example 6 with FuzzyIntervalValue

use of org.knime.core.data.FuzzyIntervalValue in project knime-core by knime.

the class Rule2DDrawingPane method paintSupportArea.

private synchronized void paintSupportArea(final Graphics2D g2, final DataRow currRow, final Color currColor) {
    FuzzyIntervalValue column1 = (FuzzyIntervalValue) currRow.getCell(0);
    FuzzyIntervalValue column2 = (FuzzyIntervalValue) currRow.getCell(1);
    int a1 = (int) (column1.getMinSupport());
    int b1 = (int) (column1.getMinCore());
    int c1 = (int) (column1.getMaxCore());
    int d1 = (int) (column1.getMaxSupport());
    int a2 = (int) (column2.getMinSupport());
    int b2 = (int) (column2.getMinCore());
    int c2 = (int) (column2.getMaxCore());
    int d2 = (int) (column2.getMaxSupport());
    int center1 = b1 + ((c1 - b1) / 2);
    int center2 = b2 + ((c2 - b2) / 2);
    Color brightColor = new Color(currColor.getRed(), currColor.getGreen(), currColor.getBlue(), BRIGHT_SUPPORT_ALPHA);
    Color darkColor = new Color(currColor.getRed(), currColor.getGreen(), currColor.getBlue(), DARK_SUPPORT_ALPHA);
    GradientPaint quad1Color = new GradientPaint(center1, a2, brightColor, center1, b2, darkColor);
    GradientPaint quad2Color = new GradientPaint(d1, center2, brightColor, c1, center2, darkColor);
    GradientPaint quad3Color = new GradientPaint(center1, d2, brightColor, center1, c2, darkColor);
    GradientPaint quad4Color = new GradientPaint(a1, center2, brightColor, b1, center2, darkColor);
    int[] northX = { a1, b1, c1, d1 };
    int[] northY = { a2, b2, b2, a2 };
    Polygon north = new Polygon(northX, northY, NR_OF_POLYGON_POINTS);
    int[] eastX = { d1, c1, c1, d1 };
    int[] eastY = { a2, b2, c2, d2 };
    Polygon east = new Polygon(eastX, eastY, NR_OF_POLYGON_POINTS);
    int[] southX = { a1, b1, c1, d1 };
    int[] southY = { d2, c2, c2, d2 };
    Polygon south = new Polygon(southX, southY, NR_OF_POLYGON_POINTS);
    int[] westX = { a1, b1, b1, a1 };
    int[] westY = { a2, b2, c2, d2 };
    Polygon west = new Polygon(westX, westY, NR_OF_POLYGON_POINTS);
    // draw support
    g2.setPaint(quad1Color);
    g2.fill(north);
    g2.setPaint(quad2Color);
    g2.fill(east);
    g2.setPaint(quad3Color);
    g2.fill(south);
    g2.setPaint(quad4Color);
    g2.fill(west);
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) Polygon(java.awt.Polygon) Point(java.awt.Point) GradientPaint(java.awt.GradientPaint)

Example 7 with FuzzyIntervalValue

use of org.knime.core.data.FuzzyIntervalValue in project knime-core by knime.

the class Rule2DDrawingPane method paintRules.

private synchronized void paintRules(final Graphics g) {
    if (m_normRules == null || !m_normRules.iterator().hasNext()) {
        return;
    }
    m_coreRegions = new HashMap<RowKey, Rectangle>();
    Graphics2D g2 = (Graphics2D) g;
    RowIterator orgItr = m_orgData.iterator();
    for (Iterator<DataRow> it = m_normRules.iterator(); it.hasNext(); ) {
        DataRow row = it.next();
        DataRow orgRow = orgItr.next();
        // or if rule is hilited
        if (!m_hideUnhilitedRules || m_hiLiteHandler.isHiLit(row.getKey())) {
            // check whether the rule is selected or hilited
            boolean selected = m_selectedRules.contains(row.getKey());
            boolean hilite = false;
            if (m_hiLiteHandler != null) {
                hilite = m_hiLiteHandler.isHiLit(row.getKey());
            }
            Color currColor = m_orgData.getDataTableSpec().getRowColor(orgRow).getColor(selected, hilite);
            FuzzyIntervalValue x = (FuzzyIntervalValue) row.getCell(0);
            FuzzyIntervalValue y = (FuzzyIntervalValue) row.getCell(1);
            // fuzzy rule
            if (x.getMinSupport() != x.getMinCore() || x.getMaxCore() != x.getMaxSupport() || y.getMinSupport() != y.getMinCore() || y.getMaxCore() != y.getMaxSupport()) {
                paintSupportArea(g2, row, currColor);
            }
            paintCoreArea(g2, row, currColor);
        }
    // end is unhiliting?
    }
// end for
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) RowKey(org.knime.core.data.RowKey) RowIterator(org.knime.core.data.RowIterator) Color(java.awt.Color) Rectangle(java.awt.Rectangle) DataRow(org.knime.core.data.DataRow) Graphics2D(java.awt.Graphics2D)

Example 8 with FuzzyIntervalValue

use of org.knime.core.data.FuzzyIntervalValue in project knime-core by knime.

the class Rule2DDrawingPane method paintCoreArea.

private synchronized void paintCoreArea(final Graphics2D g2, final DataRow currRow, final Color currColor) {
    FuzzyIntervalValue column1 = (FuzzyIntervalValue) currRow.getCell(0);
    FuzzyIntervalValue column2 = (FuzzyIntervalValue) currRow.getCell(1);
    int a1 = (int) (column1.getMinSupport());
    int b1 = (int) (column1.getMinCore());
    int c1 = (int) (column1.getMaxCore());
    int d1 = (int) (column1.getMaxSupport());
    int a2 = (int) (column2.getMinSupport());
    int b2 = (int) (column2.getMinCore());
    int c2 = (int) (column2.getMaxCore());
    int d2 = (int) (column2.getMaxSupport());
    g2.setPaint(new Color(currColor.getRed(), currColor.getGreen(), currColor.getBlue(), CORE_ALPHA));
    // draw core:
    Rectangle core = new Rectangle(b1, b2, c1 - b1, c2 - b2);
    g2.fill(core);
    m_coreRegions.put(currRow.getKey(), core);
    // draw lines
    g2.setColor(Color.BLACK);
    g2.drawLine(a1, a2, b1, b2);
    g2.drawLine(d1, a2, c1, b2);
    g2.drawLine(d1, d2, c1, c2);
    g2.drawLine(a1, d2, b1, c2);
    // bounding boxes
    // outer
    g2.drawRect(a1, a2, (d1 - a1), (d2 - a2));
    // inner
    g2.drawRect(b1, b2, c1 - b1, c2 - b2);
// draw vertical orientation lines
/*
         * g2.drawLine(a1, 0, a1, getHeight()); g2.drawLine(b1, 0, b1,
         * getHeight()); g2.drawLine(c1, 0, c1, getHeight()); g2.drawLine(d1, 0,
         * d1, getHeight());
         *
         * //draw horizontal orientation lines g2.drawLine(0, a2, getWidth(),
         * a2); g2.drawLine(0, b2, getWidth(), b2); g2.drawLine(0, c2,
         * getWidth(), c2); g2.drawLine(0, d2, getWidth(), d2);
         */
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Point(java.awt.Point) GradientPaint(java.awt.GradientPaint)

Example 9 with FuzzyIntervalValue

use of org.knime.core.data.FuzzyIntervalValue in project knime-core by knime.

the class Distances method getMinkowskiDistance.

/**
 * Calculates the Minkowski distance between two rows. If fuzzy is set true
 * only columns with cells containing numbers are used to compute the
 * distance. The given power specifies the distance kind, i.e. if power
 * is set to 2 the Euclidean distance will be computed.
 *
 * @param power The power to use.
 * @param row1 The first row
 * @param row2 The second row
 * @param fuzzy If true only fuzzy data is taken into account, if
 * <code>false</code> only number data.
 *
 * @return Minkowski distance between the two rows.
 */
public static double getMinkowskiDistance(final int power, final DataRow row1, final DataRow row2, final boolean fuzzy) {
    double distance = 0;
    for (int i = 0; i < row1.getNumCells(); i++) {
        DataType type1 = row1.getCell(i).getType();
        DataType type2 = row2.getCell(i).getType();
        if (row1.getCell(i).isMissing() || row2.getCell(i).isMissing()) {
            continue;
        }
        if (SotaUtil.isNumberType(type1) && SotaUtil.isNumberType(type2) && !fuzzy) {
            distance += Math.pow(Math.abs(((DoubleValue) row1.getCell(i)).getDoubleValue() - ((DoubleValue) row2.getCell(i)).getDoubleValue()), power);
        } else if (SotaUtil.isFuzzyIntervalType(type1) && SotaUtil.isFuzzyIntervalType(type2) && fuzzy) {
            distance += Math.pow(Math.abs(SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)) - SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i))), power);
        }
    }
    return Math.pow(distance, (double) 1 / (double) power);
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType) DataPoint(org.knime.base.node.mine.mds.DataPoint)

Example 10 with FuzzyIntervalValue

use of org.knime.core.data.FuzzyIntervalValue in project knime-core by knime.

the class Distances method getMinkowskiDistance.

/**
 * Calculates the Minkowski distance between two rows. If fuzzy is set true
 * only columns with cells containing numbers are used to compute the
 * distance. The given power specifies the distance kind, i.e. if power
 * is set to 2 the euclidean distance will be computed.
 *
 * @param power The power to use.
 * @param row1 The first row
 * @param row2 The second row
 * @param fuzzy If true only fuzzy data is taken into account, if
 * <code>false</code> only number data.
 *
 * @return Minkowski distance between the two rows.
 */
public static double getMinkowskiDistance(final int power, final DataRow row1, final DataRow row2, final boolean fuzzy) {
    double distance = 0;
    for (int i = 0; i < row1.getNumCells(); i++) {
        DataType type1 = row1.getCell(i).getType();
        DataType type2 = row2.getCell(i).getType();
        if (SotaUtil.isNumberType(type1) && SotaUtil.isNumberType(type2) && !fuzzy) {
            distance += Math.pow((((DoubleValue) row1.getCell(i)).getDoubleValue() - ((DoubleValue) row2.getCell(i)).getDoubleValue()), power);
        } else if (SotaUtil.isFuzzyIntervalType(type1) && SotaUtil.isFuzzyIntervalType(type2) && fuzzy) {
            distance += Math.pow((SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)) - SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i))), power);
        }
    }
    return Math.pow(distance, (double) 1 / (double) power);
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType)

Aggregations

FuzzyIntervalValue (org.knime.core.data.FuzzyIntervalValue)14 DataType (org.knime.core.data.DataType)10 DoubleValue (org.knime.core.data.DoubleValue)9 Color (java.awt.Color)3 GradientPaint (java.awt.GradientPaint)2 Point (java.awt.Point)2 Rectangle (java.awt.Rectangle)2 DataPoint (org.knime.base.node.mine.mds.DataPoint)2 DataRow (org.knime.core.data.DataRow)2 RowIterator (org.knime.core.data.RowIterator)2 Graphics2D (java.awt.Graphics2D)1 Polygon (java.awt.Polygon)1 DataCell (org.knime.core.data.DataCell)1 RowKey (org.knime.core.data.RowKey)1