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

Function _node2vec_walk

easygraph/functions/graph_embedding/node2vec.py:258–283  ·  view source on GitHub ↗

Simulate a random walk starting from start node.

(G, walk_length, start_node, alias_nodes, alias_edges)

Source from the content-addressed store, hash-verified

256
257
258def _node2vec_walk(G, walk_length, start_node, alias_nodes, alias_edges):
259 """
260 Simulate a random walk starting from start node.
261 """
262 walk = [start_node]
263
264 while len(walk) < walk_length:
265 cur = walk[-1]
266 cur_nbrs = sorted(G.neighbors(cur))
267 if len(cur_nbrs) > 0:
268 if len(walk) == 1:
269 walk.append(
270 cur_nbrs[_alias_draw(alias_nodes[cur][0], alias_nodes[cur][1])]
271 )
272 else:
273 prev = walk[-2]
274 next_node = cur_nbrs[
275 _alias_draw(
276 alias_edges[(prev, cur)][0], alias_edges[(prev, cur)][1]
277 )
278 ]
279 walk.append(next_node)
280 else:
281 break
282
283 return walk
284
285
286def _alias_draw(J, q):

Callers 1

simulate_walksFunction · 0.85

Calls 3

_alias_drawFunction · 0.85
appendMethod · 0.80
neighborsMethod · 0.45

Tested by

no test coverage detected