示例#1
0
def test_diff2vec():
    """
    Testing the Diff2Vec class.
    """
    model = Diff2Vec()

    graph = nx.watts_strogatz_graph(100, 10, 1.0)

    model.fit(graph)

    embedding = model.get_embedding()

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

    model = Diff2Vec(dimensions=32)

    graph = nx.watts_strogatz_graph(150, 10, 1.0)

    model.fit(graph)

    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
def karate_factory(algo, dim, nwalks, workers):
    if algo == "walklets":
        karate_obj = Walklets(dimensions=int(dim / 4),
                              walk_number=nwalks,
                              workers=workers)
    elif algo == "role2vec":
        karate_obj = Role2Vec(dimensions=dim,
                              walk_number=nwalks,
                              workers=workers)
    elif algo == "diff2vec":
        karate_obj = Diff2Vec(dimensions=dim,
                              diffusion_number=nwalks,
                              workers=workers)
    elif algo == "deepwalk":
        karate_obj = DeepWalk(dimensions=dim,
                              walk_number=nwalks,
                              workers=workers)
    elif algo == "boostne":
        karate_obj = BoostNE(dimensions=int(dim / 17) + 1)
    elif algo == "nodesketch":
        karate_obj = NodeSketch(dimensions=dim)
    elif algo == "netmf":
        karate_obj = NetMF(dimensions=dim)
    elif algo == "hope":
        karate_obj = HOPE(dimensions=dim)
    elif algo == "grarep":
        karate_obj = GraRep(dimensions=int(dim / 5) + 1)
    elif algo == "nmfadmm":
        karate_obj = NMFADMM(dimensions=int(dim / 2))
    elif algo == "graphwave":
        karate_obj = GraphWave()
    elif algo == "laplacian":
        karate_obj = LaplacianEigenmaps(dimensions=dim)
    else:
        raise RuntimeError("Invalid model type: %s" % algo)
    return karate_obj