-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
89 lines (58 loc) · 1.77 KB
/
logger.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from time import perf_counter
class Logger:
# Base class for Logging Callbacks
def __init__(self):
self.name = "Log"
def on_task_begin(self, data=None):
pass
def on_task_end(self, data=None):
pass
class LearnerLogger(Logger):
# Base class for Loggers for Learner process
pass
class ActorLogger(Logger):
# Base class for Loggers for Actor process
def __init__(self):
super().__init__()
def on_episode_begin(self, data=None):
pass
def on_episode_step(self, data=None):
pass
def on_episode_end(self, data=None):
pass
def consume_data(self):
pass
class EpisodeLengthLogger(ActorLogger):
def __init__(self):
super().__init__()
self.name = "EpisodeLength"
self.length = 0
def on_episode_begin(self, data=None):
self.length = 0
def on_episode_step(self, data=None):
self.length += 1
def consume_data(self):
return int(self.length)
class TotalRewardLogger(ActorLogger):
def __init__(self):
super().__init__()
self.name = "TotalReward"
self.reward = 0
def on_episode_begin(self, data=None):
self.reward = 0
def on_episode_step(self, data=None):
self.reward += data["reward"]
def consume_data(self):
return float(self.reward)
class EpisodeTimeLogger(ActorLogger):
def __init__(self):
super().__init__()
self.name = "EpisodeTime"
self.start_time = 0
self.end_time = 0
def on_episode_begin(self, data=None):
self.start_time = perf_counter()
def on_episode_end(self, data=None):
self.end_time = perf_counter()
def consume_data(self):
return float(self.end_time - self.start_time)