Search in sources :

Example 1 with DataPoint

use of org.knime.base.node.mine.mds.DataPoint in project knime-core by knime.

the class MDSProjectionManager method doEpoch.

/**
 * Computing one epoch if the iterative mds. In one epoch all points are
 * adjusted according to all fixed points and if <code>projectOnly</code>
 * is set <code>false</code> to all other points too.
 *
 * @param epoch The current epoch.
 * @param exec The execution monitor to show the progress and enable
 * canceling.
 * @throws CanceledExecutionException If the process was canceled.
 */
protected void doEpoch(final int epoch, final ExecutionMonitor exec) throws CanceledExecutionException {
    // through all data points
    RowIterator it1 = m_inData.iterator();
    while (it1.hasNext()) {
        exec.checkCanceled();
        DataRow r1 = it1.next();
        DataPoint p1 = m_points.get(r1.getKey());
        // first adjust point at the fixed points
        RowIterator fit = m_fixedDataPoints.iterator();
        while (fit.hasNext()) {
            DataRow fixedRow = fit.next();
            DataPoint p2 = m_fixedPoints.get(fixedRow.getKey());
            adjustDataPoint(p1, p2, r1, fixedRow);
        }
        // through all data points again
        if (!m_projectOnly) {
            RowIterator it2 = m_inData.iterator();
            while (it2.hasNext()) {
                DataRow r2 = it2.next();
                DataPoint p2 = m_points.get(r2.getKey());
                adjustDataPoint(p1, p2, r1, r2);
            }
        }
    }
    adjustLearningRate(epoch);
}
Also used : DataPoint(org.knime.base.node.mine.mds.DataPoint) RowIterator(org.knime.core.data.RowIterator) DataRow(org.knime.core.data.DataRow)

Example 2 with DataPoint

use of org.knime.base.node.mine.mds.DataPoint in project knime-core by knime.

the class MDSProjectionManager method preprocFixedDataPoints.

/**
 * Initializes for each of the fixed data points a point in the
 * target space. Which of the columns of the data table containing the
 * fixed points have to be considered (according to the non fixed points)
 * is specified by the given array of indices.
 *
 * @param fixedDataMdsIndices The indices specifying the columns of
 * the data table containing the fixed data points, to consider.
 * @throws CanceledExecutionException If the process is canceled.
 */
protected void preprocFixedDataPoints(final int[] fixedDataMdsIndices) throws CanceledExecutionException {
    m_exec.setMessage("Preprocessing fixed data points");
    // sort indices
    Arrays.sort(fixedDataMdsIndices);
    RowIterator it = m_fixedDataPoints.iterator();
    while (it.hasNext()) {
        m_exec.checkCanceled();
        DataRow row = it.next();
        DataPoint p = new DataPoint(m_dimension);
        for (int i = 0; i < m_dimension; i++) {
            final DataCell cell = row.getCell(fixedDataMdsIndices[i]);
            if (!cell.isMissing()) {
                final Double d = ((DoubleValue) cell).getDoubleValue();
                p.setElementAt(i, d);
            }
        }
        m_fixedPoints.put(row.getKey(), p);
    }
}
Also used : DataPoint(org.knime.base.node.mine.mds.DataPoint) DoubleValue(org.knime.core.data.DoubleValue) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) DataPoint(org.knime.base.node.mine.mds.DataPoint)

Example 3 with DataPoint

use of org.knime.base.node.mine.mds.DataPoint in project knime-core by knime.

the class Distances method getCosinusDistance.

/**
 * Computes the cosinus distance between the given two
 * <code>DataPoint</code>s, with given offset.
 *
 * @param point1 first point to compute the cosinus distance of
 * @param point2 second point to compute the cosinus distance of
 * @param offset offset to subtract cosinus distance from
 *
 * @return the cosinus distance between the given two rows
 */
public static double getCosinusDistance(final DataPoint point1, final DataPoint point2, final double offset) {
    double distance = 0;
    double vectorMultRes = 0;
    double vector1Length = 0;
    double vector2Length = 0;
    for (int i = 0; i < point1.size(); i++) {
        vectorMultRes += point1.getElementAt(i) * point2.getElementAt(i);
        vector1Length += Math.pow(point1.getElementAt(i), 2);
        vector2Length += Math.pow(point2.getElementAt(i), 2);
    }
    vector1Length = Math.sqrt(vector1Length);
    vector2Length = Math.sqrt(vector2Length);
    distance = vectorMultRes / (vector1Length * vector2Length);
    if (offset != 0) {
        distance = offset - distance;
    }
    return distance;
}
Also used : DataPoint(org.knime.base.node.mine.mds.DataPoint)

Example 4 with DataPoint

use of org.knime.base.node.mine.mds.DataPoint in project knime-core by knime.

the class MDSProjectionManager method adjustDataPoint.

/**
 * Adjusts the low dimensional mapping of the first data point according
 * to the second data point and its mapping.
 *
 * @param p1 The mapping of the first data point in the target space.
 * @param p2 The mapping of the second data point in the target space.
 * @param r1 The first data point in the original space.
 * @param r2 The second data point in the original space.
 */
protected void adjustDataPoint(final DataPoint p1, final DataPoint p2, final DataRow r1, final DataRow r2) {
    if (!p1.equals(p2) && !m_unmodifiablePoints.contains(p1)) {
        double disparity = disparityTransformation(m_distMan.getDistance(r1, r2));
        // double distance = m_distMan.getDistance(p1, p2);
        // use only the Euclidean distance for low dimensional data.
        double distance = m_euclideanDistMan.getDistance(p1, p2);
        if (disparity <= m_minDistThreshold) {
            // if r1 is equal r2 (or nearly equal, set p1 equal p2
            for (int d = 0; d < m_dimension; d++) {
                p1.setElementAt(d, p2.getElementAt(d));
            }
            m_unmodifiablePoints.add(p1);
        } else {
            // through all dimensions
            for (int d = 0; d < m_dimension; d++) {
                double value = p1.getElementAt(d);
                if (distance != 0) {
                    double delta = m_learningrate * (1 - (disparity / distance)) * (p2.getElementAt(d) - value);
                    // * activation;
                    p1.setElementAt(d, value + delta);
                }
            }
        }
    }
}
Also used : DataPoint(org.knime.base.node.mine.mds.DataPoint)

Example 5 with DataPoint

use of org.knime.base.node.mine.mds.DataPoint in project knime-core by knime.

the class MDSProjectionManager method init.

/**
 * Initializes the lower dimensional data points randomly.
 *
 * @param seed The random seed to use.
 * @throws CanceledExecutionException If execution was canceled by the user.
 */
public void init(final long seed) throws CanceledExecutionException {
    m_isInit = true;
    Random rand = new Random(seed);
    ExecutionMonitor exec = m_exec.createSubProgress(0.1);
    // init all data points
    RowIterator it = m_inData.iterator();
    while (it.hasNext()) {
        exec.checkCanceled();
        DataRow row = it.next();
        DataPoint p = new DataPoint(m_dimension);
        for (int j = 0; j < m_dimension; j++) {
            p.setElementAt(j, rand.nextDouble());
        }
        m_points.put(row.getKey(), p);
        exec.setProgress("Initialising data points.");
    }
}
Also used : Random(java.util.Random) DataPoint(org.knime.base.node.mine.mds.DataPoint) RowIterator(org.knime.core.data.RowIterator) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) DataRow(org.knime.core.data.DataRow) DataPoint(org.knime.base.node.mine.mds.DataPoint)

Aggregations

DataPoint (org.knime.base.node.mine.mds.DataPoint)5 DataRow (org.knime.core.data.DataRow)3 RowIterator (org.knime.core.data.RowIterator)3 Random (java.util.Random)1 DataCell (org.knime.core.data.DataCell)1 DoubleValue (org.knime.core.data.DoubleValue)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1