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

    model = MNMF()

    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

    centers = model.get_cluster_centers()

    assert centers.shape[0] == model.clusters
    assert centers.shape[1] == model.dimensions
    assert type(centers) == np.ndarray
示例#2
0
def mnmf(population, neighbors, probability):
    g = nx.newman_watts_strogatz_graph(population, neighbors, probability)
    model = MNMF()
    model.fit(g)

    #print(model.get_memberships())
    #print(model.get_embedding())
    #print(model.get_cluster_centers())
    return [
        model.get_memberships(),
        model.get_embedding(),
        model.get_cluster_centers()
    ]
示例#3
0
# DANMF example
#----------------

g = nx.newman_watts_strogatz_graph(100, 10, 0.02)

model = DANMF()

model.fit(g)

#----------------
# M-NMF example
#----------------

g = nx.newman_watts_strogatz_graph(100, 10, 0.02)

model = MNMF()

model.fit(g)

#----------------------------
# Label Propagation example
#----------------------------

g = nx.newman_watts_strogatz_graph(100, 10, 0.02)

model = LabelPropagation()

model.fit(g)

#-----------------
# GraRep example
示例#4
0
"""MNMF example."""

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

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

model = MNMF()

model.fit(g)