def test_edmot(): """ Test the EdMot procedure. """ graph = nx.newman_watts_strogatz_graph(50, 5, 0.3) model = EdMot() 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 = EdMot() 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
for num in nums: reader = GraphReader("twitch%s" % num) graph = reader.get_graph() target = reader.get_target() d = {} model = LabelPropagation() comms = run(model, graph) coeffs = [] for key in sorted(comms.keys()): sub = graph.subgraph(list(comms[key])) coeff = nx.average_clustering(sub) coeffs.append(coeff) avg_coeff = sum(coeffs) / len(coeffs) d['label'] = avg_coeff model = EdMot() comms = run(model, graph) coeffs = [] for key in sorted(comms.keys()): sub = graph.subgraph(list(comms[key])) coeff = nx.average_clustering(sub) coeffs.append(coeff) avg_coeff = sum(coeffs) / len(coeffs) d['edmot'] = avg_coeff model = GEMSEC() comms = run(model, graph) coeffs = [] for key in sorted(comms.keys()): sub = graph.subgraph(list(comms[key])) coeff = nx.average_clustering(sub)
# Splitter example #------------------- g = nx.newman_watts_strogatz_graph(100, 20, 0.05) model = EgoNetSplitter(1.0) model.fit(g) #---------------- # Edmot example #---------------- g = nx.newman_watts_strogatz_graph(100, 10, 0.9) model = EdMot(3, 0.5) model.fit(g) #---------------- # DANMF example #---------------- g = nx.newman_watts_strogatz_graph(100, 10, 0.02) model = DANMF() model.fit(g) #---------------- # M-NMF example
def edmot(population, neighbors, probability): g = nx.newman_watts_strogatz_graph(population, neighbors, probability) model = EdMot(3, 0.5) model.fit(g) #print(model.get_memberships()) return [model.get_memberships()]