MCPcopy Index your code
hub / github.com/shenweichen/GraphEmbedding / _exec_random_walk

Method _exec_random_walk

ge/walker.py:234–263  ·  view source on GitHub ↗
(self, graphs, layers_accept, layers_alias, v, walk_length, gamma, stay_prob=0.3)

Source from the content-addressed store, hash-verified

232 return walks
233
234 def _exec_random_walk(self, graphs, layers_accept, layers_alias, v, walk_length, gamma, stay_prob=0.3):
235 initialLayer = 0
236 layer = initialLayer
237
238 path = []
239 path.append(self.idx2node[v])
240
241 while len(path) < walk_length:
242 r = random.random()
243 if (r < stay_prob): # same layer
244 v = chooseNeighbor(v, graphs, layers_alias,
245 layers_accept, layer)
246 path.append(self.idx2node[v])
247 else: # different layer
248 r = random.random()
249 try:
250 x = math.log(gamma[layer][v] + math.e)
251 p_moveup = (x / (x + 1))
252 except:
253 print(layer, v)
254 raise ValueError()
255
256 if (r > p_moveup):
257 if (layer > initialLayer):
258 layer = layer - 1
259 else:
260 if ((layer + 1) in graphs and v in graphs[layer + 1]):
261 layer = layer + 1
262
263 return path
264
265
266def chooseNeighbor(v, graphs, layers_alias, layers_accept, layer):

Callers 1

_simulate_walksMethod · 0.95

Calls 1

chooseNeighborFunction · 0.85

Tested by

no test coverage detected