def test_scd(): """ Test the SCD procedure. """ graph = nx.newman_watts_strogatz_graph(50, 5, 0.3) model = SCD() 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 = SCD() 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
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) coeffs.append(coeff) avg_coeff = sum(coeffs) / len(coeffs) d['gemsec'] = avg_coeff model = SCD() 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['scd'] = avg_coeff print(d) path = os.getcwd() #os.makedirs(str(path)+str(os.sep)+"scores") file = open(str(path) + "/scores/cluster_coeff-%s.csv" % num, "w") cs = csv.writer(file) cs.writerow(['graph', "algo", "cluster_coeff"]) for key in d.keys():
from karateclub.node_embedding.neighbourhood import GraRep, DeepWalk, Walklets, NMFADMM, Diff2Vec, BoostNE, NetMF from karateclub.community_detection.overlapping import EgoNetSplitter, NNSED, DANMF, MNMF, BigClam, SymmNMF from karateclub.community_detection.non_overlapping import EdMot, LabelPropagation, SCD from karateclub.graph_embedding import Graph2Vec, FGSD, GL2Vec, SF from karateclub.node_embedding.attributed import BANE, TENE, TADW, FSCNMF from karateclub.node_embedding.structural import GraphWave, Role2Vec from karateclub.dataset import GraphReader, GraphSetReader #------------------------------------ # SCD example #------------------------------------ g = nx.newman_watts_strogatz_graph(100, 10, 0.2) model = SCD() model.fit(g) model.get_memberships() #------------------------------------ # Symm-NMF example #------------------------------------ g = nx.newman_watts_strogatz_graph(100, 10, 0.2) model = SymmNMF() model.fit(g)
"""SCD example.""" import networkx as nx from karateclub.community_detection.non_overlapping import SCD g = nx.newman_watts_strogatz_graph(100, 20, 0.05) model = SCD() model.fit(g)