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

在做东西的时候用到了社区发现,因此了解了一下有关社区发现的一些问题

1,社区发现算法

(1)SCAN:一种基于密度的社团发现算法

 Paper: 《SCAN: A Structural Clustering Algorithm for Networks》  Auther: Xiaowei Xu, Nurcan Yuruk, Zhidan Feng, Thomas A. J. Schweiger  Conference: SIGKDD 2007   

主要概念:

  • 节点相似度定义为两个节点共同邻居的数目与两个节点邻居数目的几何平均数的比值(这里的邻居均包含节点自身)。
  • 节点的 ϵ - 邻居定义为与其相似度不小于 ϵ 的节点所组成的集合
  • 核节点是指 ϵ 邻居的数目大于 μ 的节点。
  • 节点 w 是核节点 vϵ 邻居,那么称从 v 直接可达 w
  • 节点 v 可达 w ,当且仅当存在一个节点链 v1,,vnV,v1=v,vn=w,使得 vi+1 是 从vi 直接可达的。
  • 若核节点u可达节点v和节点w,则称节点v和节点w相连.

具体算法:

 

  • 对于每个未分配社团的节点 v ,检查 v 是否是核节点,是核节点则将其直接可达节点分配到一个社团中(社团标号记为该节点),并将其ϵ-邻居放进队列中,重复进行1步骤(类似于对直接可达节点进DFS)。
  • v 不是核节点则将其标志为non-member。
  • 最后检查所有的non-menber节点,若其相邻节点存在于两个及以上的社团中,则将其标为hub节点,否则标为outlier。

 

ALGORITHM SCAN(G=<V, E>, ε, μ)

// all vertices in V are labeled as unclassified;
for each unclassified vertex v ∈ V do
// STEP 1. check whether v is a core;
    if COREε,μ(v) then
// STEP 2.1. if v is a core, a new cluster is expanded;
        generate new clusterID;
        insert all x ∈ Nε (v) into queue Q;
        while Q ≠ 0 do
            y = first vertex in Q;
            R = {x ∈ V | DirREACHε,μ(y, x)};
            for each x ∈ R do
                if x is unclassified or non-member then
                    assign current clusterID to x;
                if x is unclassified then
                    insert x into queue Q;
            remove y from Q;
    else
// STEP 2.2. if v is not a core, it is labeled as non-member
        label v as non-member;
end for.
// STEP 3. further classifies non-members
for each non-member vertex v do
    if (∃ x, y ∈ Γ(v) ( x.clusterID ≠ y.clusterID) then
        label v as hub
    else
        label v as outlier;
end for.
end SCAN.

(2)复杂网络社区结构发现算法-基于python networkx clique渗透算法

Paper: G. Palla, I. Derényi, I. Farkas, and T. Vicsek, “Uncovering the overlapping community structure of complex networks in nature and society,” Nature, vol. 435, pp. 814-818, 2005.

clique渗透算法简介:

    对于一个图G而言,如果其中有一个完全子图(任意两个节点之间均存在边),节点数是k,那么这个完全子图就可称为一个k-clique。

    进而,如果两个k-clique之间存在k-1个共同的节点,那么就称这两个clique是“相邻”的。彼此相邻的这样一串clique构成最大集合,就可以称为一个社区(而且这样的社区是可以重叠的,即所谓的overlapping community,就是说有些节点可以同时属于多个社区)。下面第一组图表示两个3-clique形成了一个社区,第二组图是一个重叠社区的示意图。

2.NetWorkX安装使用和示例

NetworkX是一个用Python语言开发的图论与复杂网络建模工具,内置了常用的图与复杂网络分析算法,可以方便的进行复杂网络数据分析、仿真建模等工作。这里主要介绍clique渗透算法,

(1)安装

首先是软件的下载地址, https://pypi.python.org/pypi/networkx/,我下载的是whl文件

接着就是安装whl文件,具体安装过程网上有好多可以参考这个 windows7下怎样安装whl文件(python) 

接着安转完就是看如何执行算法了,我使用了pycharm IDE,我执行的是clique渗透算法,下边是这个算法的主要实现


"""Find k-clique communities in graph using the percolation method.

A k-clique community is the union of all cliques of size k that can be reached through adjacent (sharing k-1 nodes) k-cliques.
Parameters:

k (int) – Size of smallest clique
cliques (list or generator) – Precomputed cliques (use networkx.find_cliques(G))

Return type:

Yields sets of nodes, one for each k-clique community.
"""
import
networkx as nx import sys import time def find_community(graph,k): return list(nx.k_clique_communities(graph,k)) G = nx.Graph() ##testFile=open("F://2.txt","r") ##2-6 testFile=open("F://21.txt","r") ##5,10 for line in testFile: a=line.strip('\n').split(",") G.add_edge(a[0],a[1]) for k in range(5,10): print ("############# k值: %d ################" % k) start_time = time.clock() rst_com = find_community(G,k) end_time = time.clock() print ("计算耗时(秒):%.3f" % (end_time-start_time)) print ("生成的社区数:%d" % len(rst_com)) print(rst_com)

其中文件的格式是

a,b
c,d
a,c
a,d

3.gephi

Gephi是一款开源免费跨平台基于JVM的复杂网络分析软件, 其主要用于各种网络和复杂系统,动态和分层图的交互可视化与探测开源工具。

gephi.org, 可在官网上免费下载此软件。
目前gephi已有中文教程,网址为:udemy.com/gephi 。

 

 

参考文献:http://blog.csdn.net/DawnRanger/article/details/51108433

posted @ 2016-12-06 11:20  nolonely  阅读(13317)  评论(0编辑  收藏  举报