Search in sources :

Example 1 with FuzzyIntervalValue

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

the class Distances method getCosinusDistance.

/**
 * Computes the cosinus distance between the given two rows, with given
 * offset.
 *
 * @param row1 first row to compute the cosinus distance of
 * @param row2 second row to compute the cosinus distance of
 * @param offset offset to substract cosinus distance from
 * @param fuzzy if <code>true</code> only fuzzy data is respected, if
 *            <code>false</code> only number data
 * @return the cosinus distance between the given two rows
 */
public static double getCosinusDistance(final DataRow row1, final DataRow row2, final double offset, final boolean fuzzy) {
    double distance = 0;
    double vectorMultRes = 0;
    double vector1Length = 0;
    double vector2Length = 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) {
            vectorMultRes += ((DoubleValue) row1.getCell(i)).getDoubleValue() * ((DoubleValue) row2.getCell(i)).getDoubleValue();
            vector1Length += Math.pow(((DoubleValue) row1.getCell(i)).getDoubleValue(), 2);
            vector2Length += Math.pow(((DoubleValue) row2.getCell(i)).getDoubleValue(), 2);
        } else if (SotaUtil.isFuzzyIntervalType(type1) && SotaUtil.isFuzzyIntervalType(type2) && fuzzy) {
            vectorMultRes += SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)) * SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i));
            vector1Length += Math.pow(SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)), 2);
            vector2Length += Math.pow(SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i)), 2);
        }
    }
    vector1Length = Math.sqrt(vector1Length);
    vector2Length = Math.sqrt(vector2Length);
    distance = vectorMultRes / (vector1Length * vector2Length);
    distance = offset - distance;
    return distance;
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType)

Example 2 with FuzzyIntervalValue

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

the class Distances method getStandardDeviation.

/**
 * Returns the standard deviation of the given row.
 *
 * @param row the row to compute the standard deviation of.
 * @param fuzzy if <code>true</code> only fuzzy data is respected, if
 *            <code>false</code> only number data
 * @return the standard deviation of the given row
 */
public static double getStandardDeviation(final DataRow row, final boolean fuzzy) {
    double dev = 0;
    int count = 0;
    double mean = Distances.getMean(row, fuzzy);
    for (int i = 0; i < row.getNumCells(); i++) {
        DataType type = row.getCell(i).getType();
        if (SotaUtil.isNumberType(type) && !fuzzy) {
            dev += Math.pow((((DoubleValue) row.getCell(i)).getDoubleValue() - mean), 2);
            count++;
        } else if (SotaUtil.isFuzzyIntervalType(type) && fuzzy) {
            dev += Math.pow((SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row.getCell(i)) - mean), 2);
            count++;
        }
    }
    return Math.sqrt((dev / (count - 1)));
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType)

Example 3 with FuzzyIntervalValue

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

the class Distances method getCorrelationDistance.

/**
 * Returns the coefficient of correlation distance between the rows with a
 * given offset.
 *
 * @param row1 first row to compute the coefficient of correlation
 * @param row2 second rell to compute the coefficient of correlation
 * @param offset offset to substract coefficient of correlation from
 * @param abs flags if correlations distance should be used absolute
 * @param fuzzy if <code>true</code> only fuzzy data is respected, if
 *            <code>false</code> only number data
 * @return the coefficient of correlation between given rows
 */
public static double getCorrelationDistance(final DataRow row1, final DataRow row2, final double offset, final boolean abs, final boolean fuzzy) {
    double dist = 0;
    double meanRow1 = Distances.getMean(row1, fuzzy);
    double meanRow2 = Distances.getMean(row2, fuzzy);
    double devRow1 = Distances.getStandardDeviation(row1, fuzzy);
    double devRow2 = Distances.getStandardDeviation(row2, fuzzy);
    if (devRow1 == 0 || devRow2 == 0) {
        return (offset - 0);
    }
    int count = 0;
    for (int i = 0; i < row1.getNumCells(); i++) {
        DataType type = row1.getCell(i).getType();
        if (SotaUtil.isNumberType(type) && !fuzzy) {
            dist += (((DoubleValue) row1.getCell(i)).getDoubleValue() - meanRow1) * (((DoubleValue) row2.getCell(i)).getDoubleValue() - meanRow2);
            count++;
        } else if (SotaUtil.isFuzzyIntervalType(type) && fuzzy) {
            dist += (SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)) - meanRow1) * (SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i)) - meanRow2);
            count++;
        }
    }
    dist = offset - (dist / (count * devRow1 * devRow2));
    if (abs) {
        dist = Math.abs(dist);
    }
    return dist;
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType)

Example 4 with FuzzyIntervalValue

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

the class Distances method getCosinusDistance.

/**
 * Returns the cosinus distance between the cells values and the number
 * cells of the given row with a given offset.
 *
 * @param row row to compute the cosinus distance of
 * @param cell cell to compute the cosinus distance of
 * @param offset offset to substract cosinus distance from
 * @param fuzzy if <code>true</code> only fuzzy data is respected, if
 *            <code>false</code> only number data
 * @return the cosinus distance between given row and cell
 */
public static double getCosinusDistance(final DataRow row, final SotaTreeCell cell, final double offset, final boolean fuzzy) {
    int col = 0;
    double distance = 0;
    double vectorMultRes = 0;
    double vectorLength = 0;
    double cellLength = 0;
    for (int i = 0; i < row.getNumCells(); i++) {
        DataType type = row.getCell(i).getType();
        if (SotaUtil.isNumberType(type) && !fuzzy) {
            if (col < cell.getData().length) {
                vectorMultRes += cell.getData()[col].getValue() * ((DoubleValue) row.getCell(i)).getDoubleValue();
                vectorLength += Math.pow(((DoubleValue) row.getCell(i)).getDoubleValue(), 2);
                cellLength += Math.pow(cell.getData()[col].getValue(), 2);
                col++;
            }
        } else if (SotaUtil.isFuzzyIntervalType(type) && fuzzy) {
            if (col < cell.getData().length) {
                vectorMultRes += cell.getData()[col].getValue() * SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row.getCell(i));
                vectorLength += Math.pow(SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row.getCell(i)), 2);
                cellLength += Math.pow(cell.getData()[col].getValue(), 2);
                col++;
            }
        }
    }
    vectorLength = Math.sqrt(vectorLength);
    cellLength = Math.sqrt(cellLength);
    distance = vectorMultRes / (vectorLength * cellLength);
    distance = offset - distance;
    return distance;
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) DataType(org.knime.core.data.DataType)

Example 5 with FuzzyIntervalValue

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

the class Distances method getCosinusDistance.

/**
 * Computes the cosinus distance between the given two rows, with given
 * offset.
 *
 * @param row1 first row to compute the cosinus distance of
 * @param row2 second row to compute the cosinus distance of
 * @param offset offset to subtract cosinus distance from
 * @param fuzzy if <code>true</code> only fuzzy data is respected, if
 *            <code>false</code> only number data
 * @return the cosinus distance between the given two rows
 */
public static double getCosinusDistance(final DataRow row1, final DataRow row2, final double offset, final boolean fuzzy) {
    double distance = 0;
    double vectorMultRes = 0;
    double vector1Length = 0;
    double vector2Length = 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) {
            vectorMultRes += ((DoubleValue) row1.getCell(i)).getDoubleValue() * ((DoubleValue) row2.getCell(i)).getDoubleValue();
            vector1Length += Math.pow(((DoubleValue) row1.getCell(i)).getDoubleValue(), 2);
            vector2Length += Math.pow(((DoubleValue) row2.getCell(i)).getDoubleValue(), 2);
        } else if (SotaUtil.isFuzzyIntervalType(type1) && SotaUtil.isFuzzyIntervalType(type2) && fuzzy) {
            vectorMultRes += SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)) * SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i));
            vector1Length += Math.pow(SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row1.getCell(i)), 2);
            vector2Length += Math.pow(SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row2.getCell(i)), 2);
        }
    }
    vector1Length = Math.sqrt(vector1Length);
    vector2Length = Math.sqrt(vector2Length);
    distance = vectorMultRes / (vector1Length * vector2Length);
    if (offset != 0) {
        distance = offset - distance;
    }
    return distance;
}
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)

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