社区发现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)
一.概念 复杂网络:现实生活中各种系统都可以看做成复杂网络,复杂网络构成包括节点和边,节点是网络中的基本组成单元,节点之间的联系或者关系是网络中的边.例如 电力网络:基站代表节点,基站之间是否互通表示 ...
随机推荐
- Docker RestApi Create mysql Container
docker 提供了创建容器的rest api http://192.168.150.6:8888/containers/create?name=demo-mysql docker mysql容器的参 ...
- 38-解决Fiddler查看Post参数中文乱码的问题
转载自:https://blog.csdn.net/JusterDu/article/details/50888617 解决Fiddler查看Post参数中文乱码的问题 2016年03月14日 18: ...
- Intellij Idea notes
1. 解决intellij idea国际化配置文件resource bundle中文乱码问题 https://blog.csdn.net/u012453843/article/details/7531 ...
- jetty tutorial
http://www.eclipse.org/jetty/documentation/current/embedding-jetty.html#d0e18726 Version: 9.2.2-SNAP ...
- 安装scrapy解决的坑
在windows下: pip install scrapy 最后一步报错: 本来以为是缺少 Microsoft Visual C++ 14.0 这个库,一看下载需要400多M,算了再看下报错... 感 ...
- 10 Consensus and Profile
Problem A matrix is a rectangular table of values divided into rows and columns. An m×nm×n matrix ha ...
- Vivado 2017封装自定义IP Core
使用Vivado2017.3自定义IP Core.通常情况下,我们做设计采用模块化设计,对于已经设计好的一部分模块功能,就可以直接拿来调用,IP Core就是这样来的,一般来说我们看不到IP Core ...
- URAL 1996 Cipher Message 3 (FFT + KMP)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意 :给出两个串A , B,每个串是若干个byt ...
- npm 安装less
npm install less less-loader --save 在style加上lang="less" 就可以直接用了
- C#用 catch 捕获异类的常用类型
C#用 catch 捕获异类的常用类型 最近在书上刚刚学到了try和catch用法,然后网上找了下常用的,自己存在这里方便自己查找 Exception 类 描述 SystemException 其他 ...