RayObservable now gives Output in Range [0, 1]

This commit is contained in:
Dominik Moritz Roth 2022-08-15 17:15:56 +02:00
parent de4704f813
commit bd191c82fd

View File

@ -97,7 +97,7 @@ class RayObservable(Observable):
self.include_rand = include_rand self.include_rand = include_rand
def get_observation_space(self): def get_observation_space(self):
return spaces.Box(low=0, high=self.num_steps, return spaces.Box(low=0, high=1,
shape=(self.num_rays+self.include_rand, self.num_chans), dtype=np.uint8) shape=(self.num_rays+self.include_rand, self.num_chans), dtype=np.uint8)
def _get_ray_heads(self): def _get_ray_heads(self):
@ -148,7 +148,7 @@ class RayObservable(Observable):
self.env.agent.pos[0]*self.env.width, sy + \ self.env.agent.pos[0]*self.env.width, sy + \
self.env.agent.pos[1]*self.env.height self.env.agent.pos[1]*self.env.height
if self._check_collision((rx, ry), entity_type, entities): if self._check_collision((rx, ry), entity_type, entities):
self.rays[r, c] = self.num_steps-s self.rays[r, c] = (self.num_steps-s)/self.num_steps
if self.occlusion: if self.occlusion:
occ_dist = s occ_dist = s
break break
@ -157,7 +157,7 @@ class RayObservable(Observable):
def draw(self): def draw(self):
for c, entity_type in enumerate(self.chans): for c, entity_type in enumerate(self.chans):
for r, (hx, hy) in enumerate(self._get_ray_heads()): for r, (hx, hy) in enumerate(self._get_ray_heads()):
s = self.num_steps - self.rays[r, c] s = self.num_steps - self.rays[r, c]*self.num_steps
sx, sy = (s+1)*hx/self.num_steps, (s+1)*hy/self.num_steps sx, sy = (s+1)*hx/self.num_steps, (s+1)*hy/self.num_steps
rx, ry = sx + \ rx, ry = sx + \
self.env.agent.pos[0]*self.env.width, sy + \ self.env.agent.pos[0]*self.env.width, sy + \