浏览代码

rename create random to random action

/develop/action-spec-gym
Andrew Cohen 4 年前
当前提交
e5cc57f9
共有 3 个文件被更改,包括 4 次插入4 次删除
  1. 2
      ml-agents-envs/mlagents_envs/base_env.py
  2. 4
      ml-agents-envs/mlagents_envs/tests/test_steps.py
  3. 2
      ml-agents/mlagents/trainers/tests/torch/test_reward_providers/utils.py

2
ml-agents-envs/mlagents_envs/base_env.py


return np.zeros((n_agents, self.continuous_size), dtype=np.float32)
return np.zeros((n_agents, self.discrete_size), dtype=np.int32)
def create_random(self, n_agents: int) -> np.ndarray:
def random_action(self, n_agents: int) -> np.ndarray:
"""
Generates a numpy array corresponding to a random action (either discrete
or continuous) for a number of agents.

4
ml-agents-envs/mlagents_envs/tests/test_steps.py


specs = ActionSpec.create_continuous(action_len)
zero_action = specs.create_empty(4)
assert np.array_equal(zero_action, np.zeros((4, action_len), dtype=np.float32))
random_action = specs.create_random(4)
random_action = specs.random_action(4)
assert random_action.dtype == np.float32
assert random_action.shape == (4, action_len)
assert np.min(random_action) >= -1

zero_action = specs.create_empty(4)
assert np.array_equal(zero_action, np.zeros((4, len(action_shape)), dtype=np.int32))
random_action = specs.create_random(4)
random_action = specs.random_action(4)
assert random_action.dtype == np.int32
assert random_action.shape == (4, len(action_shape))
assert np.min(random_action) >= 0

2
ml-agents/mlagents/trainers/tests/torch/test_reward_providers/utils.py


next_observations = [
np.random.normal(size=shape) for shape in behavior_spec.observation_shapes
]
action = behavior_spec.action_spec.create_random(1)[0, :]
action = behavior_spec.action_spec.random_action(1)[0, :]
for _ in range(number):
curr_split_obs = SplitObservations.from_observations(curr_observations)
next_split_obs = SplitObservations.from_observations(next_observations)

正在加载...
取消
保存