社区发现SLPA算法
社区(community)定义:同一社区内的节点与节点之间关系紧密,而社区与社区之间的关系稀疏。
设图G=G(V,E),所谓社区发现是指在图G中确定nc(>=1)个社区C={C1,C2,...,Cnv},使得各社区的顶点集合构成V的一个覆盖。
若任意两个社区的顶点集合的交际均为空,则称C为非重叠社区(disjoint communities);否则称为重叠社区(overlapping communities)。
SLPA(Speaker-listener Label Propagation Algorithm)算法是一种社区发现算法,它是对LPA算法(标签传播算法)的拓展。
算法思想如下:
输入参数:迭代次数T,满足社区次数要求的阈值r
输出参数:每一个节点的社区分布
(1)首先,每一个节点的存储器中初始化一个唯一的标签。
(2)然后,重复进行以下步骤,直到达到最大迭代T:
a. 选择一个节点作为监听器;
b. 所选节点的每个邻居随机选择概率正比于该标签在其存储器中的出现频率的标签,把所选择的标签(speakervote)发送到听众(listener);
c. 监听器增加接收到的最流行的标签到内存。
(3)最后,根据在存储器里的标签和阈值r,后处理被用于输出社区。
public int speakerVote() {
//Run through each element in the map to create a cumulative distribution
Set<Integer> communityIds = communityDistribution.keySet();
ArrayList<Integer> communities = new ArrayList<Integer>();
ArrayList<Integer> cumulativeCounts = new ArrayList<Integer>();
int sum=-1;
for (Integer comm: communityIds) {
sum += communityDistribution.get(comm);
communities.add(comm);
cumulativeCounts.add(sum);
}
//Generate a random integer in the range [0,sum)
int rand = RandomNumGenerator.getRandomInt(sum+1);
//Find the index of first value greater than rand in cumulativeCounts
int i=0;
for (i=0; i<cumulativeCounts.size(); i++) {
if (cumulativeCounts.get(i)>=rand)
break;
}
//Return the corresponding community
return communities.get(i);
}
SpeakerVote
public void updateLabels(Integer userId){
Set<DefaultWeightedEdge> incomingEdges = userNodegraph.getGraph().incomingEdgesOf(userId);//获取所有该顶点的入度顶点
Map<Integer, Integer> incomingVotes = new HashMap<Integer, Integer>();//所有speaker顶点投票情况
//For each vertex V with an incoming edge to the current node
for ( DefaultWeightedEdge edge: incomingEdges ) {
int speakerId = userNodegraph.getGraph().getEdgeSource(edge);
UserNode speakerNode = userNodegraph.getNodeMap().get(speakerId);
int votedCommunity = speakerNode.speakerVote();
int votedCommunitycount = 1;
if ( incomingVotes.containsKey(votedCommunity)){
votedCommunitycount += incomingVotes.get(votedCommunity);
}
incomingVotes.put(votedCommunity, votedCommunitycount);
}
//Find the most popular vote
Iterator<Entry<Integer, Integer>> it = incomingVotes.entrySet().iterator();
int popularCommunity=-1;
int popularCommunityCount=0;
while ( it.hasNext()) {
Entry<Integer, Integer> entry = it.next();
if ( entry.getValue() > popularCommunityCount ) {
popularCommunity = entry.getKey();
popularCommunityCount = entry.getValue();
}
}
//Update community distribution of the current node by 1
UserNode currentNode = userNodegraph.getNodeMap().get(userId);
currentNode.updateCommunityDistribution(popularCommunity, 1);
}
listenerUpdateCommunity
注:源代码请联系limin12891@163.com.
社区发现SLPA算法的更多相关文章
- SLAP(Speaker-Listener Label Propagation Algorithm)社区发现算法
其中部分转载的社区发现SLPA算法文章 一.概念 社区(community)定义:同一社区内的节点与节点之间关系紧密,而社区与社区之间的关系稀疏. 设图G=G(V,E),所谓社区发现是指在图G中确定n ...
- 网络科学 - 社区发现 Community structure and detection及其几个实现工具
首先什么是社区(Community structure)呢?其实并不是指一个网络相互连接的部分,而是一个网络中链接“紧密的部分”,至于怎么定义紧密就有很多方法了. 社区发现算法可以参考下面的博客:博客 ...
- 社区发现(Community Detection)算法 [转]
作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...
- 社区发现(Community Detection)算法(转)
作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...
- 社区发现(Community Detection)算法
作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...
- 模块度与Louvain社区发现算法
Louvain算法是基于模块度的社区发现算法,该算法在效率和效果上都表现较好,并且能够发现层次性的社区结构,其优化目标是最大化整个社区网络的模块度. 模块度(Modularity) 模块度是评估一个社 ...
- 社区发现算法问题&&NetworkX&&Gephi
在做东西的时候用到了社区发现,因此了解了一下有关社区发现的一些问题 1,社区发现算法 (1)SCAN:一种基于密度的社团发现算法 Paper: <SCAN: A Structural Clust ...
- 社区发现算法 - Fast Unfolding(Louvian)算法初探
1. 社团划分 0x1:社区是什么 在社交网络中,用户相当于每一个点,用户之间通过互相的关注关系构成了整个网络的结构. 在这样的网络中,有的用户之间的连接较为紧密,有的用户之间的连接关系较为稀疏.其中 ...
- Top Leaders社区发现算法(top leaders community detection approach in information networks)
一.概念 复杂网络:现实生活中各种系统都可以看做成复杂网络,复杂网络构成包括节点和边,节点是网络中的基本组成单元,节点之间的联系或者关系是网络中的边.例如 电力网络:基站代表节点,基站之间是否互通表示 ...
随机推荐
- sql判断表是否已经存在
if (object_id(N'td_VipExchangeCodeInfo',N'U') is not null)print '存在'else print '不存在'
- catkin
catkin ros https://github.com/dirkholz/pcl_online_viewer rosrun ???
- MyEclipse中Web项目文件名上红色和黄色感叹号处理
MyEclipse中Web项目文件名上红色和黄色感叹号处理 先说红色感叹号: 那就是代表错误,说明你引用的JAR包位置无效,所以,你应该重新将包导入到工程里面去,这个具体应该会吧,如果是初 ...
- Python中where()函数的用法
where()的用法 首先强调一下,where()函数对于不同的输入,返回的只是不同的. 1当数组是一维数组时,返回的值是一维的索引,所以只有一组索引数组 2当数组是二维数组时,满足条件的数组值返回的 ...
- CI框架入门教程
1. URL常用的相关函数 url相关函数在辅助类url中第一,要使用它们必须先加载$this->load->helper('url')或者自动装载 site_url('控制器/方法 ...
- Linux C 网络编程——3. TCP套接口编程
1. 基本流程 2. socket() int socket(int domain, int type, int protocol); socket()打开一个网络通讯端口,如果成功的话,就像open ...
- iperf 指令
1. 测试UDP丢包率 30个现成以5Mbps速度测试60s iperf -u -c 目的IP -b 5M -P 30 -t 60 测试TCP丢包率 iperf -c 目的IP -b 5M -P 30 ...
- 打造自己的Sublime使用环境
1.破解LICENSE(如果不是特穷还是买一个吧,不是特别贵,支持正版)----- BEGIN LICENSE -----Andrew WeberSingle User LicenseEA7E-855 ...
- 【转】如何避免OOM总结
原文地址:http://www.csdn.net/article/2015-09-18/2825737/3 减小对象的内存占用 避免OOM的第一步就是要尽量减少新分配出来的对象占用内存的大小,尽量使用 ...
- 【转】Leader-Follower线程模型
上图就是L/F多线程模型的状态变迁图,共6个关键点: (1)线程有3种状态:领导leading,处理processing,追随following (2)假设共N个线程,其中只有1个leading线程( ...