电竞比分网-中国电竞赛事及体育赛事平台

分享

科學網(wǎng)—復雜網(wǎng)絡分析庫NetworkX學習筆記(2):統(tǒng)計指標計算

 londonKu 2012-11-19
無論是實際網(wǎng)絡還是對模型網(wǎng)絡進行分析,都離不開對網(wǎng)絡拓撲統(tǒng)計指標的計算。反映網(wǎng)絡結構與動力學特性的統(tǒng)計指標有很多,Costa等的Characterization of Complex Networks: A Survey of measurements一文對此有全面的綜述,本文僅介紹一些常用的統(tǒng)計指標在NetworkX中如何計算。

一、度、度分布

NetworkX可以用來統(tǒng)計圖中每個節(jié)點的度,并生成度分布序列。下邊是一段示例代碼(這段代碼可以在Shell里一行一行的輸入,也可以將其保存為一個以py結尾的純文本文件后直接運行),注意看注釋部分:

import networkx as nx
G = nx.random_graphs.barabasi_albert_graph(1000,3)   #生成一個n=1000,m=3的BA無標度網(wǎng)絡
print G.degree(0)                                   #返回某個節(jié)點的度
print G.degree()                                     #返回所有節(jié)點的度
print nx.degree_histogram(G)    #返回圖中所有節(jié)點的度分布序列(從1至最大度的出現(xiàn)頻次)


對上述結果稍作處理,就可以在Origin等軟件里繪制度分布曲線了,當然也可以用matplotlib直接作圖,在上述代碼后接著輸入:

import matplotlib.pyplot as plt                 #導入科學繪圖的matplotlib包
degree =  nx.degree_histogram(G)          #返回圖中所有節(jié)點的度分布序列
x = range(len(degree))                             #生成x軸序列,從1到最大度
y = [z / float(sum(degree)) for z in degree] 
#將頻次轉換為頻率,這用到Python的一個小技巧:列表內涵,Python的確很方便:)
plt.loglog(x,y,color="blue",linewidth=2)           #在雙對數(shù)坐標軸上繪制度分布曲線 
plt.show()                                                          #顯示圖表


二、群聚系數(shù)

這個在NetworkX里實現(xiàn)起來很簡單,只需要調用方法nx.average_clustering(G) 就可以完成平均群聚系數(shù)的計算,而調用nx.clustering(G) 則可以計算各個節(jié)點的群聚系數(shù)。

三、直徑和平均距離

nx.diameter(G)返回圖G的直徑(最長最短路徑的長度),而nx.average_shortest_path_length(G)則返回圖G所有節(jié)點間平均最短路徑長度。

四、匹配性

這個也比較簡單,調用 nx.degree_assortativity(G) 方法可以計算一個圖的度匹配性。

五、中心性

這個我大部分不知道怎么翻譯,直接上NX的幫助文檔吧,需要計算哪方面的centrality自己從里邊找:)

Degree centrality measures.(點度中心性?)
degree_centrality(G)     Compute the degree centrality for nodes.
in_degree_centrality(G)     Compute the in-degree centrality for nodes.
out_degree_centrality(G)     Compute the out-degree centrality for nodes.

Closeness centrality measures.(緊密中心性?)
closeness_centrality(G[, v, weighted_edges])     Compute closeness centrality for nodes.

Betweenness centrality measures.(介數(shù)中心性?)
betweenness_centrality(G[, normalized, ...])     Compute betweenness centrality for nodes.
edge_betweenness_centrality(G[, normalized, ...])     Compute betweenness centrality for edges.

Current-flow closeness centrality measures.(流緊密中心性?)
current_flow_closeness_centrality(G[, ...])     Compute current-flow closeness centrality for nodes.
Current-Flow Betweenness

Current-flow betweenness centrality measures.(流介數(shù)中心性?)
current_flow_betweenness_centrality(G[, ...])     Compute current-flow betweenness centrality for nodes.
edge_current_flow_betweenness_centrality(G)     Compute current-flow betweenness centrality for edges.

Eigenvector centrality.(特征向量中心性?)
eigenvector_centrality(G[, max_iter, tol, ...])     Compute the eigenvector centrality for the graph G.
eigenvector_centrality_numpy(G)     Compute the eigenvector centrality for the graph G.

Load centrality.(徹底暈菜~~~)
load_centrality(G[, v, cutoff, normalized, ...])     Compute load centrality for nodes.
edge_load(G[, nodes, cutoff])     Compute edge load.


六、小結

上邊介紹的統(tǒng)計指標只是NetworkX能計算的指標中的一小部分內容,除此之外NetworkX還提供了很多(我還沒有用到過的)統(tǒng)計指標計算方法,感興趣的朋友可以去查NetworkX的在線幫助文檔:http://networkx./reference/index.html。對于加權圖的統(tǒng)計指標計算,NetworkX似乎沒有直接提供方法(也可能是我沒找到),估計需要自己動手編制一些程序來完成。

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多