-
Notifications
You must be signed in to change notification settings - Fork 0
/
traj_info.py
24 lines (19 loc) · 923 Bytes
/
traj_info.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
from rlpyt.samplers.collections import TrajInfo
class EnvInfoTrajInfo(TrajInfo):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def step(self, observation, action, reward, done, agent_info, env_info):
super().step(observation, action, reward, done, agent_info, env_info)
# log all int, float and bools from env_info
for key, value in env_info._asdict().items():
try:
float_value = float(value)
self.__setattr__(key, float_value)
if not hasattr(self, key + '_traj_sum'):
setattr(self, key + '_traj_sum', float_value)
else:
new_value = self.__getattribute__(key + '_traj_sum') + float_value
setattr(self, key + '_traj_sum', new_value)
except (ValueError, TypeError):
# can't log value
pass