def test_deepwalk(): """ Testing the DeepWalk class. """ model = DeepWalk() graph = nx.watts_strogatz_graph(100, 10, 0.5) 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 = DeepWalk(dimensions=32) graph = nx.watts_strogatz_graph(150, 10, 0.5) 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
def embed(self): seed = np.random.randint(1e6) model = DW(dimensions=self.dim_embedding, walk_length=self.walk_length, window_size=self.window_size, seed=seed) model.fit(self.graph.to_undirected()) self.embedding = model.get_embedding()
def test_neu(): """ Test the NEU meta embedding class. """ graph = nx.newman_watts_strogatz_graph(100, 20, 0.05) model = NetMF() meta_model = NEU() meta_model.fit(graph, model) embedding = meta_model.get_embedding() assert embedding.shape[0] == graph.number_of_nodes() assert type(embedding) == np.ndarray graph = nx.newman_watts_strogatz_graph(200, 20, 0.05) model = DeepWalk() meta_model = NEU() meta_model.fit(graph, model) embedding = meta_model.get_embedding() assert embedding.shape[0] == graph.number_of_nodes() assert type(embedding) == np.ndarray
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
def deepwalk_embedding(Graph): dw = DeepWalk(dimensions=256) G = nx.convert_node_labels_to_integers(Graph) dw.fit(G) embeddings = dw.get_embedding() return embeddings
if save == 'T': plt.savefig(output_png_filename) else: plt.show() plt.close() return #################################################################################### # Main #################################################################################### # # DeepWalk g = nx.newman_watts_strogatz_graph(100, 20, 0.05) draw_graph(g) model = DeepWalk() model.fit(g) embedding = model.get_embedding() # # Walklets model = Walklets() model.fit(g) embedding = model.get_embedding() # # Community Detection with LabelPropagation # Get graph reader = GraphReader("facebook") graph = reader.get_graph() draw_graph(graph, 'F', 'F', '') target = reader.get_target() # Fit