-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewards.py
68 lines (43 loc) · 1.9 KB
/
rewards.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
import numpy as np
class Reward:
"""A simple wrapper class for reward computation."""
def __call__(self, trajectories, shapes):
raise NotImplementedError
@property
def name(self):
return self.NAME
class ZeroReward(Reward):
"""Returns zero reward for every shape and step in trajectory."""
NAME = 'zero'
def __call__(self, trajectories, shapes):
return np.zeros((trajectories.shape[0],), dtype=np.float32)
class VertPosReward(Reward):
"""Returns reward proportional to the vertical position of the first object."""
NAME = 'vertical_position'
def __call__(self, trajectories, shapes):
return trajectories[:, 0, 1]
class HorPosReward(Reward):
"""Returns reward proportional to the horizontal position of the first object."""
NAME = 'horizontal_position'
def __call__(self, trajectories, shapes):
return trajectories[:, 0, 0]
class AgentXReward(Reward):
"""Returns reward proportional to the horizontal position of the agent. Assumes that agent is the first object."""
NAME = 'agent_x'
def __call__(self, trajectories, shapes):
return trajectories[:, 0, 1]
class AgentYReward(Reward):
"""Returns reward proportional to the vertical position of the agent. Assumes that agent is the first object."""
NAME = 'agent_y'
def __call__(self, trajectories, shapes):
return trajectories[:, 0, 0]
class TargetXReward(Reward):
"""Returns reward proportional to the horizontal position of the target. Assumes that target is second object."""
NAME = 'target_x'
def __call__(self, trajectories, shapes):
return trajectories[:, 1, 1]
class TargetYReward(Reward):
"""Returns reward proportional to the vertical position of the target. Assumes that target is the second object."""
NAME = 'target_y'
def __call__(self, trajectories, shapes):
return trajectories[:, 1, 0]