Created
January 29, 2017 09:23
-
-
Save maxfischer2781/2e8ca9729829e6baf944428805959d09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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