Skip to content

Commit

Permalink
bug fix: compute_reward for batch input
Browse files Browse the repository at this point in the history
  • Loading branch information
nicehiro committed May 19, 2023
1 parent da809b8 commit c4700cd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gymnasium_robotics/envs/maze/maze.py
Expand Up @@ -349,10 +349,11 @@ def add_xy_position_noise(self, xy_pos: np.ndarray) -> np.ndarray:
def compute_reward(
self, achieved_goal: np.ndarray, desired_goal: np.ndarray, info
) -> float:
d = np.linalg.norm(achieved_goal - desired_goal, axis=-1)
if self.reward_type == "dense":
return np.exp(-np.linalg.norm(desired_goal - achieved_goal))
return np.exp(-d)
elif self.reward_type == "sparse":
return 1.0 if np.linalg.norm(achieved_goal - desired_goal) <= 0.45 else 0.0
return - (d > 0.45).astype(np.float32)

def compute_terminated(
self, achieved_goal: np.ndarray, desired_goal: np.ndarray, info
Expand Down

0 comments on commit c4700cd

Please sign in to comment.