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 ...
随机推荐
- java设计模式学习笔记--依赖倒转原则
依赖倒转原则简述 1.高层模块不应该依赖低层模块,二者都应该依赖其抽象 2.抽象不应该依赖细节,细节应该依赖抽象 3.依赖倒转得中心思想时面向接口编程 4.依赖倒转原则时基于这样得设计理念:相对于细节 ...
- jQuery---钢琴案例 (按下1-9数字键,能触发对应的mouseenter事件)
钢琴案例 (按下1-9数字键,能触发对应的mouseenter事件) 1. 结合之前的学习,主要内容,就是on注册keyup事件,函数里传入e, 用e.keyCode,来获取1-9的数字的范围. 如果 ...
- 【sklearn朴素贝叶斯算法】高斯分布/多项式/伯努利贝叶斯算法以及代码实例
朴素贝叶斯 朴素贝叶斯方法是一组基于贝叶斯定理的监督学习算法,其"朴素"假设是:给定类别变量的每一对特征之间条件独立.贝叶斯定理描述了如下关系: 给定类别变量\(y\)以及属性值向 ...
- js打印前几天或后几天的日期
<script language="JavaScript" type="text/javascript">function dater(sj){ v ...
- pyqt5-字体,颜色选择对话框设置label标签字体颜色样式
1.采用实例方法,先创建2个dialog对象,采用该对象的信号触发相应的操作 import sys from PyQt5.Qt import * class MyWidget(QWidget): de ...
- Python带你来一次说走就走的环球旅行
image 1.目 标 场 景 十一长假,相信大部分的朋友这会应该是在全国各地浪或者是在浪的路上,朋友圈成为你们表演的场所. 当然,也有一小戳朋友是选择家里蹲,你们是否感觉到无聊?是否想出去浪,参 ...
- JavaScirpt 认识DOM和BOM (汇总)
将HTML代码分解为DOM节点层次图 DOM节点有: 1. 元素节点:上图中<html>.<body>.<p>等都是元素节点,即标签. 2. 文本节点:向用户展示的 ...
- vitualbox安装centos7卡死
在用vitualbox安装centos7的时候,每次到配置页面,都会莫名卡死,试了几遍才发现不是卡死,而是弹窗用鼠标点击是没用的,需要用tab键和回车来选中执行.
- Java代码中特殊注释
Java代码中特殊注释 TODO: + 说明:标识处有功能代码待编写,待实现的功能在说明中会简略说明. FIXME: + 说明:标识处代码需要修正,甚至代码是错误的,不能工作,需要修复,如何修正会在说 ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) (模拟)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...