Skip to content

Instantly share code, notes, and snippets.

@maxfischer2781
Created January 29, 2017 09:23
Show Gist options
  • Save maxfischer2781/2e8ca9729829e6baf944428805959d09 to your computer and use it in GitHub Desktop.
Save maxfischer2781/2e8ca9729829e6baf944428805959d09 to your computer and use it in GitHub Desktop.
import argparse
from matplotlib import pyplot
from dengraph import dengraph
from dengraph.graphs import graph_io
CLI = argparse.ArgumentParser()
CLI.add_argument('--csv', help='csv inout file')
CLI.add_argument('-d', '--distance', help='maximum distance between nodes', default=1, type=float)
CLI.add_argument('-n', '--neighbours', help='neighbours required for cores', default=5, type=float)
options = CLI.parse_args()
with open(options.csv) as csv_file:
graph = graph_io.csv_graph_reader((ln for ln in csv_file if ln[0] != '#' and ln != '\n'), nodes_header=True, symmetric=True)
#pyplot.hist([dist for node in graph for dist in graph[node].values()], bins=200)
if False:
xs, ys = [], []
for node in graph:
for r in range(100):
dst = r/100
xs.append(dst)
ys.append(len(list(graph.get_neighbours(node, dst))))
pyplot.hist2d(xs, ys, bins=(100, 250))
pyplot.show()
clustering = dengraph.DenGraphIO(graph, core_neighbours=options.neighbours, cluster_distance=options.distance)
for idx, cluster in enumerate(clustering):
print(idx, len(cluster))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment