def check_similarity(filename_a, filename_b, expected_similarity):
expected_similarity = float(expected_similarity)
assert expected_similarity <= 1.0
def sizeof_graph(g):
return len(g.nodes())
G_a = get_graph_from_filename(filename_a)
G_b = get_graph_from_filename(filename_b)
# always a < b
if sizeof_graph(G_a) > sizeof_graph(G_b):
G_a, G_b = G_b, G_a
length = int((sizeof_graph(G_a) + sizeof_graph(G_b)) / 2.0 * expected_similarity)
# print('length = %s, G_a_size = %s, G_b_size = %s' %(length, G_a_size, G_b_size))
if length > sizeof_graph(G_a):
# size difference too high, return false directly
return False
count = 0
for subgraphs in subgraphs_product(G_a, G_b, length):
count += 1
# print(count)
if nx.is_isomorphic(subgraphs[0], subgraphs[1]):
return True
return False
network_similarity.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录