COMMUNITY DETECTION_python-louvain
Python-louvain Package
pip install python-louvain
import community
#first compute the best partition
partition = community.best_partition(G)
#Drawing partition
Method 1:
#drawing
size = float(len(set(partition.values())))
pos = nx.spring_layout(G)
count = 0.
for com in set(partition.values()) :
count = count + 1.
list_nodes = [nodes for nodes in partition.keys()
if partition[nodes] == com]
nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20,
node_color = str(count / size)) nx.draw_networkx_edges(G, pos, alpha=0.5)
plt.show()
Method 2:
pos = nx.spring_layout(G)
values = [partition.get(node) for node in G.nodes()]
nx.draw_networkx(G, pos, cmap=plt.get_cmap('magma'), node_color=values, node_size=50, with_labels=False)
Supplementary knowledge:
1. what is the partition of graphs.
partition: dict; {key (nodes_id): values(community_id)}
2. function : community.best_partition(G)
Returns
-------
partition : dictionnary
The partition, with communities numbered from 0 to number of communities
def best_partition(graph,
partition=None,
weight='weight',
resolution=1.,
randomize=None,
random_state=None):
"""Compute the partition of the graph nodes which maximises the modularity
(or try..) using the Louvain heuristices This is the partition of highest modularity, i.e. the highest partition
of the dendrogram generated by the Louvain algorithm. Parameters
----------
graph : networkx.Graph
the networkx graph which is decomposed
partition : dict, optional
the algorithm will start using this partition of the nodes.
It's a dictionary where keys are their nodes and values the communities
weight : str, optional
the key in graph to use as weight. Default to 'weight'
resolution : double, optional
Will change the size of the communities, default to 1.
represents the time described in
"Laplacian Dynamics and Multiscale Modular Structure in Networks",
R. Lambiotte, J.-C. Delvenne, M. Barahona
randomize : boolean, optional
Will randomize the node evaluation order and the community evaluation
order to get different partitions at each call
random_state : int, RandomState instance or None, optional (default=None)
If int, random_state is the seed used by the random number generator;
If RandomState instance, random_state is the random number generator;
If None, the random number generator is the RandomState instance used
by `np.random`. Returns
-------
partition : dictionnary
The partition, with communities numbered from 0 to number of communities
COMMUNITY DETECTION_python-louvain的更多相关文章
- 模块度与Louvain社区发现算法
Louvain算法是基于模块度的社区发现算法,该算法在效率和效果上都表现较好,并且能够发现层次性的社区结构,其优化目标是最大化整个社区网络的模块度. 模块度(Modularity) 模块度是评估一个社 ...
- Louvain 算法原理
Louvain算法是一种基于图数据的社区发现算法,算法的优化目标为最大化整个数据的模块度,模块度的计算如下: 其中m为图中边的总数量,k_i表示所有指向节点i的连边权重之和,k_j同理.A_{i,j} ...
- Louvain Modularity Fast unfolding of communities in large networks
Louvain Modularity Fast unfolding of communities in large networks https://arxiv.org/pdf/0803.0476.p ...
- Louvain algorithm for community detection
主要理解Louvain 算法中对于模块度的定义:模块度是评估一个社区网络划分好坏的度量方法,它的物理含义是社区内节点的连边数与随机情况下的边数只差,它的取值范围是 [−1/2,1).可以简单地理解为社 ...
- [论文阅读笔记] LouvainNE Hierarchical Louvain Method for High Quality and Scalable Network Embedding
[论文阅读笔记] LouvainNE: Hierarchical Louvain Method for High Quality and Scalable Network Embedding 本文结构 ...
- Louvain 论文笔记
Louvain Introduce Louvain算法是社区发现领域中经典的基于模块度最优化的方法,且是目前市场上最常用的社区发现算法.社区发现旨在发现图结构中存在的类簇(而非传统的向量空间). Al ...
- 并行Louvain社区检测算法
因为在我最近的科研中需要用到分布式的社区检测(也称为图聚类(graph clustering))算法,专门去查找了相关文献对其进行了学习.下面我们就以这篇论文IPDPS2018的文章[1]为例介绍并行 ...
- conda安装包
前面讲了有关conda改变镜像提高安装速度,这里来解决很多实用C写的酷,在Windows下不好安装的解决方案 1. 寻找wheel预编译文件 没有的话 2.使用conda命令安装 没有该包的话 3.实 ...
- Hadoop 全分布模式 平台搭建
现将博客搬家至CSDN,博主改去CSDN玩玩~ 传送门:http://blog.csdn.net/sinat_28177969/article/details/54138163 Ps:主要答疑区在本帖 ...
- {ICIP2014}{收录论文列表}
This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...
随机推荐
- C#设计模式学习笔记:(3)抽象工厂模式
本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7596897.html,记录一下学习过程以备后续查用. 一.引言 接上一篇C#设计模式学习笔记:简单工厂模式( ...
- P5016 龙虎斗
链接:P5016 ------------------------------------ 作为2019年的模拟,还是有必要写一些的 --------------------------------- ...
- SP1805 HISTOGRA - Largest Rectangle in a Histogram
--------------------------------------------------- 我就是想学个单调栈然后全网都是个蓝题 ----------------------------- ...
- Django---Django连接Mysql数据库
前面介绍了Django平台的数据交互,这些数据都是在本地存放着,修改内容或者重新启动服务,数据就消失了,如果我们把数据存放在数据库中,不就保存了吗? Django数据库 Django中自带的也有数据库 ...
- C语言程序设计(实验一)
实验项目:1.3.2,1.3.3,1.3.4,2.3.1,2.3.2 姓名:邹琼 实验地点:家 实验时间:2020年2月28日 一.实验目的与要求 1.实验目的 掌握DEVC++的安装方法,并实现 ...
- sql查询如何将A表数据name字段对应B表name字段得到对应的B表id主键然后添加A到表usel_id中
1.写这个的原因 最近在写公司项目的时候一个功能很是让我头疼如标题看到的一样,平时我们一般都只负责数据表的查询或者连表查询某一个字段和A表字段一起显示出来. 但是添加到A表还是头一次,第一天想了很久都 ...
- html+layui
添加html+layui项目 先引用一个js文件 <form class="layui-form" action=""> <link href ...
- pyqt5-下拉框联动效果
from PyQt5.Qt import * class MyWindow(QWidget): def __init__(self): super().__init__() self.setWindo ...
- Python3 基本语法 学习笔记
如何定义python源文件的文件编码 如果想要定义文件代码的编码,一个特殊的注释应该放到源文件的第一或第二行,例如: # coding=<encoding name> 或 使用一种大多数编 ...
- Gerrit评审代码流程注意事项
Gerrit管理CR流程时要注意下面两大事项: (一)格式规范 这部分主要是根据公司或者团队的要求规范来撰写格式,这里不做统一介绍了:格式规范的宗旨是让修改的代码和业务需求能够匹配.可追溯. (二)评 ...