
284
13
章 グラフ分析
unfinished_nodes = list(g.nodes)
component_index = 0
while len(unfinished_nodes) != 0:
node_list = [unfinished_nodes[0]]
while len(node_list) != 0:
current_node = node_list.pop()
if current_node in unfinished_nodes:
unfinished_nodes.remove(current_node)
component_table[current_node] = component_index
for i i
n g.neighbors(current_node):
node_list.insert(0, i)
component_index += 1
return component_table
13.4
クラスタ係数
グラフのノード間の関係を測る別のメカニズムとしてクラスタ係数がある。クラスタ係数は、グラ
フ上にある特定のノードの任意の2 つの隣接ノードが互いの隣接ノードである確率である。例13-5
にクラスタ係数を求めるコードを示す。
例13-5 クラスタ係数の計算
def calculate_clustering_coefficients(g):
#
ノードのクラスタ係数は
#
そのノードの隣接ノードも互いに隣接ノードである割合である。
node_ccs ...