Using OpenAI gym

Using the OpenAI gym really makes deep reinforcement learning easy. Keras-RL will do most of the hard work, but I think it's worth walking through the gym separately so that you can understand how the agent interacts with the environment.

Environments are objects that can be instantiated. For example, to create a CartPole-v0 environment, we just need to import the gym and create the environment, as shown in the following code:

import gymenv = gym.make("CartPole-v0")

Now, if our agent wants to act in that environment, it just needs to send an action and get back a state and a reward, as follows:

next_state, reward, done, info = env.step(action)

The agent can play through an entire episode by using a loop to interact with the ...

Get Deep Learning Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.