def test_danmf():
    """
    Test the DANMF procedure.
    """
    graph = nx.newman_watts_strogatz_graph(100, 5, 0.3)

    model = DANMF()

    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] == 2*model.layers[-1]
    assert type(embedding) == np.ndarray


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

    model = DANMF()

    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] == 2*model.layers[-1]
    assert type(embedding) == np.ndarray
示例#2
0
"""DANMF example."""

import networkx as nx
from karateclub.community_detection.overlapping import DANMF

g = nx.newman_watts_strogatz_graph(100, 20, 0.05)

model = DANMF()

model.fit(g)
示例#3
0
def danmf(population, neighbors, probability):
    g = nx.newman_watts_strogatz_graph(population, neighbors, probability)
    model = DANMF()
    model.fit(g)
    #print(model.get_embedding())
    return [model.get_memberships(), model.get_embedding()]