def local_path_index(G, ebunch=None):
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
#NeighborSet = nx.all_neighbors(G, u)
#len( sorted(nx.common_neighbors(G, u, v) ))
paths = list( nx.all_simple_paths(G, source=u, target=v, cutoff=3))
print paths
A2 = 0.0
A3 = 0.0
for path in paths:
if len(path) == 3:
A2 = A2 + 1.0
elif len(path) == 4:
A3 = A3 + 1.0
return A2 + 0.001 * A3 #Coefficient = 0.001
Rank_List = []
for u, v in ebunch:
Rank_List.append((u, v, predict(u, v)))
return Rank_List #((u, v, predict(u, v)) for u, v in ebunch)
#return ((u, v, predict(u, v)) for u, v in ebunch)
评论列表
文章目录