Environment API
Base environment
gym_classics2.envs.abstract.base_env.BaseEnv
Bases: Env
Abstract base class for shared functionality between all environments.
Source code in gym_classics2/envs/abstract/base_env.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
start_states
property
Tuple of raw states from which an episode may start.
These are raw environment states even when :attr:tabular is true. Use
:meth:state2id to convert them to integer observations.
states
state2id
id2state
is_reachable
Returns True if the state can be reached from at least one start location, False otherwise.
actions
action2id
Converts a action label into a numeric action ID.
id2action
Converts a numeric action ID into a label. Choices for type are 'text' and 'arrow'.
Source code in gym_classics2/envs/abstract/base_env.py
model
Return the complete transition model for a state-action pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Integer state ID when :attr: |
required | |
action
|
Integer action ID. |
required |
Returns:
| Type | Description |
|---|---|
|
A four-item list |
|
|
|
|
|
otherwise. The remaining items are one-dimensional NumPy arrays in the |
|
|
same order. |
Source code in gym_classics2/envs/abstract/base_env.py
Gridworld
gym_classics2.envs.abstract.gridworld.Gridworld
Bases: BaseEnv
Abstract class for creating gridworld-type environments.
Source code in gym_classics2/envs/abstract/gridworld.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
reset
Reset to a start cell and render a frame in human mode.
Source code in gym_classics2/envs/abstract/gridworld.py
step
Advance the environment and render a frame in human mode.
Source code in gym_classics2/envs/abstract/gridworld.py
render
Prints a gridworld array in a human-readable format. The array should be a vector with values for states in the gridworld, such as a value function or policy.
Source code in gym_classics2/envs/abstract/gridworld.py
image
image(V=None, policy=None, episode=None, labels=None, title=None, cmap='auto', origin='lower', clim=None)
Display the a gridworld as an image.
:param V: The value (e.g., a value function) to display. If None, display state indices. :param labels: The labels to show on the grid cells in the same order as the value function. If True, show rounded values from V. :param policy: The policy to display. If not None, show the policy. :param episode: Show an episode :param title: Title of the plot. :param cmap: Colormap to use for the value function. :param origin: 'lower' means (0,0) is at the bottom-left, 'upper' means (0,0) is at the top-left.
Source code in gym_classics2/envs/abstract/gridworld.py
image_list
Creates a sequence of images, one for each episode.
Source code in gym_classics2/envs/abstract/gridworld.py
Concrete environments
gym_classics2.envs.gym_classics2.classic_gridworld_v1.ClassicGridworld
Bases: Gridworld
A 4x3 pedagogical gridworld. The agent starts in the bottom-left cell. Actions are noisy; with a 10% chance each, a move action may be rotated by 90 degrees clockwise or counter-clockwise (the "80-10-10 rule"). Cell (1, 1) is blocked and cannot be occupied by the agent.
reference: cite{1} (page 646).
state: Grid location.
actions: Move up/right/down/left.
rewards: +1 for taking any action in cell (3, 2). -1 for taking any action in cell (3, 1). NOTE: v1 uses the original -0.04 penalty for each state.
termination: Earning a nonzero reward.
Source code in gym_classics2/envs/gym_classics2/classic_gridworld_v1.py
gym_classics2.envs.gym_classics2.cliff_walk_v1.CliffWalk
Bases: Gridworld
The Cliff Walking task, a 12x4 gridworld often used to contrast Sarsa with Q-Learning. The agent begins in the bottom-left cell and must navigate to the goal (bottom-right cell) without entering the region along the bottom ("The Cliff").
v1 follows the textbook and does not end episodes when the cliff is reached. Also, the goal is a real state.
reference: cite{3} (page 132, example 6.6).
state: Grid location.
actions: Move up/right/down/left.
rewards: -100 for entering The Cliff. -1 for all other transitions.
termination: reaching the goal.
Source code in gym_classics2/envs/gym_classics2/cliff_walk_v1.py
gym_classics2.envs.gym_classics2.dyna_maze.DynaMaze
Bases: Gridworld
A 9x6 deterministic gridworld with barriers to make navigation more challenging. The agent starts in cell (0, 3); the goal is the top-right cell.
reference: cite{3} (page 164, example 8.1).
state: Grid location.
actions: Move up/right/down/left.
rewards: +1 for episode termination.
termination: Reaching the goal.
Source code in gym_classics2/envs/gym_classics2/dyna_maze.py
gym_classics2.envs.gym_classics2.four_rooms.FourRooms
Bases: Gridworld
An 11x11 gridworld segmented into four rooms. The agent begins in the bottom-left cell; the goal is in the top-right cell.
reference: cite{2} (page 192).
state: Grid location.
actions: Move up/right/down/left.
rewards: +1 for episode termination.
termination: Taking any action in the goal.
Sutton, Precup and Singh: Between MDPs and semi-MDPs: A framework for temporal abstraction in reinforcement learning.
Artificial Intelligence, 112(1-2):181-211, 1999. [https://hdl.handle.net/20.500.14394/9879]
Source code in gym_classics2/envs/gym_classics2/four_rooms.py
gym_classics2.envs.gym_classics2.L_maze.LMazeGridworld
Bases: Gridworld
A deterministic 10x10 maze separated by an L-shaped barrier.
The agent begins below the horizontal barrier and must travel around it to reach the goal near the upper-right corner.
Reference: Maze used to demonstrate Dijkstra's algorithm, Wikipedia [https://en.wikipedia.org/wiki/Dijkstra's_algorithm]
Source code in gym_classics2/envs/gym_classics2/L_maze.py
gym_classics2.envs.gym_classics2.sparse_gridworld.SparseGridworld
Bases: NoisyGridworld
A 10x8 featureless gridworld. The agent starts in cell (1, 3) and the goal is at
cell (6, 3). To make it more challenging, the same 80-10-10 transition probabilities
from ClassicGridworld are used. Great for testing various forms of credit
assignment in the presence of noise.
reference: cite{3} (page 147, figure 7.4).
states: Grid location.
actions: Move up/right/down/left.
rewards: +1 for episode termination.
termination: Reaching the goal.
Source code in gym_classics2/envs/gym_classics2/sparse_gridworld.py
gym_classics2.envs.gym_classics2.windy_gridworld.WindyGridworld
Bases: Gridworld
A 10x7 deterministic gridworld where some columns are affected by an upward wind. The agent starts in cell (0, 3) and the goal is at cell (7, 3). If an agent executes an action from a cell with wind, the resulting position is given by the vector sum of the action's effect and the wind.
reference: cite{3} (page 130, example 6.5).
state: Grid location.
actions: Move up/right/down/left.
rewards: -1 for all transitions unless the episode terminates.
termination: Reaching the goal.
Source code in gym_classics2/envs/gym_classics2/windy_gridworld.py
gym_classics2.envs.gym_classics2.linear_walks.Walk5
Bases: LinearWalk
A 5-state deterministic linear walk. Ideal for implementing random walk experiments.
reference: cite{3} (page 125).
state: Discrete position {0, ..., 4} on the number line.
actions: Move left/right.
rewards: +1 for moving right in the extreme right state.
termination: Moving right in the extreme right state or moving left in the extreme left state.
Source code in gym_classics2/envs/gym_classics2/linear_walks.py
gym_classics2.envs.gym_classics2.linear_walks.Walk19
Bases: LinearWalk
Same as 5Walk but with 19 states and an additional -1 reward for moving left
in the extreme left state.
reference: cite{3} (page 145).