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);
}
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
}
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);
*/
}
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);
}
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);
}
Aggregations