-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerator.py
More file actions
44 lines (30 loc) · 1.19 KB
/
Copy pathgenerator.py
File metadata and controls
44 lines (30 loc) · 1.19 KB
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
39
40
41
42
43
44
import numpy as np
class RandomGenerator:
def __init__(self, n_symbols, smart=False, offset=2):
self.n_symbols = n_symbols
self.smart = smart
self.offset = offset
def next_symbols(self, n):
if not self.smart:
symbols = np.random.randint(0, self.n_symbols, n)
else:
symbols = list(range(self.n_symbols))
np.random.shuffle(symbols)
while len(symbols) < n:
new_symbols = symbols[-self.n_symbols:-self.offset]
np.random.shuffle(new_symbols)
symbols += new_symbols
return symbols[:n]
class SequenceGenerator:
def __init__(self, sequence, global_shift=0, shuffle=None):
self.sequence = sequence[global_shift:] + sequence[:global_shift]
if 'global' == shuffle:
np.random.shuffle(self.sequence)
self.shuffle_line = 'line' == shuffle
self.shift = 0
def next_symbols(self, n):
symbols = self.sequence[self.shift:self.shift+n]
if self.shuffle_line:
np.random.shuffle(symbols)
self.shift += n
return symbols