src/main.cc
/**
 * Calculate nearest neighbours list for each node
 */
Calculate nearest neighbours list for each node
Calculate nearest neighbours list for each node
static vector<vector<uint32_t>> 
init_nn_lists(const vector<vector<double>> &dist_matrix, uint32_t nn_size = 32) {
    const uint32_t size = dist_matrix.size();
    vector<vector<uint32_t>> nn_lists;
    for (uint32_t i = 0; i < size; ++i) {
        vector<uint32_t> all_nodes = range(0u, size);
        all_nodes.erase( all_nodes.begin() + i ); 
        const auto &dist = dist_matrix[i];
        sort(all_nodes.begin(), all_nodes.end(),
            [&](uint32_t u, uint32_t v) -> bool { return dist[u] < dist[v]; });
        assert( dist[all_nodes[0]] <= dist[all_nodes[1]] );
        all_nodes.resize(nn_size); 
        nn_lists.push_back(all_nodes);
    }
    return nn_lists;
}
static vector < vector < uint32_t > > init_nn_lists ( const vector < vector < double > > & dist_matrix , uint32_t nn_size = 32 ) { const uint32_t size = dist_matrix . size ( ) ; vector < vector < uint32_t > > nn_lists ; for ( uint32_t i = 0 ; i < size ; ++ i ) { vector < uint32_t > all_nodes = range ( 0u , size ) ; all_nodes . erase ( all_nodes . begin ( ) + i ) ; const auto & dist = dist_matrix [ i ] ; sort ( all_nodes . begin ( ) , all_nodes . end ( ) , [ & ] ( uint32_t u , uint32_t v ) -> bool { return dist [ u ] < dist [ v ] ; } ) ; assert ( dist [ all_nodes [ 0 ] ] <= dist [ all_nodes [ 1 ] ] ) ; all_nodes . resize ( nn_size ) ; nn_lists . push_back ( all_nodes ) ; } return nn_lists ; }
Calculate nearest neighbours list for each node
Calculate nearest neighbours list for each node
// We don't want node to be a neighbour of self // drop size - nn_size farthest nodes