Search in sources :

Example 1 with HeapItem

use of org.deeplearning4j.clustering.sptree.HeapItem in project deeplearning4j by deeplearning4j.

the class VPTree method search.

public void search(Node node, DataPoint target, int k, PriorityQueue<HeapItem> pq) {
    if (node == null)
        return;
    DataPoint get = items.get(node.getIndex());
    double distance = getDistance(get, target);
    if (distance < tau) {
        if (pq.size() == k)
            pq.next();
        pq.add(new HeapItem(node.index, distance), distance);
        if (pq.size() == k)
            tau = pq.peek().getDistance();
    }
    if (node.getLeft() == null && node.getRight() == null)
        return;
    if (distance < node.getThreshold()) {
        if (distance - tau <= node.getThreshold()) {
            // if there can still be neighbors inside the ball, recursively search left child first
            search(node.getLeft(), target, k, pq);
        }
        if (distance + tau >= node.getThreshold()) {
            // if there can still be neighbors outside the ball, recursively search right child
            search(node.getRight(), target, k, pq);
        }
    } else {
        if (distance + tau >= node.getThreshold()) {
            // if there can still be neighbors outside the ball, recursively search right child first
            search(node.getRight(), target, k, pq);
        }
        if (distance - tau <= node.getThreshold()) {
            // if there can still be neighbors inside the ball, recursively search left child
            search(node.getLeft(), target, k, pq);
        }
    }
}
Also used : HeapItem(org.deeplearning4j.clustering.sptree.HeapItem) DataPoint(org.deeplearning4j.clustering.sptree.DataPoint)

Aggregations

DataPoint (org.deeplearning4j.clustering.sptree.DataPoint)1 HeapItem (org.deeplearning4j.clustering.sptree.HeapItem)1