https://github.com/vandanparmar/MoNeRe
Tip revision: d0aa0acaccc3ce5917ac46482bec17adac5a9b25 authored by vandanparmar on 17 September 2018, 11:01:59 UTC
Update README.md
Update README.md
Tip revision: d0aa0ac
network_explore.py
'''To create a reduced network from a network.'''
def gen_sorted_node_list(G):
node_dict = dict(G.degree)
to_return = sorted(node_dict,key=node_dict.get,reverse=True)
return to_return
def reduce_graph(graphs):
key_nodes = []
for graph in graphs:
sorted_nodes = gen_sorted_node_list(graph)
accounted_for = set()
nodes = set(graph.nodes)
while accounted_for!=nodes:
node = sorted_nodes.pop(0)
key_nodes.append(node)
neighbours = set(graph[node].keys())
accounted_for.update(neighbours)
accounted_for.update([node])
graph.remove_node(node)
sorted_nodes = gen_sorted_node_list(graph)
return key_nodes