4
$\begingroup$
 make_env = lambda: ptan.common.wrappers.wrap_dqn(gym.make("PongNoFrameskip-v4"))
 envs = [make_env() for _ in range(NUM_ENVS)]

Here is a code you can look at.

The two above lines of code create multiple environments for the game of Atari Pong with the A2C algorithm.

I understand why it is very useful to have multiple agents working on different instances of the same environment as it is presented in A3C (i.e. an asynchronous version of A2C). However, in the above code, it has a single agent working on different instances of the same environment.

What is the advantage of using more than one environment with a single agent?

UPDATE

class GymEnvVec:
    def __init__(self, name, n_envs, seed):
        self.envs = [gym.make(name) for i in range(n_envs)]
        [env.seed(seed + 10 * i) for i, env in enumerate(self.envs)]

    def reset(self):
        return [env.reset() for env in self.envs]

    def step(self, actions):
        return list(zip(*[env.step(a) for env, a in zip(self.envs, actions)]))
$\endgroup$
0

1 Answer 1

2
$\begingroup$

What is the advantage of using more than one environment with a single agent?

There are two main advantages to this approach:

  • The dataset for training is closer to the independent, identically distributed (i.i.d.) ideal, important for theoretical and practical reasons when training a neural network. Samples taken from a single trajectory are not independent, but instead are correlated due to rules of the environment - so using a single trajectory is furthest from i.i.d. This is a similar motivation to use of experience replay tables for DQN variants of Q-learning. However, experience replay is inherently off-policy, so not a good fit to A2C or A3C that need samples taken when acting under the current policy.

  • Collecting experience is often a major bottleneck in training RL agents. Being able to do so in parallel in a distributed environment can significantly speed up the training process.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .