LFR简单使用入门
来源:互联网 发布:淘宝账号销号 编辑:程序博客网 时间:2024/06/06 06:53
1. 运行环境
LFR程序下载链接, 运行环境为Linux、g++
1.1 先安装build-essential:(可省略)
$ sudo apt-get install build-essential
1.2 查看 gcc 版本
$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; 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-8
import networkx as nx
from collections import defaultdict
def transfer_2_gml():
"""--------------------------------------------------------------------------
function: 将LFR的network.dat和community.dat转化为.gml文件
parameter:
return:
-------------------------------------------------------------------------------"""
nodes_labels={}
k=0
with 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-with
G=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-with
for e in edges:
a,b=e
G.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链接
阅读全文
0 0
- LFR简单使用入门
- 神经网络-LFR model
- XPath简单使用 入门
- VIM 简单使用入门
- Ibatis入门--简单使用
- Git 简单入门使用
- UEditor简单入门使用
- xshell简单使用入门
- XUtils简单入门使用
- maven简单入门使用
- Git 使用简单入门
- Dagger2简单入门使用
- MyBatis简单入门使用
- JDBC简单入门使用
- MyBatis简单入门使用
- java htmlparser 简单使用入门
- git简单使用入门总结
- struts1简单入门使用实例
- win7命令行 端口占用 查询进程号 杀进程
- css选择器
- 【面经笔记】深信服电话二面
- 相关性学习-皮尔逊相关系数
- Parallel Scavenge收集器
- LFR简单使用入门
- 超强自定义TabLayout
- Codis源码解析——codis-server添加到集群
- 【nginx-rtmp】04、获取客户端订阅/连接数(Getting number of subscribers)
- Mysql 中!=和 <>
- aix下扩充swap大小
- JDNI配置和使用
- poj3259(判断有无负环)
- MVC与三层架构区别