From 76e7dc9fbf79f4f56eb93778a8bacf2bca1017c4 Mon Sep 17 00:00:00 2001 From: Lucas Alegre Date: Sun, 27 Oct 2024 19:44:09 -0300 Subject: [PATCH] Refactor _cost_objective variable --- mo_gymnasium/envs/mujoco/ant_v4.py | 4 ++-- mo_gymnasium/envs/mujoco/ant_v5.py | 4 ++-- mo_gymnasium/envs/mujoco/hopper_v4.py | 4 ++-- mo_gymnasium/envs/mujoco/hopper_v5.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mo_gymnasium/envs/mujoco/ant_v4.py b/mo_gymnasium/envs/mujoco/ant_v4.py index cc2ba7ed..852c395f 100644 --- a/mo_gymnasium/envs/mujoco/ant_v4.py +++ b/mo_gymnasium/envs/mujoco/ant_v4.py @@ -28,7 +28,7 @@ class MOAntEnv(AntEnv, EzPickle): def __init__(self, cost_objective=True, **kwargs): super().__init__(**kwargs) EzPickle.__init__(self, cost_objective, **kwargs) - self.cost_objetive = cost_objective + self._cost_objetive = cost_objective self.reward_dim = 3 if cost_objective else 2 self.reward_space = Box(low=-np.inf, high=np.inf, shape=(self.reward_dim,)) @@ -39,7 +39,7 @@ def step(self, action): cost = info["reward_ctrl"] healthy_reward = info["reward_survive"] - if self.cost_objetive: + if self._cost_objetive: cost /= self._ctrl_cost_weight # Ignore the weight in the original AntEnv vec_reward = np.array([x_velocity, y_velocity, cost], dtype=np.float32) else: diff --git a/mo_gymnasium/envs/mujoco/ant_v5.py b/mo_gymnasium/envs/mujoco/ant_v5.py index 77c65979..a84dadec 100644 --- a/mo_gymnasium/envs/mujoco/ant_v5.py +++ b/mo_gymnasium/envs/mujoco/ant_v5.py @@ -32,7 +32,7 @@ class MOAntEnv(AntEnv, EzPickle): def __init__(self, cost_objective=True, **kwargs): super().__init__(**kwargs) EzPickle.__init__(self, cost_objective, **kwargs) - self.cost_objetive = cost_objective + self._cost_objetive = cost_objective self.reward_dim = 3 if cost_objective else 2 self.reward_space = Box(low=-np.inf, high=np.inf, shape=(self.reward_dim,)) @@ -43,7 +43,7 @@ def step(self, action): cost = info["reward_ctrl"] healthy_reward = info["reward_survive"] - if self.cost_objetive: + if self._cost_objetive: cost /= self._ctrl_cost_weight # Ignore the weight in the original AntEnv vec_reward = np.array([x_velocity, y_velocity, cost], dtype=np.float32) else: diff --git a/mo_gymnasium/envs/mujoco/hopper_v4.py b/mo_gymnasium/envs/mujoco/hopper_v4.py index 6fe0ed3c..0d24b3a9 100644 --- a/mo_gymnasium/envs/mujoco/hopper_v4.py +++ b/mo_gymnasium/envs/mujoco/hopper_v4.py @@ -27,7 +27,7 @@ class MOHopperEnv(HopperEnv, EzPickle): def __init__(self, cost_objective=True, **kwargs): super().__init__(**kwargs) EzPickle.__init__(self, cost_objective, **kwargs) - self.cost_objetive = cost_objective + self._cost_objetive = cost_objective self.reward_dim = 3 if cost_objective else 2 self.reward_space = Box(low=-np.inf, high=np.inf, shape=(self.reward_dim,)) @@ -53,7 +53,7 @@ def step(self, action): height = 10 * (z - self.init_qpos[1]) energy_cost = np.sum(np.square(action)) - if self.cost_objetive: + if self._cost_objetive: vec_reward = np.array([x_velocity, height, -energy_cost], dtype=np.float32) else: vec_reward = np.array([x_velocity, height], dtype=np.float32) diff --git a/mo_gymnasium/envs/mujoco/hopper_v5.py b/mo_gymnasium/envs/mujoco/hopper_v5.py index 1c4e6d17..3345461d 100644 --- a/mo_gymnasium/envs/mujoco/hopper_v5.py +++ b/mo_gymnasium/envs/mujoco/hopper_v5.py @@ -22,7 +22,7 @@ class MOHopperEnv(HopperEnv, EzPickle): def __init__(self, cost_objective=True, **kwargs): super().__init__(**kwargs) EzPickle.__init__(self, cost_objective, **kwargs) - self.cost_objetive = cost_objective + self._cost_objetive = cost_objective self.reward_dim = 3 if cost_objective else 2 self.reward_space = Box(low=-np.inf, high=np.inf, shape=(self.reward_dim,))