コード例 #1
0
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
    assert type(memberships) == dict

    embedding = model.get_embedding()

    assert embedding.shape[0] == graph.number_of_nodes()
    assert embedding.shape[1] == model.dimensions
    assert type(embedding) == np.ndarray

    graph = nx.newman_watts_strogatz_graph(150, 5, 0.3)

    model = GEMSEC(dimensions=4)

    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

    embedding = model.get_embedding()

    assert embedding.shape[0] == graph.number_of_nodes()
    assert embedding.shape[1] == model.dimensions
    assert type(embedding) == np.ndarray
コード例 #2
0
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()

#--------------------
# NodeSketch example
コード例 #3
0
ファイル: gemsec_example.py プロジェクト: zyloong/karateclub
"""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)