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 deepwalk_embedding(Graph): dw = DeepWalk(dimensions=256) G = nx.convert_node_labels_to_integers(Graph) dw.fit(G) embeddings = dw.get_embedding() return embeddings
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 model = LabelPropagation()