Skip to content

Commit

Permalink
Simple point agent done
Browse files Browse the repository at this point in the history
  • Loading branch information
arilato committed Dec 3, 2018
1 parent fa3161d commit 7b81c9c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions PointAgents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)))

0 comments on commit 7b81c9c

Please sign in to comment.