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

Understanding an OpenAI Gym environment

To understand the basics of importing Gym packages, loading an environment, and other important functions associated with OpenAI Gym, here's an example of a Frozen Lake environment.

Load the Frozen Lake environment in the following way:

import Gym 
env = Gym.make('FrozenLake-v0') #make function of Gym loads the specified environment

Next, we come to resetting the environment. While performing a reinforcement learning task, an agent undergoes learning through multiple episodes. As a result, at the start of each episode, the environment needs to be reset so that it comes to its initial situation and the agent begins from the start state. The following code shows the process for resetting an environment:

import Gym 
env = Gym.make('FrozenLake-v0')
s = env.reset() # resets the environment and returns the start state as a value
print(s)

-----------
0 #initial state is 0

After taking each action, there might be a requirement to show the status of the agent in the environment. Visualizing that status is done by:

env.render()

------------
SFFF FHFH FFFH HFFG

The preceding output shows that this is an environment with 4 x 4 grids, that is, 16 states arranged in the preceding manner where S, H, F, and G represents different forms of a state where:

  • S: Start block
  • F: Frozen block
  • H: Block has hole
  • G: Goal block

In newer versions of the Gym, the environment features can't be modified directly. This is done by unwrapping the environment parameters with:

env = env.unwrapped

Each environment is defined by the state spaces and action spaces for the agent to perform. The type (discrete or continuous) and size of state spaces and action spaces is very important to know in order to build a reinforcement learning agent:

print(env.action_space)
print(env.action_space.n)

----------------
Discrete(4)
4

The Discrete(4) output means that the action space of the Frozen Lake environment is a discrete set of values and has four distinct actions that can be performed by the agent.

print(env.observation_space)
print(env.observation_space.n)

----------------
Discrete(16)
16

The Discrete(16) output means that the observation (state) space of the Frozen Lake environment is a discrete set of values and has 16 different states to be explored by the agent.

主站蜘蛛池模板: 信阳市| 缙云县| 泰兴市| 登封市| 祁门县| 龙门县| 固阳县| 汝南县| 天等县| 且末县| 陆河县| 大竹县| 惠来县| 云浮市| 蕉岭县| 郧西县| 宜昌市| 洛宁县| 扎鲁特旗| 桃园市| 南投市| 光泽县| 收藏| 客服| 赫章县| 成武县| 民丰县| 宝兴县| 林口县| 太保市| 淳安县| 科技| 涟源市| 蓬溪县| 原平市| 女性| 绥德县| 普兰店市| 道孚县| 图木舒克市| 钟山县|