demon 社区发现_社团检测常用算法调用总结

本文总结了多种社区检测算法的实现与使用,包括Louvain模ularity在Linux和MinGW下的编译与应用,Link Communities的固定结果输出,OSLOM的层次社团检测,Infomap的无向图处理,GCE在不同平台的编译问题,DEMON的Python实现,以及CFinder的直接使用和BigClam的社群查找。每个算法都详细介绍了编译过程和使用示例。
摘要由CSDN通过智能技术生成

测试文件 graph.txt,内容为:

01

02

03

12

13

24

45

47

56

57

58

68

78

710

89

910

912

913

1011

1012

1112

1113

1213

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

01

02

03

12

13

24

45

47

56

57

58

68

78

710

89

910

912

913

1011

1012

1112

1113

1213

网络如下图所示:

Louvain Modularity

该算法的结果有随机性

Linux编译

使用make编译,这个版本会提示main_community.cpp:125:27: error: ‘getpid’ was not declared in this scope srand(time(NULL)+getpid());

只要在前面加上头文件#include 就可以了。

MinGW编译

需要修改的地方:

1. graph_binary.cpp 中第30行的 #include 注释掉。

2. main_community.cpp 的第29行添加#include

3. 由于代码中默认long类型是8字节大小,而我的windows中long大小是4字节,导致出错。需修改的地方:

graph.cpp文件 142行 long tot=0; 改为 long long tot=0;

graph.cpp文件 144行 tot+=(long)links[i].size(); 改为 tot+=(long long)links[i].size();

graph_binary.cpp 第57行 改为finput.read((char *)(&links[0]), (long)nb_links*4);

graph_binary.cpp 第161 162行改为 foutput.write((char *)(&degrees[0]),8*nb_nodes); foutput.write((char *)(&links[0]),4*nb_links);

修改graph_binary.h文件 约55行   vector degrees; 改为 vector degrees;

之后可以编译

使用方法:

无权图:

./convert -i graph.txt -o graph.bin

./community graph.bin -l -1 -v > graph.tree

1

2

./convert-igraph.txt-ograph.bin

./communitygraph.bin-l-1-v>graph.tree

有权图:

./convert -i graph.txt -o graph.bin -w graph.weights

./community graph.bin -l -1 -w graph.weights > graph.tree

1

2

./convert-igraph.txt-ograph.bin-wgraph.weights

./communitygraph.bin-l-1-wgraph.weights>graph.tree

结果如下:

0 0

1 0

2 0

3 0

4 1

5 1

6 1

7 1

8 1

9 2

10 2

11 2

12 2

13 2

0 0

1 1

2 2

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

00

10

20

30

41

51

61

71

81

92

102

112

122

132

00

11

22

这个算法的结果有层次结构的,第一个0到13行 是叶子层,后面还有的话就是更高的level

Link Communities

对于相同的图,该算法的结果是固定的。

cpp版本:

编译(Linux,MinGW)

g++ -O5 -o calcJaccards calcAndWrite_Jaccards.cpp

g++ -O5 -o clusterJaccards clusterJaccsFile.cpp

1

2

g++-O5-ocalcJaccardscalcAndWrite_Jaccards.cpp

g++-O5-oclusterJaccardsclusterJaccsFile.cpp

使用:

./calcJaccards net.pairs net.jaccs

./clusterJaccards net.pairs net.jaccs net.clusters net.mc_nc THRESHOLD

1

2

./calcJaccardsnet.pairsnet.jaccs

./clusterJaccardsnet.pairsnet.jaccsnet.clustersnet.mc_ncTHRESHOLD

THRESHOLD是一个小数(例如0.2)

输出net.clusters文件:

0,1 0,2 0,3 1,2 1,3

2,4

4,5 4,7 5,6 5,7 5,8 6,8 7,8 7,10 8,9 9,10 9,12 9,13 10,11 10,12 11,12 11,13 12,13

1

2

3

0,10,20,31,21,3

2,4

4,54,75,65,75,86,87,87,108,99,109,129,1310,1110,1211,1211,1312,13

OSLOM

Linux编译

下载代码后,执行目录中的 compile_all.sh 进行编译。

编译后,会生成可执行文件oslom_dir和oslom_undir,分别适用于有向图和无向图

MinGW编译

编译出exe但是运行会段错误,暂未调通。

使用方法

./oslom_undir -f graph.txt -uw

1

./oslom_undir-fgraph.txt-uw

-f 指定图文件, -uw表示不带权,-w表示带权

会在当前目录生成结果文件夹:graph.txt_oslo_files,其中 tp ,tp1, tp2…就是社团文件。oslom的社团检测是分层级的,tp是最顶层社团,tp1是下面一层…

运行结果:

#module 0 size: 4 bs: 0.0932256

0 1 2 3

#module 1 size: 10 bs: 0.0578294

4 5 6 7 8 9 10 11 12 13

1

2

3

4

#module 0 size: 4 bs: 0.0932256

0123

#module 1 size: 10 bs: 0.0578294

45678910111213

Infomap

linux下,执行make进行编译。

MinGW中编译

没有安装OMP的情况下使用make noomp编译 。

若报错undefined reference to `_Unwind_Resume’,修改makefile,在第17行加入 CXXFLAGS += -Wl,-Bdynamic -lgcc_s

使用方法

Infomap中结点的起始编号默认从1开始,如果有0结点,要使用-z选项

Infomap/Infomap graph.txt . -z -i link-list --clu

1

Infomap/Infomapgraph.txt.-z-ilink-list--clu

输出文件graph.clu

# 'graph.txt . -z -i link-list --clu' -> 14 nodes partitioned in 0s from codelength 3.772924456 in one level to codelength 2.986246713 in 2 levels.

# node cluster flow:

9 1 0.0869565

10 1 0.0869565

12 1 0.0869565

11 1 0.0652174

13 1 0.0652174

5 2 0.0869565

7 2 0.0869565

8 2 0.0869565

4 2 0.0652174

6 2 0.0434783

0 3 0.0652174

1 3 0.0652174

2 3 0.0652174

3 3 0.0434783

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

# 'graph.txt . -z -i link-list --clu' -> 14 nodes partitioned in 0s from codelength 3.772924456 in one level to codelength 2.986246713 in 2 levels.

# node cluster flow:

910.0869565

1010.0869565

1210.0869565

1110.0652174

1310.0652174

520.0869565

720.0869565

820.0869565

420.0652174

620.0434783

030.0652174

130.0652174

230.0652174

330.0434783

Greedy Clique Expansion(GCE)

代码下载地址:GCE

linux编译

linux上代码直接编译会有错误,对 graph_loading 文件作如下修改:

1. 注释掉语句 close(graphFD);

2. 把整个 const char *readEdge(const char *cur, int &l, int &r) 函数 移动到文件前面namespace graph_loading { 后,(14行)

3. 找到 struct readEdgeInvalidLineInDataException : public exception { }; 这一行,把它移动到文件前面namespace graph_loading { 后,(14行)

windows上编译

把mman.h放到GCECommunityFinder目录,修改graph_loading.cpp中的 #include  改为 #include “mman.h”

g++ -c mman.cpp可以生成一个mman.o文件

把mman.o文件放到GCECommunityFinder\build目录,修改makefile,在第9行后面加入 ./mman.o

g++ -o "GCECommunityFinder" ./Community_Finder.o ./Seed.o ./aaron_utils.o ./cliques.o ./find_communities.o ./graph_loading.o ./graph_representation.o ./mman.o

1

g++-o"GCECommunityFinder"./Community_Finder.o./Seed.o./aaron_utils.o./cliques.o./find_communities.o./graph_loading.o./graph_representation.o./mman.o

编译时提示mkdir函数没有声明,在cliques.cpp第2行加入

#include

编译时提示

../graph_loading.cpp:340:17: error: aggregate 'graph_loading::mmapFile(const char*)::stat64 buf' has incomplete type and cannot be defined

struct stat64 buf;

^

../graph_loading.cpp:341:24: error: 'fstat64' was not declared in this scope

fstat64(graphFD, &buf) == 0 || Die("fstat64 failed");

1

2

3

4

5

../graph_loading.cpp:340:17:error:aggregate'graph_loading::mmapFile(const char*)::stat64 buf'hasincompletetypeandcannotbedefined

structstat64buf;

^

../graph_loading.cpp:341:24:error:'fstat64'wasnotdeclaredinthisscope

fstat64(graphFD,&buf)==0||Die("fstat64 failed");

在#include 这一行上面加入下面的代码

#if __MINGW32__

#define __MSVCRT_VERSION__ 0x0601

#endif

struct __stat64

{

_dev_t st_dev;

_ino_t st_ino;

_mode_t st_mode;

short st_nlink;

short st_uid;

short st_gid;

_dev_t st_rdev;

__int64 st_size;

__time64_t st_atime;

__time64_t st_mtime;

__time64_t st_ctime;

};

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

#if __MINGW32__

#define __MSVCRT_VERSION__ 0x0601

#endif

struct__stat64

{

_dev_tst_dev;

_ino_tst_ino;

_mode_tst_mode;

shortst_nlink;

shortst_uid;

shortst_gid;

_dev_tst_rdev;

__int64st_size;

__time64_tst_atime;

__time64_tst_mtime;

__time64_tst_ctime;

};

进入build文件执行make就可以编译了

使用方法

GCECommunityFinder/build/GCECommunityFinder graph.txt 3 0.6 1.0 0.75 2> LC_output.txt | tee GCE.gen

1

GCECommunityFinder/build/GCECommunityFindergraph.txt30.61.00.752>LC_output.txt|teeGCE.gen

注意2>是一个整体 2不是参数

GCE.gen

0 1 3 2

4 5 7 8 6

9 12 13 11 10

1

2

3

0132

45786

912131110

DEMON

Democratic Estimate of the Modular Organization of a Network

需要安装networkx 安装命令

sudo pip install networkx

1

sudopipinstallnetworkx

运行命令

python demon_py/launch.py graph.txt

1

pythondemon_py/launch.pygraph.txt

产生文件communities,内容为

04,5,6,7,8

19,10,11,12,13

20,1,2,3

1

2

3

04,5,6,7,8

19,10,11,12,13

20,1,2,3

CFinder

下载后直接提供了可执行文件 ,使用下面的命令给予运行权限

chmod +x CFinder/CFinder_commandline

chmod +x CFinder/CFinder_commandline64

1

2

chmod+xCFinder/CFinder_commandline

chmod+xCFinder/CFinder_commandline64

使用方法

CFinder/CFinder_commandline64 -i graph.txt -l CFinder/licence.txt -o CFinderOutput

1

CFinder/CFinder_commandline64-igraph.txt-lCFinder/licence.txt-oCFinderOutput

-o后面是输出目录,这个目录必须之前不存在

输出文件在 指定的目录中的k=3中的communities文件

# The communities at k=3

# from /home/yalewoo/CommunityDetectionAlgorithm/graph.txt

# at no lower link weight threshold,

# and at no upper link weight threshold.

# Links were treated as undirected.

# No time limit was set for the clique search.

0: 0 1 2 3

1: 4 5 7 6 8

2: 10 11 12 13 9

1

2

3

4

5

6

7

8

9

10

# The communities at k=3

# from /home/yalewoo/CommunityDetectionAlgorithm/graph.txt

# at no lower link weight threshold,

# and at no upper link weight threshold.

# Links were treated as undirected.

# No time limit was set for the clique search.

0:0123

1:45768

2:101112139

BigClam

Linux编译

使用 make all 编译整个 snap

MinGw编译

未成功。

使用方法

snap-master/examples/bigclam/bigclam -i:graph.txt

结果在当前目录生成的 cmtyvv.txt 文件中:

13129

131112

301

201

91312

131112

658

131112

210

574

130

031

578

685

758

758

785

685

785

578

685

685

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

13129

131112

301

201

91312

131112

658

131112

210

574

130

031

578

685

758

758

785

685

785

578

685

685

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值