社區發現算法問題&&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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM