复杂网络社区结构发现算法-基于igraph 标签传播算法

【前言】

      继续我们本系列对复杂网络社区结构的方法探索,之前已经尝试过spark上标签传播算法、igraph 中随机游走算法、networkx中的clique渗透算法(见笔者相关文章),但一直局限于无向、无权重图的分析。本次,向前迈一步,引入权重。选用了igraph中的标签传播算法。

【方法讨论】  

    相比于spark上的标签传播算法,发现igraph中的接口增加了对权重的支持,同时不用事先指定迭代的次数,这是两点好的地方。当然,可以处理的数据量级上,igraph单机版本没法和spark集群版本相提并论了。但是相比于python版本networkx的性能瓶颈,igraph C library的计算效率领先几条街。(小小吐槽一下:igraph同时提供有python、R、C三种版本的接口,相比之下,C library的使用要繁琐很多,如果不是追求性能稍好些,真心推荐使用其它两种方式)

   在对权重的处理上,官方文档如是说:

Weights are taken into account as follows: when the new label of node i is determined, the algorithm iterates over all edges incident on node i and calculate the total weight of edges leading to other nodes with label 0, 1, 2, ..., k-1 (where k is the number of possible labels). The new label of node i will then be the label whose edges (among the ones incident on node i) have the highest total weight.

    算法接口也比较简洁明确(稍后咱们详细看如何使用):

int igraph_community_label_propagation(const igraph_t *graph,
                                       igraph_vector_t *membership,
                                       const igraph_vector_t *weights,
                                       const igraph_vector_t *initial,
                                       igraph_vector_bool_t *fixed, 
				       igraph_real_t *modularity);

 【不废话,上完整版代码】

#include <stdio.h>
#include <stdlib.h>
#include </usr/local/igraph-0.7.1/include/igraph.h>
#include <string.h>

int main(int argc,char *argv[])
{
    printf("Hello world!\n");
    FILE *edgeListFile;
    FILE *community
  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值