-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsequences.py
More file actions
41 lines (34 loc) · 1.23 KB
/
Copy pathsequences.py
File metadata and controls
41 lines (34 loc) · 1.23 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
"""
Generate random instances of various artificial tasks.
Right now, only a bit-vector copy task is implemented.
"""
import numpy as np
def copy_sequence(seq_length, vec_size):
"""
Returns inputs, outputs
where inputs is a length 2 * seq_length + 2 sequence of vec_size + 2 vecs
and outputs is a length 2 * seq_length + 2 sequence of vec_size vecs
inputs starts with a start bit, then the seq to be copied, then and end bit, then 0s
outputs is 0s until after inputs has the end bit, then it's the first sequence, but without
the extra bits
"""
input_size = vec_size + 2
length = seq_length * 2 + 2
inputs = np.zeros((length,input_size),dtype=np.uint8)
outputs = np.zeros((length,vec_size),dtype=np.uint8)
in_sequence = np.random.randint(2, size=(seq_length, input_size))
in_sequence[:,-2:] = 0
out_sequence = in_sequence[:,:-2]
# set start bit in inputs
start_vec = np.zeros(input_size)
start_vec[-2] = 1
inputs[0] = start_vec
# set the pattern bits in inputs
inputs[1:seq_length+1] = in_sequence
# set stop bit in inputs
stop_vec = np.zeros(input_size)
stop_vec[-1] = 1
inputs[seq_length+1] = stop_vec
# set all the bits in outputs
outputs[seq_length+2:] = out_sequence
return inputs, outputs