def test_label_propagation(): """ Test Label Propagation procedure. """ graph = nx.newman_watts_strogatz_graph(50, 5, 0.3) model = LabelPropagation() model.fit(graph) memberships = model.get_memberships() indices = [k for k, v in memberships.items()].sort() nodes = [node for node in graph.nodes()].sort() assert graph.number_of_nodes() == len(memberships) assert indices == nodes assert type(memberships) == dict graph = nx.newman_watts_strogatz_graph(150, 5, 0.3) model = LabelPropagation() model.fit(graph) memberships = model.get_memberships() indices = [k for k, v in memberships.items()].sort() nodes = [node for node in graph.nodes()].sort() assert graph.number_of_nodes() == len(memberships) assert indices == nodes assert type(memberships) == dict
def labelPropagation(population, neighbors, probability): g = nx.newman_watts_strogatz_graph(population, neighbors, probability) model = LabelPropagation() model.fit(g) #print(model.get_memberships()) return [model.get_memberships()]
for num in nums: file = open( str(path) + str(os.sep) + str(alg_name) + "_" + str(num) + ".csv", "w") csvwriter = csv.writer(file) csvwriter.writerow(['comm', 'size']) reader = GraphReader("twitch%s" % num) graph = reader.get_graph() if alg_name == 'label': model = LabelPropagation() elif alg_name == 'edmot': model = EdMot() elif alg_name == 'gemsec': model = GEMSEC() elif alg_name == 'scd': model = SCD() l = {} model.fit(graph) cluster_membership = model.get_memberships() for key in sorted(cluster_membership.keys()): try: l[cluster_membership[key]].add(key) except: l[cluster_membership[key]] = {key} tot = 0 for key in sorted(l.keys()): csvwriter.writerow([key, len(l[key])]) tot += len(l[key]) print(tot) file.flush() file.close()