public SortedMultiMap<Double,Integer> getMostSimilar(
            Matrix m, int row,
            int kNearestRows, SimilarityFunction simFunction) {
        
        
        Object key = workQueue.registerTaskGroup(m.rows() - 1);

        // the most-similar set will automatically retain only a fixed number of
        // elements
        final SortedMultiMap<Double,Integer> mostSimilar =
            new BoundedSortedMultiMap<Double,Integer>(kNearestRows, false);

        // loop through all the other words computing their similarity
        int rows = m.rows();
        Vector v = m.getRowVector(row);
        for (int i = 0; i < rows; ++i) {
            // skip same row
            if (i == row) 
                continue;

            workQueue.add(key,
                          new Comparison(m, v, i, simFunction, mostSimilar));
        }
        
        // Wait for all the partition densities to be calculated
        workQueue.await(key);
        
        return mostSimilar;
    }
public SortedMultiMap < Double , Integer > getMostSimilar ( Matrix m , int row , int kNearestRows , SimilarityFunction simFunction ) { Object key = workQueue . registerTaskGroup ( m . rows ( ) - 1 ) ; final SortedMultiMap < Double , Integer > mostSimilar = new BoundedSortedMultiMap < Double , Integer > ( kNearestRows , false ) ; int rows = m . rows ( ) ; Vector v = m . getRowVector ( row ) ; for ( int i = 0 ; i < rows ; ++ i ) { if ( i == row ) continue ; workQueue . add ( key , new Comparison ( m , v , i , simFunction , mostSimilar ) ) ; } workQueue . await ( key ) ; return mostSimilar ; }
Compares the specified row to all other rows, returning the k-nearest
rows according to the similarity metric.

@param m The {@link Matrix} containing data points to be compared
@param row The current row in {@code m} to be compared against all other
rows
@param kNearestRows The number of most similar rows to retain
@param simFunction The {@link SimilarityFunction} to use when comparing
rows
@return a mapping from the similarity to the k most similar rows