finish up beerpong, walker2d and ant needs more extensions, fix import bugs.

This commit is contained in:
Onur
2022-07-01 09:54:42 +02:00
parent 4437ab9577
commit d4e3b957a9
9 changed files with 62 additions and 94 deletions
+11 -14
View File
@@ -2,6 +2,10 @@ import numpy as np
from gym.envs.mujoco.ant_v3 import AntEnv
MAX_EPISODE_STEPS_ANTJUMP = 200
# TODO: This environment was not testet yet. Do the following todos and test it.
# TODO: Right now this environment only considers jumping to a specific height, which is not nice. It should be extended
# to the same structure as the Hopper, where the angles are randomized (->contexts) and the agent should jump as heigh
# as possible, while landing at a specific target position
class ALRAntJumpEnv(AntEnv):
@@ -22,14 +26,12 @@ class ALRAntJumpEnv(AntEnv):
healthy_z_range=(0.3, float('inf')),
contact_force_range=(-1.0, 1.0),
reset_noise_scale=0.1,
context=True, # variable to decide if context is used or not
exclude_current_positions_from_observation=True,
max_episode_steps=200):
self.current_step = 0
self.max_height = 0
self.context = context
self.max_episode_steps = max_episode_steps
self.goal = 0 # goal when training with context
self.goal = 0
super().__init__(xml_file, ctrl_cost_weight, contact_cost_weight, healthy_reward, terminate_when_unhealthy,
healthy_z_range, contact_force_range, reset_noise_scale,
exclude_current_positions_from_observation)
@@ -53,15 +55,11 @@ class ALRAntJumpEnv(AntEnv):
done = height < 0.3 # fall over -> is the 0.3 value from healthy_z_range? TODO change 0.3 to the value of healthy z angle
if self.current_step == self.max_episode_steps or done:
if self.context:
# -10 for scaling the value of the distance between the max_height and the goal height; only used when context is enabled
# height_reward = -10 * (np.linalg.norm(self.max_height - self.goal))
height_reward = -10*np.linalg.norm(self.max_height - self.goal)
# no healthy reward when using context, because we optimize a negative value
healthy_reward = 0
else:
height_reward = self.max_height - 0.7
healthy_reward = self.healthy_reward * self.current_step
# -10 for scaling the value of the distance between the max_height and the goal height; only used when context is enabled
# height_reward = -10 * (np.linalg.norm(self.max_height - self.goal))
height_reward = -10*np.linalg.norm(self.max_height - self.goal)
# no healthy reward when using context, because we optimize a negative value
healthy_reward = 0
rewards = height_reward + healthy_reward
@@ -105,7 +103,6 @@ if __name__ == '__main__':
obs = env.reset()
for i in range(2000):
# objective.load_result("/tmp/cma")
# test with random actions
ac = env.action_space.sample()
obs, rew, d, info = env.step(ac)
@@ -114,4 +111,4 @@ if __name__ == '__main__':
if d:
env.reset()
env.close()
env.close()