-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessor_init.pyx
49 lines (42 loc) · 1.98 KB
/
processor_init.pyx
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
45
46
47
48
49
"""
Shows information about the first few states.
Needs data from the sss collector.
"""
from cython import ccall, cclass, returns
from numpy import empty, var
from processor_base cimport BaseProcessor
@cclass
class Processor(BaseProcessor):
formats = ('sss',)
@ccall
@returns('object')
def process(self):
records_count = len(self.data)
features = self.max_features
actions = self.max_actions
states0 = empty((records_count, features), dtype='f4')
states3 = empty((records_count, features), dtype='f4')
fstates1 = empty((records_count, actions, features), dtype='f4')
fstates4 = empty((records_count, actions, features), dtype='f4')
changes1 = empty((records_count, actions, features), dtype='f4')
changes4 = empty((records_count, actions, features), dtype='f4')
variances1 = empty((records_count, features), dtype='f4')
variances4 = empty((records_count, features), dtype='f4')
for index, (record, meta) in enumerate(self.data):
states0[index] = record['states'][0]
states3[index] = record['states'][3]
fstates1[index] = record['following_states'][0]
fstates4[index] = record['following_states'][3]
changes1[index] = fstates1[index] - states0[index]
changes4[index] = fstates4[index] - states3[index]
variances1[index] = var(fstates1[index], axis=0)
variances4[index] = var(fstates4[index], axis=0)
return self.results((
("initial states", states0),
# ("states after the first action", fstates1),
("changes after the first action", changes1),
("the first action matters", variances1.any()),
("state after three actions", states3),
# ("following (fourth) states", fstates4),
("changes after the fourth action", changes4),
("the fourth action matters", variances4.any())))