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

Function node2vec

easygraph/functions/graph_embedding/node2vec.py:13–118  ·  view source on GitHub ↗

Graph embedding via Node2Vec. 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,
    p=1.0,
    q=1.0,
    weight_key=None,
    workers=None,
    **skip_gram_params,
)

Source from the content-addressed store, hash-verified

11
12@not_implemented_for("multigraph")
13def node2vec(
14 G,
15 dimensions=128,
16 walk_length=80,
17 num_walks=10,
18 p=1.0,
19 q=1.0,
20 weight_key=None,
21 workers=None,
22 **skip_gram_params,
23):
24 """Graph embedding via Node2Vec.
25
26 Parameters
27 ----------
28 G : easygraph.Graph or easygraph.DiGraph
29
30 dimensions : int
31 Embedding dimensions, optional(default: 128)
32
33 walk_length : int
34 Number of nodes in each walk, optional(default: 80)
35
36 num_walks : int
37 Number of walks per node, optional(default: 10)
38
39 p : float
40 The return hyper parameter, optional(default: 1.0)
41
42 q : float
43 The input parameter, optional(default: 1.0)
44
45 weight_key : string or None (default: None)
46 On weighted graphs, this is the key for the weight attribute
47
48 workers : int or None, optional(default : None)
49 The number of workers generating random walks (default: None). None if not using only one worker.
50
51 skip_gram_params : dict
52 Parameters for gensim.models.Word2Vec - do not supply 'size', it is taken from the 'dimensions' parameter
53
54 Returns
55 -------
56 embedding_vector : dict
57 The embedding vector of each node
58
59 most_similar_nodes_of_node : dict
60 The most similar nodes of each node and its similarity
61
62 Examples
63 --------
64
65 >>> node2vec(G,
66 ... dimensions=128, # The graph embedding dimensions.
67 ... walk_length=80, # Walk length of each random walks.
68 ... num_walks=10, # Number of random walks.
69 ... p=1.0, # The `p` possibility in random walk in [1]_
70 ... q=1.0, # The `q` possibility in random walk in [1]_

Callers 1

Calls 4

learn_embeddingsFunction · 0.85
simulate_walksFunction · 0.70
to_index_node_graphMethod · 0.45

Tested by

no test coverage detected