首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于Graphlabs中的Graphchi :社区检测示例

关于Graphlabs中的Graphchi :社区检测示例
EN

Stack Overflow用户
提问于 2012-08-23 05:36:45
回答 1查看 579关注 0票数 0

如果有人知道Graphchi并试图理解communitydetection.cpp代码,我需要帮助来理解这段代码在step by tep方式中做了什么:

代码语言:javascript
复制
 for(int i=0; i < vertex.num_edges(); i++) {
            bidirectional_label edgelabel = vertex.edge(i)->get_data();
            vid_t nblabel = neighbor_label(edgelabel, vertex.id(), vertex.edge(i)->vertex_id());
            std::map<vid_t, int>::iterator existing = counts.find(nblabel);
            int newcount = 0;
            if(existing == counts.end()) {
                counts.insert(std::pair<vid_t,int>(nblabel, 1));
                newcount = 1;
            } else {
                existing->second++;//map iterator
                newcount = existing->second;
            }
            if (newcount > maxcount || (maxcount == newcount && nblabel > maxlabel)) {
                maxlabel = nblabel;
                maxcount = newcount;
            }
        }
        newlabel = maxlabel;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-23 06:23:31

不出所料,我在社区检测示例中添加了代码注释:http://code.google.com/p/graphchi/source/browse/example_apps/communitydetection.cpp

代码语言:javascript
复制
          /* The basic idea is to find the label that is most popular among
           this vertex's neighbors. This label will be chosen as the new label
           of this vertex. */
        // This part could be optimized: STL map is quite slow.
        std::map<vid_t, int> counts;
        int maxcount=0;
        vid_t maxlabel=0;
        /* Iterate over all the edges */
        for(int i=0; i < vertex.num_edges(); i++) {
            /* Extract neighbor's current label. The edge contains the labels of
               both vertices it connects, so we need to use the right one. 
               (See comment for bidirectional_label above) */
            bidirectional_label edgelabel = vertex.edge(i)->get_data();
            vid_t nblabel = neighbor_label(edgelabel, vertex.id(), vertex.edge(i)->vertex_id());

            /* Check if this label (nblabel) has been encountered before ... */
            std::map<vid_t, int>::iterator existing = counts.find(nblabel);
            int newcount = 0;
            if(existing == counts.end()) {
                /* ... if not, we add this label with count of one to the map */
                counts.insert(std::pair<vid_t,int>(nblabel, 1));
                newcount = 1;
            } else {
                /* ... if yes, we increment the counter for this label by 1 */
                existing->second++;
                newcount = existing->second;
            }

            /* Finally, we keep track of the most frequent label */
            if (newcount > maxcount || (maxcount == newcount && nblabel > maxlabel)) {
                maxlabel = nblabel;
                maxcount = newcount;
            }
        }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12081773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档