大家好,欢迎来到IT知识分享网。
1. 运行环境
LFR程序下载链接, 运行环境为Linux、g++
1.1 先安装build-essential:(可省略)
$ sudo apt-get install build-essential
1.2 查看 gcc 版本
$ gcc --versiongcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3Copyright (C) 2011 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1.3 安装 统一版本的 g++
$ sudo apt-get install g++
1.4 查看安装版本
$ g++ --version
2. 用LFR生成网络
- 首先跳转到
LFR的binary_network目录中compile一下。
$ make
这样会生成一个 benchmark 文件,它就是我们构建网络的工具。
- 使用
benchmark生成一个网络数据的简单的例子:
$ ./benchmark -f flags.dat -t1 3
这里的 flags.dat 文件在解压缩包后就有的,它表示参数的设置。benchmark工具会根据这个flag.dat文件生成网络数据。如果要生成其他的网络,要修改这个文件的参数。
$ ./benchmark [FLAG] [P][FLAG] [P]-N number of nodes-k average degree-maxk maximum degree-mu mixing parameter-t1 minus exponent for the degree sequence-t2 minus exponent for the community size distribution-minc minimum for the community sizes-maxc maximum for the community sizes-on number of overlapping nodes-om number of memberships of the overlapping nodes-C [average clustering coefficient]
- 关于参数mu
1-mu是节点与其同一个社区内的节点之间的共享比例,mu是节点与其它社区节点的共享比例。mu设置的小一点,社区内部更加紧凑。 - 一个
flag.dat文件的例子:
-N 2000-k 16-maxk 60-mu 0.3-t1 2-t2 1-minc 32-maxc 40-on 0-om 0
3. 转化为gml文件
network.dat文件是得到的网络结构,每一行表示一条边。文件community.dat是该网络的真实社区结构其每一行表示 (节点、节点所在的社区)。
将network.dat 和 community.dat 转化为我们需要的 LFR-1.gml 文件:
#coding=utf-8import networkx as nxfrom collections import defaultdictdef transfer_2_gml():"""--------------------------------------------------------------------------function: 将LFR的network.dat和community.dat转化为.gml文件parameter:return:-------------------------------------------------------------------------------"""nodes_labels={}k=0with open("community.dat","r") as f:for line in f.readlines():items=line.strip("\r\n").split("\t")v=items[0]label=items[1]nodes_labels[v]=label#end-for#end-withG=nx.Graph()for v in nodes_labels.keys(): #添加所有的节点,并且记录其真实标签G.add_node(v, value=nodes_labels[v])edges=set()with open("network.dat","r") as f:for line in f.readlines():items=line.strip("\r\n").split("\t")a=items[0]b=items[1]if (a,b) not in edges or (b,a) not in edges:edges.add( (a,b) )#end-for#end-withfor e in edges:a,b=eG.add_edge(a,b,type="Undirected")nx.write_gml(G,"LFR-1.gml")print ("transfer LFR(*.dat) data to *.gml")communities=defaultdict(lambda :[])for v in nodes_labels.keys():label=nodes_labels[v]communities[label].append(v)for c in communities.keys():print ("community ", c ,": \n", communities[c], "\n")def main():transfer_2_gml()if __name__ == '__main__':main()
4. 参考
[1] LFR程序下载
[2] LFR使用示例–github链接
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/124933.html