社区(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算法的更多相关文章

  1. SLAP(Speaker-Listener Label Propagation Algorithm)社区发现算法

    其中部分转载的社区发现SLPA算法文章 一.概念 社区(community)定义:同一社区内的节点与节点之间关系紧密,而社区与社区之间的关系稀疏. 设图G=G(V,E),所谓社区发现是指在图G中确定n ...

  2. 网络科学 - 社区发现 Community structure and detection及其几个实现工具

    首先什么是社区(Community structure)呢?其实并不是指一个网络相互连接的部分,而是一个网络中链接“紧密的部分”,至于怎么定义紧密就有很多方法了. 社区发现算法可以参考下面的博客:博客 ...

  3. 社区发现(Community Detection)算法 [转]

    作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...

  4. 社区发现(Community Detection)算法(转)

    作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...

  5. 社区发现(Community Detection)算法

    作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...

  6. 模块度与Louvain社区发现算法

    Louvain算法是基于模块度的社区发现算法,该算法在效率和效果上都表现较好,并且能够发现层次性的社区结构,其优化目标是最大化整个社区网络的模块度. 模块度(Modularity) 模块度是评估一个社 ...

  7. 社区发现算法问题&&NetworkX&&Gephi

    在做东西的时候用到了社区发现,因此了解了一下有关社区发现的一些问题 1,社区发现算法 (1)SCAN:一种基于密度的社团发现算法 Paper: <SCAN: A Structural Clust ...

  8. 社区发现算法 - Fast Unfolding(Louvian)算法初探

    1. 社团划分 0x1:社区是什么 在社交网络中,用户相当于每一个点,用户之间通过互相的关注关系构成了整个网络的结构. 在这样的网络中,有的用户之间的连接较为紧密,有的用户之间的连接关系较为稀疏.其中 ...

  9. Top Leaders社区发现算法(top leaders community detection approach in information networks)

    一.概念 复杂网络:现实生活中各种系统都可以看做成复杂网络,复杂网络构成包括节点和边,节点是网络中的基本组成单元,节点之间的联系或者关系是网络中的边.例如 电力网络:基站代表节点,基站之间是否互通表示 ...

随机推荐

  1. 3-java_string学习笔记:

    java中String的常用方法

  2. 1-为什么java的main方法必须是静态的

    为什么java的main方法必须是静态的   今天看类型信息时发现一个问题,不能再main方法中打印this关键字的信息,这时想起了之前的知识,不能再静态方法中调用this.理由很简单,this表示“ ...

  3. 解析config文件 练手代码

    解析一个如下的CONFIG文件 #config.txt #SHTTPD Web 服务器配置文件示例 #侦听端口 ListenPort = 80 #最大并发访问客户端数目 MaxClient = 8 # ...

  4. centos 7 安装最新版本git

    https://serverfault.com/questions/709433/install-a-newer-version-of-git-on-centos-7 You could use a  ...

  5. word生成包含echarts图形使用phantomjs,支持word2003,2007

    代码具体地址在我的github上 :https://github.com/HaoTwoDonkey/QuickOutPutWord 写得不好,欢迎提出问题 下面说几个phantomjs使用过程中遇到的 ...

  6. Mysql 关于not exists一例

    场景: 业务上需要做一个查询,因为是Web及时响应,所以对响应时间有要求,原业务场景是需要从无库存订单中剔除绑定闲置库存,因单条sql查询实现复杂,故考虑用差集方式: select a.col1, a ...

  7. checkbox数据回显问题

    一.问题 在用复选框的时候,最常用的无非就是全选,全不选,数据回显等问题!要做的比较灵活!最近做项目的时候,就遇到这些问题,下面从js和JQueyr两方面解决一下全选,全不选,数据回显的问题. 二.H ...

  8. eclipse中maven install提示编码GBK的不可映射字符

    今天在eclipse中使用Maven编译项目源代码时,结果如下了如下的错误 在Java源码中没有提示任何报错,即便是改掉项目编码也是不行,如下图所示:

  9. eclipse启动tomcat出现内存溢出错误 java.lang.OutOfMemoryError: PermGen space

    发布工程后,启动tomcat出现如下内存溢出错误: java.lang.OutOfMemoryError: PermGen space ... java.lang.OutOfMemoryError: ...

  10. POJ1789 Truck History 2017-04-13 12:02 33人阅读 评论(0) 收藏

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27335   Accepted: 10634 D ...