-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointAgents.py
41 lines (33 loc) · 1.38 KB
/
PointAgents.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
import numpy as np
class PointAgent():
import collections
def __init__(self, goal, maxdist):
self.goal = goal
self.loc = [0, 0]
self.maxdist = maxdist
def dist_to_goal(self, loc):
return ((loc[0] - self.goal[0]) ** 2 + (loc[1] - self.goal[1]) ** 2) ** 0.5
def get_action_distr(self, loc):
dist = min(self.maxdist, self.dist_to_goal(loc))
angle = np.arctan((loc[1] - self.goal[1]) / (loc[0] - self.goal[0]))
return (dist, angle)
def move(self, dist_distr, angle_distr):
distance = dist_distr()
angle = angle_distr()
self.loc[0] += np.cos(angle) * distance
self.loc[1] += np.sin(angle) * distance
class NoisyPointAgent(PointAgent):
def __init__(self, goal, maxdist, dist_noise, angle_noise):
self.dist_noise = dist_noise
self.angle_noise = angle_noise
PointAgent.__init__(self, goal, maxdist)
def get_action_distr(self, loc):
no_noise = list(PointAgent.get_action_distr(self, loc))
print(no_noise)
noisy = no_noise
noisy[0] *= self.dist_noise()
noisy[1] += self.angle_noise()
return noisy
if __name__ == '__main__':
agent = NoisyPointAgent(goal=(10,10), maxdist=5, dist_noise = lambda: np.random.normal(loc=1), angle_noise = lambda: np.random.normal(scale=0.1))
print(agent.get_action_distr(loc=(0,0)))