forked from vladfi1/phillip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_data.py
executable file
·45 lines (34 loc) · 963 Bytes
/
merge_data.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
39
40
41
42
43
44
#!/usr/bin/env python3
import numpy as np
import glob
from phillip import util
import pickle
use_hickle = True
if use_hickle:
import hickle
path = "experience/FalconFalconBF"
def load_experience(path):
with open(path, 'rb') as f:
return pickle.load(f)
def prune_experience(experience):
state = experience['state']
state['players'] = state['players'][:2]
return experience
prune_load = util.compose(prune_experience, load_experience)
paths = glob.glob(path+'/*')[:100]
experiences = []
for i, p in enumerate(paths):
if i % 10 == 0:
print('reading %d/%d' % (i, len(paths)))
experiences.append(prune_load(p))
def to_array(*xs):
return np.array(xs)
merged = util.deepZipWith(to_array, *experiences)
# hickle can't handle empty lists :(
# but we don't want the initial state anyways
del merged['initial']
if use_hickle:
hickle.dump(merged, 'merged.hickle')
else:
with open('merged.pickle', 'wb') as f:
pickle.dump(merged, f)