官术网_书友最值得收藏!

Running an environment

Any gym environment can be initialized and run by using a simple interface. Let's start by importing the gym library, as follows:

  1. First we import the gym library:
import gym 
  1. Next, create an environment by passing an argument to gym.make. In the following code, CartPole is used as an example:
environment = gym.make('CartPole-v0') 
  1. Next, reset the environment:
environment.reset() 
  1. Then, start an iteration and render the environment, as follows:
for dummy in range(100):
environment.render()
environment.step(environment.action_space.sample())

Also, change the action space at every step, to see CartPole moving. Running the preceding program should produce a visualization. The scene should start with a visualization, as follows:

The preceding image is called a CartPoleThe CartPole is made up of a cart that can move horizontally and a pole that can move rotationally, with respect to the center of the cart.

The pole is pivoted to the cart. After some time, you will notice that the pole is falling to one side, as shown in the following image:

After a few more iterations, the pole will swing back, as shown in the following image. All of the movements are constrained by the laws of physics. The steps are taken randomly:

Other environments can be seen in a similar way, by replacing the argument of the gym environment, such as MsPacman-v0 or MountrainCar-v0. For other environments, other licenses may be required. Next, we will go through the rest of the environments.

主站蜘蛛池模板: 石台县| 陆河县| 景洪市| 呼伦贝尔市| 元谋县| 黄骅市| 长岭县| 铜鼓县| 灵山县| 舟曲县| 牙克石市| 兴文县| 鹤峰县| 龙川县| 淮滨县| 长垣县| 博爱县| 金门县| 佛学| 兴安盟| 岚皋县| 昭苏县| 通海县| 唐海县| 平昌县| 广德县| 临安市| 紫金县| 华阴市| 阳高县| 温宿县| 南康市| 康乐县| 正镶白旗| 江华| 鹰潭市| 惠安县| 贡觉县| 屯昌县| 黄大仙区| 蓝山县|