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
ファイル: examples.py プロジェクト: kmkwon94/comcomai
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()]