which can be installed with the help of the following command:
pip install gym
There are various environments in OpenAI gym which can be used for various purposes.
Few of them are Cartpole-v0, Hopper-v1, and MsPacman-v0. They require differentengines. The detail documentation of OpenAI Gym can be found on
https://gym.openai.com/docs/#environments.
The following code shows an example of Python code for cartpole-v0 environment:
import gym
env = gym.make('CartPole-v0')env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample())
We can construct other environments in a similar way.
For building reinforcement learning agent, we will be using the OpenAI Gym package as shown:
import gym
env = gym.make('CartPole-v0')
for _ in range(20):
observation = env.reset()
for i in range(100):
env.render()
print(observation)
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(i+1))
env = gym.make('CartPole-v0')
for _ in range(20):
observation = env.reset()
for i in range(100):
env.render()
print(observation)
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(i+1))
break
You may observe that the cartpole can balance itself.
0 comments:
Post a Comment