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的更多相关文章

  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. H5测试方法

    一 功能测试 1 关注页面请求:请求数据是否正确,相应是否正确,是否有重复请求,造成流量浪费,响应速度变慢 2 关注application cache:cokkie值是否正确,清除cokkie后表现是 ...

  2. 剑指offer-面试题47-礼物的最大价值-动态规划

    /* 题目: 给定一个m*n的棋盘,每格放一个礼物(每个礼物的值大于0), 从左上角出发,向下或向右走到达右下角,得到的礼物和最大. */ /* 思路: f(i,j)=max[f(i-1,j),f(i ...

  3. BundlePhobia

    1.BundlePhobia用于分析npm package的依赖.bundle后的大小.下载速度预估等等,帮助你在引用一个package之前了解引入该package的代价. 2.也可以将项目的pack ...

  4. 使用Python库paramiko登录远程设备

    前言 手动下载paramiko库的安装包.在PyPi库中查找即可,但是不到是我的电脑问题还是网络问题,2.0.0以上版本我都安装不了,因此我自己是安装的paramiko 1.17.0版本,此版本经过测 ...

  5. GitKraken 快速配置 SSH Key

    快速使用 GitKraken 配置SSH keys git是现在最流行的版本管理工具,应用范围非常广泛,推荐一款git的可视化工具,这款 工具特别方便 它的官方如下https://www.gitkra ...

  6. fiddler使用post方法带参数(base64)请求接口,模拟表单提交,类似工具postman

    头格式如下: Content-Length: Content-Type: multipart/form-data; boundary=-------------------------- Host: ...

  7. 数据结构与算法之比较排序【Java】

    比较排序与非比较排序的对比 常见的快速排序.归并排序.堆排序.冒泡排序等属于比较排序.在排序的最终结果里,元素之间的次序依赖于它们之间的比较.每个数都必须和其他数进行比较,才能确定自己的位置.在冒泡排 ...

  8. Python GUI编程(TKinter)(简易计算器)

    搞课设搞得心累,现在看到人脸这两个字就烦躁,无聊搞搞tkinter,实现一个计算器的功能,能够简单的加减乘除. 简单的页面如下: 简单的代码如下: # encoding:utf-8 import tk ...

  9. jmeter测试出现端口占用

    原文地址:https://www.cnblogs.com/deepSleeping/p/12067654.html Jmeter测试会出现端口占用情况 这边在这里做个记录,每次都要百度查询,刚好需要整 ...

  10. ubantu crontab定时任务设置

    Lynx浏览器安装.安装命令:sudo apt-get install lynx.打开终端输入:crontab -e若初次执行会出现以下(选择编译器,一般选4(Vim))Select an edito ...