-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwalks.py
40 lines (35 loc) · 1.1 KB
/
walks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
def get_seq_random_walk_random_global_jumps(mesh_extra, f0, seq_len):
nbrs = mesh_extra['edges']
n_vertices = mesh_extra['n_vertices']
seq = np.zeros((seq_len + 1,), dtype=np.int32)
jumps = np.zeros((seq_len + 1,), dtype=np.bool)
visited = np.zeros((n_vertices + 1,), dtype=np.bool)
visited[-1] = True
visited[f0] = True
seq[0] = f0
jumps[0] = [True]
backward_steps = 1
jump_prob = 1 / 100
for i in range(1, seq_len + 1):
this_nbrs = nbrs[seq[i - 1]]
nodes_to_consider = [n for n in this_nbrs if not visited[n]]
jump_now = np.random.binomial(1, jump_prob)
if len(nodes_to_consider) and not jump_now:
to_add = np.random.choice(nodes_to_consider)
jump = False
backward_steps = 1
else:
if i > backward_steps and not jump_now:
to_add = seq[i - backward_steps - 1]
backward_steps += 2
else:
backward_steps = 1
to_add = np.random.randint(n_vertices)
jump = True
visited[...] = 0
visited[-1] = True
visited[to_add] = 1
seq[i] = to_add
jumps[i] = jump
return seq, jumps