MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / deepwalk

Function deepwalk

easygraph/functions/graph_embedding/deepwalk.py:15–74  ·  view source on GitHub ↗

Graph embedding via DeepWalk. Parameters ---------- G : easygraph.Graph or easygraph.DiGraph dimensions : int Embedding dimensions, optional(default: 128) walk_length : int Number of nodes in each walk, optional(default: 80) num_walks : int Number

(G, dimensions=128, walk_length=80, num_walks=10, **skip_gram_params)

Source from the content-addressed store, hash-verified

13
14@not_implemented_for("multigraph")
15def deepwalk(G, dimensions=128, walk_length=80, num_walks=10, **skip_gram_params):
16 """Graph embedding via DeepWalk.
17
18 Parameters
19 ----------
20 G : easygraph.Graph or easygraph.DiGraph
21
22 dimensions : int
23 Embedding dimensions, optional(default: 128)
24
25 walk_length : int
26 Number of nodes in each walk, optional(default: 80)
27
28 num_walks : int
29 Number of walks per node, optional(default: 10)
30
31 skip_gram_params : dict
32 Parameters for gensim.models.Word2Vec - do not supply `size`, it is taken from the `dimensions` parameter
33
34 Returns
35 -------
36 embedding_vector : dict
37 The embedding vector of each node
38
39 most_similar_nodes_of_node : dict
40 The most similar nodes of each node and its similarity
41
42 Examples
43 --------
44
45 >>> deepwalk(G,
46 ... dimensions=128, # The graph embedding dimensions.
47 ... walk_length=80, # Walk length of each random walks.
48 ... num_walks=10, # Number of random walks.
49 ... skip_gram_params = dict( # The skip_gram parameters in Python package gensim.
50 ... window=10,
51 ... min_count=1,
52 ... batch_words=4,
53 ... iter=15
54 ... ))
55
56 References
57 ----------
58 .. [1] https://arxiv.org/abs/1403.6652
59
60 """
61 G_index, index_of_node, node_of_index = G.to_index_node_graph()
62
63 walks = simulate_walks(G_index, walk_length=walk_length, num_walks=num_walks)
64 model = learn_embeddings(walks=walks, dimensions=dimensions, **skip_gram_params)
65
66 (
67 embedding_vector,
68 most_similar_nodes_of_node,
69 ) = _get_embedding_result_from_gensim_skipgram_model(
70 G=G, index_of_node=index_of_node, node_of_index=node_of_index, model=model
71 )
72

Callers 1

Calls 4

learn_embeddingsFunction · 0.90
simulate_walksFunction · 0.70
to_index_node_graphMethod · 0.45

Tested by

no test coverage detected