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

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.

主站蜘蛛池模板: 邯郸县| 定结县| 巴中市| 西乌珠穆沁旗| 乾安县| 湟源县| 嘉禾县| 丰城市| 普兰县| 晋城| 通城县| 乌兰浩特市| 阿尔山市| 壤塘县| 吐鲁番市| 微山县| 井研县| 布拖县| 泰安市| 潼关县| 五家渠市| 嘉义县| 福州市| 平远县| 蓝田县| 葵青区| 苗栗市| 九寨沟县| 宜阳县| 沙河市| 合江县| 桂平市| 莱芜市| 宝丰县| 安康市| 花垣县| 乌海市| 措勤县| 屯留县| 莱阳市| 前郭尔|