对于在这里遇到同样问题但节点太多的人来说,这里对@Hooked的答案没有几个简单的改进(尽管我相信有更好的解决方案,正如@Hooked在评论中提到的那样,这只是一个快速的复制粘贴修复程序,适用于与我有相同原因并有缩放问题的人)
1)igraph比networkx更具规模
2)我们只能取一个节点的邻域来消除大多数不必要的组合
例如,如果我们在较大的network中寻找motif(两个igraph对象)motif_rank = max(max(motif.shortest_paths_dijkstra()))
result = collections.OrderedDict.fromkeys(network.vs['label'], 0)
for node in self.network.vs:
# Get relevant nodes around node of interest that might create the motif of interest
nodes_to_expand = {node}
for rank in range(motif_rank):
nodes_expanded = nodes_to_expand
for node_to_expand in nodes_to_expand:
nodes_expanded = set.union(nodes_expanded, set(node_to_expand.neighbors()))
nodes_to_expand = nodes_expanded
# Look at all combinations
for sub_nodes in itertools.combinations(nodes_to_expand, motif.vcount()):
subg = network.subgraph(sub_nodes)
if subg.is_connected() and subg.isomorphic(motif):
result[node['label']] = result[node['label']]+1