@Override public HardAssigner<T, float[], IntFloatPair> defaultHardAssigner() { return new ExactFeatureVectorAssigner<T>(this, nn.distanceComparator()); }
private List<IntFloatPair> search(T query, BoundedPriorityQueue<IntFloatPair> queue, List<IntFloatPair> results) { IntFloatPair wp = null; // reset all values in the queue to MAX, -1 for (final IntFloatPair p : results) { p.second = Float.MAX_VALUE; p.first = -1; wp = queue.offerItem(p); } // perform the search final int size = this.pnts.size(); for (int i = 0; i < size; i++) { wp.second = ObjectNearestNeighbours.distanceFunc(distance, query, pnts.get(i)); wp.first = i; wp = queue.offerItem(wp); } return queue.toOrderedListDestructive(); }
@Override public Boolean call() { try { final int D = ds.getData(0).length(); final T[] points = ds.createTemporaryArray(stopRow - startRow); ds.getData(startRow, stopRow, points); final int[] argmins = new int[points.length]; final float[] mins = new float[points.length]; nno.searchNN(points, argmins, mins); synchronized (centroids_accum) { for (int i = 0; i < points.length; ++i) { final int k = argmins[i]; final double[] vector = points[i].asDoubleVector(); for (int d = 0; d < D; ++d) { centroids_accum[k][d] += vector[d]; } counts[k] += 1; } } } catch (final Exception e) { e.printStackTrace(); } return true; } }
@Override public List<ScoredAnnotation<ANNOTATION>> annotate(final OBJECT object) { if (this.nn == null) this.nn = new ObjectNearestNeighboursExact<FEATURE>(this.features, this.comparator); final TObjectIntHashMap<ANNOTATION> selected = new TObjectIntHashMap<ANNOTATION>(); final List<FEATURE> queryfv = new ArrayList<FEATURE>(1); queryfv.add(this.extractor.extractFeature(object)); final int[][] indices = new int[1][this.k]; final float[][] distances = new float[1][this.k]; this.nn.searchKNN(queryfv, this.k, indices, distances); int count = 0; for (int i = 0; i < this.k; i++) { // Distance check if (distances[0][i] > this.threshold) { continue; } final Collection<ANNOTATION> anns = this.annotations.get(indices[0][i]); for (final ANNOTATION ann : anns) { selected.adjustOrPutValue(ann, 1, 1); count++; } } final TObjectIntIterator<ANNOTATION> iterator = selected.iterator(); final List<ScoredAnnotation<ANNOTATION>> result = new ArrayList<ScoredAnnotation<ANNOTATION>>(selected.size()); while (iterator.hasNext()) { iterator.advance(); result.add(new ScoredAnnotation<ANNOTATION>(iterator.key(), (float) iterator.value() / (float) count)); } return result; }
private List<IntFloatPair> search(T query, BoundedPriorityQueue<IntFloatPair> queue, List<IntFloatPair> results) { IntFloatPair wp = null; // reset all values in the queue to MAX, -1 for (final IntFloatPair p : results) { p.second = Float.MAX_VALUE; p.first = -1; wp = queue.offerItem(p); } // perform the search final int size = this.pnts.size(); for (int i = 0; i < size; i++) { wp.second = ObjectNearestNeighbours.distanceFunc(distance, query, pnts.get(i)); wp.first = i; wp = queue.offerItem(wp); } return queue.toOrderedListDestructive(); }