Skip to main content

SimpleMazeMDP:

This repository contains code to provide a simple Maze environment used as example MDP for tabular dynamic programming and reinforcement learning labs.

If you want to do the corresponding labs, you need a Google account. Then you can copy-paste the dynamic programming colab and the reinforcement learning colab.

Documentation

MDPs and mazes

Some code is provided to create mazes, transform them into MDPs and visualize them together with policies or value functions. It is contained into three files: *maze.py, mdp.py and maze_plotter.py. The following sections give an overview of this code.

Content of the maze.py file

A maze is represented as an object of the Maze class. It is defined as a grid of width x height cells, and some of these cells contain a wall.

The build_maze(width, height, walls, hit=False) function is used to create a Maze, where walls is a list of the number of the cells which contain a wall. The hit parameter has an impact on the MDP reward function: if hit is true, the agent is penalized each time it tries to move to a wall cell. Otherwise, the agent is just rewarded when it reaches terminal states. In the provided function, the list of terminal states is a singleton corresponding to the last cell that the agent can visit.

Apart from representing the two reward functions described above, the Maze class contains a constructor whose only role is to create the MDP corresponding to the maze and the maze plotter used to display simulations. A key point is that only cells where there is no wall are considered as states of the underlying MDP. To facilitate the correspondence between mazes and MDPs, each free cell (i.e. with no wall) knows the number of its corresponding MDP state.

The maze constructors also builds the action space, the initial state distribution, the transition function and the reward function of the MDP. Once all these data structures have been created, the resulting MDP is built.

A build_maze() and a create_random_maze() functions are provided to create mazes in the lab notebooks or python files.

Content of the mdp.py file

The mdp.py file contains the SimpleActionSpace class and the Mdp class.

The SimpleActionSpace class contains the list of actions and a method to sample from this list. In our maze environment, the possible actions for the agent are going north, south, east or west (resp. [0, 1, 2, 3]).

The Mdp class is designed to be compatible with the OpenAI gym interface (https://gym.openai.com/). The main methods are reset(self, uniform=False), which resets the MDP into an initial state drawn from the initial state distribution, and step(self, u, deviation=0) which is used to let the agent perform a step in the environment, sending and action and receiving the next state, the reward, and a signal telling whether a terminal state was reached. The function render(self) provides a visual rendering of the current state of the simulation.

Content of the maze_plotter.py file

The code to display the effect of the algorithms in these environments is in maze_plotter.py, in the MazePlotter class. In order to visualize the environment, you use the new_render() function to initialize the rendering, then render(V, policy, agent_pos) to refresh the maze with either the newly calculated state values and the policy, or the state-action values, and eventually the current position of the agent. There is also a render_pi(policy) function which only displays the policy (useful for policy iteration). The function save_fig(title) is used to save the last render into a file.

You can see examples of calls to these different visualizations in the functions defined in dynamic programming and reinforcement learning notebooks or python files.

Toolbox

The toolbox.py file provide a few useful functions such as egreedy(), egreedy_loc() and softmax() which are used to perform exploration in reinforcement learning algorithms.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mazemdp-1.3.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mazemdp-1.3.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file mazemdp-1.3.0.tar.gz.

File metadata

  • Download URL: mazemdp-1.3.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mazemdp-1.3.0.tar.gz
Algorithm Hash digest
SHA256 fed832b91f568015b963d971d14dc83f0648573a2fc430b1dbf6c988fba12ca9
MD5 ecf9a0db5e878fc24a3a9f91561610ea
BLAKE2b-256 7acaf8b27c5fc8aff6e646c4ba7903e7b6cc5917b988d037544396acf922c0b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mazemdp-1.3.0.tar.gz:

Publisher: python-publish.yml on osigaud/SimpleMazeMDP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mazemdp-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: mazemdp-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mazemdp-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daf82136d6fc97390b922818ba68d2ffc3dc4798c2d860687b5edfabef524ea8
MD5 be3ec7aee40a10da66d8c28896bdba22
BLAKE2b-256 3c3a3d3e1a1de8d9ecaa73dac61481177184373a3b40850147ffd0e23cbf81d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mazemdp-1.3.0-py3-none-any.whl:

Publisher: python-publish.yml on osigaud/SimpleMazeMDP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 files

1.2.13

2 files

1.2.12

2 files

1.2.11

2 files

1.2.10

2 files

1.2.9

2 files

1.2.8

2 files

1.2.7

2 files

1.2.6

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1

2 files

1.0

2 files

0.9.1

2 files

0.9

2 files

0.8.1

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7

2 files

0.6

2 files

0.1.1

1 file

0.1.0

1 file

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page