浏览代码

Better hybrid actions test env (#4523)

* Add test env for hybrid actions, clean up BehaviorSpec

* Add reward function and proper step
/develop/actionmodel-csharp
GitHub 4 年前
当前提交
2b300088
共有 1 个文件被更改,包括 19 次插入2 次删除
  1. 21
      ml-agents/mlagents/trainers/tests/simple_test_envs.py

21
ml-agents/mlagents/trainers/tests/simple_test_envs.py


vec_obs_size=OBS_SIZE,
action_size=1,
):
super().__init__(brain_names, False)
self.continuous_env = SimpleEnvironment(
brain_names,
False,

self.discrete_action = {}
def step(self) -> None:
self.continuous_env.step()
self.discrete_env.step()
assert all(action is not None for action in self.continuous_env.action.values())
assert all(action is not None for action in self.discrete_env.action.values())
for name in self.names:
cont_done = self.continuous_env._take_action(name)
cont_reward = self.continuous_env._compute_reward(name, cont_done)
self.rewards[name] += cont_reward / 2
disc_done = self.discrete_env._take_action(name)
disc_reward = self.discrete_env._compute_reward(name, disc_done)
self.rewards[name] += disc_reward / 2
all_done = cont_done and disc_done
self.step_result[name] = self._make_batched_step(
name, all_done, cont_reward + disc_reward
)
self.reset()
self.continuous_env.goal = self.goal
self.discrete_env.goal = self.goal
def set_actions(self, behavior_name: BehaviorName, action: HybridAction) -> None:
self.continuous_env.set_actions(action.continuous)

正在加载...
取消
保存