def test_GEMSEC(): """ Test the GEMSEC procedure. """ graph = nx.newman_watts_strogatz_graph(100, 5, 0.3) model = GEMSEC() 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 embedding = model.get_embedding() assert embedding.shape[0] == graph.number_of_nodes() assert embedding.shape[1] == model.dimensions
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) 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)
from karateclub.community_detection.overlapping import EgoNetSplitter, NNSED, DANMF, MNMF, BigClam, SymmNMF from karateclub.community_detection.non_overlapping import EdMot, LabelPropagation, SCD, GEMSEC from karateclub.graph_embedding import Graph2Vec, FGSD, GL2Vec, SF, NetLSD, GeoScattering from karateclub.node_embedding.attributed import BANE, TENE, TADW, FSCNMF, SINE, MUSAE from karateclub.node_embedding.structural import GraphWave, Role2Vec from karateclub.node_embedding.meta import NEU from karateclub.dataset import GraphReader, GraphSetReader #---------------- # GEMSEC example #---------------- g = nx.newman_watts_strogatz_graph(100, 20, 0.05) model = GEMSEC() model.fit(g) memberships = model.get_memberships() #------------------------------- # Geometric Scattering example #------------------------------- graphs = [nx.newman_watts_strogatz_graph(50, 5, 0.3) for _ in range(100)] model = GeoScattering() model.fit(graphs) embedding = model.get_embedding()
"""GEMSEC example.""" import networkx as nx from karateclub.community_detection.non_overlapping import GEMSEC g = nx.newman_watts_strogatz_graph(100, 20, 0.05) model = GEMSEC() model.fit(g)