Search in sources :

Example 11 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 cells values
 * and the number cells of the given row with a given offset.
 *
 * @param row row to compute the coefficient of correlation
 * @param cell cell 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 row and cel
 */
public static double getCorrelationDistance(final DataRow row, final SotaTreeCell cell, final double offset, final boolean abs, final boolean fuzzy) {
    int col = 0;
    double dist = 0;
    double meanRow = Distances.getMean(row, fuzzy);
    double meanCell = Distances.getMean(cell);
    double devRow = Distances.getStandardDeviation(row, fuzzy);
    double devCell = Distances.getStandardDeviation(cell);
    if (devRow == 0 || devCell == 0) {
        return (offset - 0);
    }
    int count = 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) {
                dist += (cell.getData()[col].getValue() - meanCell) * (((DoubleValue) row.getCell(i)).getDoubleValue() - meanRow);
                col++;
                count++;
            }
        } else if (SotaUtil.isFuzzyIntervalType(type) && fuzzy) {
            if (col < cell.getData().length) {
                dist += (cell.getData()[col].getValue() - meanCell) * (SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) row.getCell(i)) - meanRow);
                col++;
                count++;
            }
        }
    }
    dist = offset - (dist / (count * devRow * devCell));
    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 12 with FuzzyIntervalValue

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

the class SotaFuzzyMath method getCenterOfAllCoreRegions.

// /**
// * Calculates the distance between the core regions of two
// * FuzzyIntervalCells. If the number of FuzzyIntervalCells of the given
// * DataRows is not equal -1 is returned. To calculate the distance the
// * method computes for each cell of the given cells the center of its core
// * region, this results in two vectors. Than the euclidean distance
// * between these vectors is calculated and returned.
// * @param cells1 The first DataRow which contains FuzzyIntervalCells
// * @param cells2 The second DataRow which contains FuzzyIntervalCells
// * @param spec DataTableSpec of DataRows, to see which cells are
// * FuzzyIntervalCells
// * @return The euclidean distance btwn the core regions of set of cells,
// * if the number of FuzzyIntervalCells is greater than 0.
// * Else -1 is returned.
// */
// public static double getCoreDistance(final DataRow cells1,
// final DataRow cells2, final DataTableSpec spec) {
// double distance = -1;
// 
// // Check is given DataRow have the same length
// // If not return -1;
// if (cells1.getNumCells() != cells2.getNumCells()) {
// return distance;
// }
// 
// double[] centerOfCoreRegionVector1 =
// SotaFuzzyMath.getCenterOfAllCoreRegions(cells1, spec);
// double[] centerOfCoreRegionVector2 =
// SotaFuzzyMath.getCenterOfAllCoreRegions(cells2, spec);
// 
// if (centerOfCoreRegionVector1.length
// == centerOfCoreRegionVector2.length) {
// // Calculate distance between vectors of centers of core regions
// distance = MDSEuclideanAlgorithm.getDistance(
// centerOfCoreRegionVector1, centerOfCoreRegionVector2);
// }
// 
// return distance;
// }
/**
 * Computes the center vector of all core regions of the given FuzzyCells as
 * a double array. If the row contains no FuzzyCell <code>null</code> is
 * returned.
 *
 * @param cells FuzzyCells to compute the center of the core regions
 * @param spec DataTableSpec of rows, to see which cells are
 *            FuzzyIntervalCells
 * @return the vector of the center of all core regions of the given
 *         FuzzyCells as a double array. If row contains no FuzzyCells
 *         <code>null</code> is returned.
 */
public static double[] getCenterOfAllCoreRegions(final DataRow cells, final DataTableSpec spec) {
    int fuzzyCellCount = SotaFuzzyMath.getNumberOfFuzzyCells(cells, spec);
    // If not return null.
    if (fuzzyCellCount <= 0) {
        return null;
    }
    double[] centerOfCoreRegionVector = new double[fuzzyCellCount];
    // Store centers of core regions of each FuzzyIntervalCell
    for (int i = 0; i < cells.getNumCells(); i++) {
        DataType type = spec.getColumnSpec(i).getType();
        if (type.isCompatible(FuzzyIntervalValue.class)) {
            centerOfCoreRegionVector[i] = SotaFuzzyMath.getCenterOfCoreRegion((FuzzyIntervalValue) cells.getCell(i));
        }
    }
    return centerOfCoreRegionVector;
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DataType(org.knime.core.data.DataType)

Example 13 with FuzzyIntervalValue

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

the class SotaFuzzyMath method getCoreDilatationToOtherCore.

/**
 * Computes the core dilatation of a core region to another core region.
 *
 * @param cells1 core region to compute dilataion for
 * @param cells2 core region which indicates the direction
 * @param spec DataTableSpec of row to get information about types of
 *            DataCells
 * @return dilatation of core region of cells1, with respect to the
 *         direction indicated by cells2
 */
public static double getCoreDilatationToOtherCore(final DataRow cells1, final DataRow cells2, final DataTableSpec spec) {
    double dilatation = -1;
    int fuzzyCellCount1 = SotaFuzzyMath.getNumberOfFuzzyCells(cells1, spec);
    int fuzzyCellCount2 = SotaFuzzyMath.getNumberOfFuzzyCells(cells2, spec);
    // If not return -1.
    if (fuzzyCellCount1 != fuzzyCellCount2 && fuzzyCellCount1 <= 0) {
        return dilatation;
    }
    dilatation = 0;
    double alternativeDilatation = 0;
    double[] fuzzyCells1CoreRegion = SotaFuzzyMath.getCenterOfAllCoreRegions(cells1, spec);
    // Through all dimensions
    int currentFuzzyCell = 0;
    for (int d = 0; d < cells1.getNumCells(); d++) {
        DataType type = spec.getColumnSpec(d).getType();
        if (type.isCompatible(FuzzyIntervalValue.class)) {
            FuzzyIntervalValue fuzzyCell1 = (FuzzyIntervalValue) cells1.getCell(d);
            FuzzyIntervalValue fuzzyCell2 = (FuzzyIntervalValue) cells2.getCell(d);
            // Cell1 is left to Cell2
            if (fuzzyCell2.getMinCore() > fuzzyCell1.getMaxCore()) {
                dilatation += Math.pow(Math.abs(fuzzyCells1CoreRegion[currentFuzzyCell] - fuzzyCell1.getMaxCore()), 2);
            } else if (fuzzyCell1.getMinCore() > fuzzyCell2.getMaxCore()) {
                // Cell1 is right to Cell2
                dilatation += Math.pow(Math.abs(fuzzyCells1CoreRegion[currentFuzzyCell] - fuzzyCell1.getMinCore()), 2);
            } else if (fuzzyCell2.getMinCore() <= fuzzyCell1.getMaxCore() && fuzzyCell2.getMinCore() >= fuzzyCell1.getMinCore()) {
                // 
                // / If they overlap in any dimension
                // 
                // Cell1 is left to Cell2 with overlap on the right
                alternativeDilatation += Math.pow(Math.abs(fuzzyCells1CoreRegion[currentFuzzyCell] - fuzzyCell1.getMaxCore()), 2);
            } else if (fuzzyCell1.getMinCore() <= fuzzyCell2.getMaxCore() && fuzzyCell1.getMinCore() >= fuzzyCell2.getMinCore()) {
                // Cell1 is right to Cell2 with overlap on the left
                alternativeDilatation += Math.pow(Math.abs(fuzzyCells1CoreRegion[currentFuzzyCell] - fuzzyCell1.getMinCore()), 2);
            } else if (fuzzyCell2.getMaxCore() > fuzzyCell1.getMaxCore() && fuzzyCell2.getMinCore() < fuzzyCell1.getMinCore()) {
                // Cell1 is in Cell2
                alternativeDilatation += Math.pow(Math.abs(fuzzyCells1CoreRegion[currentFuzzyCell] - fuzzyCell1.getMaxCore()), 2);
            } else if (fuzzyCell1.getMaxCore() > fuzzyCell2.getMaxCore() && fuzzyCell1.getMinCore() < fuzzyCell2.getMinCore()) {
                // Cell2 is in Cell1
                alternativeDilatation += Math.pow(Math.abs(fuzzyCells1CoreRegion[currentFuzzyCell] - fuzzyCell1.getMaxCore()), 2);
            }
            currentFuzzyCell++;
        }
    }
    if (dilatation > 0) {
        return Math.sqrt(dilatation);
    }
    return Math.sqrt(alternativeDilatation);
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DataType(org.knime.core.data.DataType)

Example 14 with FuzzyIntervalValue

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

the class ParallelCoordinatesViewContent method computeDoubleValues.

private void computeDoubleValues(final DataTable data, final Vector<Map<String, Integer>> stringieMap, final ExecutionMonitor exec, final int nrRows) throws CanceledExecutionException {
    // iterate over the rows that are drawable
    int i = 0;
    // iterate over the rows
    int j = 0;
    for (RowIterator it = data.iterator(); (i < nrRows) && it.hasNext(); j++) {
        if (exec != null) {
            exec.checkCanceled();
            // we are doing only half of the job here (but the second half)
            exec.setProgress((j / nrRows / 2.0) + 1.0 / 2.0);
        }
        DataRow row = it.next();
        if (m_rowIsDrawable[j]) {
            m_doubleArray[i] = new TwoDim[m_nrVisibleColumns];
            m_keyVector[i] = row.getKey();
            m_colorVector[i] = m_inputSpec.getRowColor(row);
            m_sizes[i] = data.getDataTableSpec().getRowSize(row);
            for (int col = 0, realCol = 0; col < m_columnCount; col++) {
                if (!m_hideColumn[col]) {
                    m_doubleArray[i][realCol] = new TwoDim();
                    DataCell cell = row.getCell(col);
                    if (cell.getType().isCompatible(DoubleValue.class)) {
                        DoubleValue dcell = (DoubleValue) cell;
                        double dValue = normalize(dcell.getDoubleValue(), m_minVector[realCol], m_maxVector[realCol]);
                        m_doubleArray[i][realCol].setMin(dValue);
                        m_doubleArray[i][realCol].setMax(dValue);
                    } else if (cell.getType().isCompatible(FuzzyIntervalValue.class)) {
                        if (cell.isMissing()) {
                            m_doubleArray[i][realCol].setMin(0);
                            m_doubleArray[i][realCol].setMax(1);
                        } else {
                            FuzzyIntervalValue fcell = (FuzzyIntervalValue) cell;
                            double mincore = fcell.getMinCore();
                            double maxcore = fcell.getMaxCore();
                            m_doubleArray[i][realCol].setMin(normalize(mincore, m_minVector[realCol], m_maxVector[realCol]));
                            m_doubleArray[i][realCol].setMax(normalize(maxcore, m_minVector[realCol], m_maxVector[realCol]));
                        }
                    } else {
                        // if the column is a string one
                        // no. corresponding to the string value
                        int intValue = 0;
                        double dValue = 0;
                        intValue = ((stringieMap.get(realCol).get(cell.toString().trim()))).intValue();
                        dValue = (double) intValue / (stringieMap.get(realCol).size() - 1);
                        m_doubleArray[i][realCol].setMin(dValue);
                        m_doubleArray[i][realCol].setMax(dValue);
                        m_doubleArray[i][realCol].setStringReference(intValue);
                    }
                    realCol++;
                } else {
                // column is hidden
                // do nothing
                }
            }
            i++;
        }
    }
}
Also used : FuzzyIntervalValue(org.knime.core.data.FuzzyIntervalValue) DoubleValue(org.knime.core.data.DoubleValue) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

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