MCPcopy
hub / github.com/THUDM/CogDL / _node2vec_walk

Method _node2vec_walk

cogdl/models/emb/node2vec.py:105–126  ·  view source on GitHub ↗
(self, walk_length, start_node)

Source from the content-addressed store, hash-verified

103 return features_matrix
104
105 def _node2vec_walk(self, walk_length, start_node):
106 # Simulate a random walk starting from start node.
107 G = self.G
108 alias_nodes = self.alias_nodes
109 alias_edges = self.alias_edges
110
111 walk = [start_node]
112
113 while len(walk) < walk_length:
114 cur = walk[-1]
115 cur_nbrs = list(G.neighbors(cur))
116 if len(cur_nbrs) > 0:
117 if len(walk) == 1:
118 walk.append(cur_nbrs[alias_draw(alias_nodes[cur][0], alias_nodes[cur][1])])
119 else:
120 prev = walk[-2]
121 next = cur_nbrs[alias_draw(alias_edges[(prev, cur)][0], alias_edges[(prev, cur)][1])]
122 walk.append(next)
123 else:
124 break
125
126 return walk
127
128 def _simulate_walks(self, num_walks, walk_length):
129 # Repeatedly simulate random walks from each node.

Callers 1

_simulate_walksMethod · 0.95

Calls 1

alias_drawFunction · 0.90

Tested by

no test coverage detected