private DBIDs getNearestNeighbors ( Relation < V > relation , SimilarityQuery < V > simQ , DBIDRef queryObject ) { Heap < DoubleDBIDPair > nearestNeighbors = new TiedTopBoundedHeap <> ( knn ) ; for ( DBIDIter iter = relation . iterDBIDs ( ) ; iter . valid ( ) ; iter . advance ( ) ) { if ( DBIDUtil . equal ( iter , queryObject ) ) { continue ; } double sim = simQ . similarity ( queryObject , iter ) ; if ( sim > 0. ) { nearestNeighbors . add ( DBIDUtil . newPair ( sim , iter ) ) ; } } // Collect DBIDs ArrayModifiableDBIDs dbids = DBIDUtil . newArray ( nearestNeighbors . size ( ) ) ; while ( nearestNeighbors . size ( ) > 0 ) { dbids . add ( nearestNeighbors . poll ( ) ) ; } return dbids ; }
Get the k nearest neighbors in terms of the shared nearest neighbor distance .