Python-louvain Package

pip install python-louvain

  1. import community
  2. #first compute the best partition
  3. partition = community.best_partition(G)

#Drawing partition

Method 1:

  1. #drawing
  2. size = float(len(set(partition.values())))
  3. pos = nx.spring_layout(G)
  4. count = 0.
  5. for com in set(partition.values()) :
  6. count = count + 1.
  7. list_nodes = [nodes for nodes in partition.keys()
  8. if partition[nodes] == com]
  9. nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20,
  10. node_color = str(count / size))
  11.  
  12. nx.draw_networkx_edges(G, pos, alpha=0.5)
  13. plt.show()

Method 2:

  1. pos = nx.spring_layout(G)
  2. values = [partition.get(node) for node in G.nodes()]
  3. 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)

  1. Returns
  2. -------
  3. partition : dictionnary
  4. The partition, with communities numbered from 0 to number of communities
  1. def best_partition(graph,
  2. partition=None,
  3. weight='weight',
  4. resolution=1.,
  5. randomize=None,
  6. random_state=None):
  7. """Compute the partition of the graph nodes which maximises the modularity
  8. (or try..) using the Louvain heuristices
  9.  
  10. This is the partition of highest modularity, i.e. the highest partition
  11. of the dendrogram generated by the Louvain algorithm.
  12.  
  13. Parameters
  14. ----------
  15. graph : networkx.Graph
  16. the networkx graph which is decomposed
  17. partition : dict, optional
  18. the algorithm will start using this partition of the nodes.
  19. It's a dictionary where keys are their nodes and values the communities
  20. weight : str, optional
  21. the key in graph to use as weight. Default to 'weight'
  22. resolution : double, optional
  23. Will change the size of the communities, default to 1.
  24. represents the time described in
  25. "Laplacian Dynamics and Multiscale Modular Structure in Networks",
  26. R. Lambiotte, J.-C. Delvenne, M. Barahona
  27. randomize : boolean, optional
  28. Will randomize the node evaluation order and the community evaluation
  29. order to get different partitions at each call
  30. random_state : int, RandomState instance or None, optional (default=None)
  31. If int, random_state is the seed used by the random number generator;
  32. If RandomState instance, random_state is the random number generator;
  33. If None, the random number generator is the RandomState instance used
  34. by `np.random`.
  35.  
  36. Returns
  37. -------
  38. partition : dictionnary
  39. The partition, with communities numbered from 0 to number of communities

COMMUNITY DETECTION_python-louvain的更多相关文章

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

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

  2. Louvain 算法原理

    Louvain算法是一种基于图数据的社区发现算法,算法的优化目标为最大化整个数据的模块度,模块度的计算如下: 其中m为图中边的总数量,k_i表示所有指向节点i的连边权重之和,k_j同理.A_{i,j} ...

  3. 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 ...

  4. Louvain algorithm for community detection

    主要理解Louvain 算法中对于模块度的定义:模块度是评估一个社区网络划分好坏的度量方法,它的物理含义是社区内节点的连边数与随机情况下的边数只差,它的取值范围是 [−1/2,1).可以简单地理解为社 ...

  5. [论文阅读笔记] LouvainNE Hierarchical Louvain Method for High Quality and Scalable Network Embedding

    [论文阅读笔记] LouvainNE: Hierarchical Louvain Method for High Quality and Scalable Network Embedding 本文结构 ...

  6. Louvain 论文笔记

    Louvain Introduce Louvain算法是社区发现领域中经典的基于模块度最优化的方法,且是目前市场上最常用的社区发现算法.社区发现旨在发现图结构中存在的类簇(而非传统的向量空间). Al ...

  7. 并行Louvain社区检测算法

    因为在我最近的科研中需要用到分布式的社区检测(也称为图聚类(graph clustering))算法,专门去查找了相关文献对其进行了学习.下面我们就以这篇论文IPDPS2018的文章[1]为例介绍并行 ...

  8. conda安装包

    前面讲了有关conda改变镜像提高安装速度,这里来解决很多实用C写的酷,在Windows下不好安装的解决方案 1. 寻找wheel预编译文件 没有的话 2.使用conda命令安装 没有该包的话 3.实 ...

  9. Hadoop 全分布模式 平台搭建

    现将博客搬家至CSDN,博主改去CSDN玩玩~ 传送门:http://blog.csdn.net/sinat_28177969/article/details/54138163 Ps:主要答疑区在本帖 ...

  10. {ICIP2014}{收录论文列表}

    This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...

随机推荐

  1. linux系统挂载u盘拷贝文件

    linux系统在不能远程的情况下用u盘传文件(比如服务器装上系统还没配IP),需要先将u盘挂载到系统中的某个位置,再使用cp命令拷贝文件,简要步骤如下: 1.把U盘插入Linux电脑,确保U盘指示灯是 ...

  2. 【sklearn朴素贝叶斯算法】高斯分布/多项式/伯努利贝叶斯算法以及代码实例

    朴素贝叶斯 朴素贝叶斯方法是一组基于贝叶斯定理的监督学习算法,其"朴素"假设是:给定类别变量的每一对特征之间条件独立.贝叶斯定理描述了如下关系: 给定类别变量\(y\)以及属性值向 ...

  3. SURF特征检测

    SERF(speed up robust feature )特征的关键特性: 特征检测 尺度空间:缩放到不同的大小或分辨率仍能检测 选择不变性:光照不变,旋转不变 特征向量:描述为一个特征向量 DDN ...

  4. 【Jmeter】jmeter提取response中的返回值,并保存到本地文件--BeanShell后置处理器

    有个需求,需要在压测环境中,创建几十万的账号数据,然后再根据创建结果,查询到某些账号信息. 按照之前我的做法,直接Python调用API,然后再数据库查询: 但是近期所有开发人员的数据库访问权限被限制 ...

  5. R语言的内存(小总结)

    memory.size()----->查看当前的内存的使用情况. memory.limit()------->当前的工作空间的最大内存容量. ls()-------->查看当前的内存 ...

  6. 回味Ubuntu10.10致敬Gnome桌面

    目录 Ubuntu10.10可用源 Ubuntu10.10更新语言包 输入法支持 浏览器选择 文件下载 压缩文件中文乱码的处理 视频播放 科学计算 搭建Lamp环境 实现文件分享 主题美化 Ubunt ...

  7. pandas玩转excel-> (1)如何利用pandas创建【行,列,单元格】

    import pandas as pd #------新建单元格的方法一:通过先创建字典的形式 #可以先新建一个字典d={'x':100,'y':200,'z':300} #打印字典的索引print( ...

  8. P5331 [SNOI2019]通信 [线段树优化建图+最小费用最大流]

    这题真让人自闭-我EK费用流已经死了?- (去掉define int long long就过了) 我建的边害死我的 spfa 还是spfa已经死了? 按费用流的套路来 首先呢 把点 \(i\) 拆成两 ...

  9. Linux的常用命令---这是对Linux最基本的尊重

    Linux: 诞生日期:1991年 开发者:林纳斯·托瓦茨 特点:免费,开源 发行版本:centos|red Hat|Ubuntu|红旗等 思想:一切都是文件 重要文件目录 bin:二进制文件(命令) ...

  10. 1080 Graduate Admission

    大致题意就是有N个学生,有M个学校,每个学校的名额都是正整数.每个学生可以填K个学校志愿,N个学生一起排名以后,排名高的学生先挑学校,不保护一志愿. 题目要求: 首先,把所有学生按总成绩SUM(GE+ ...