Create Custom Grid World Environments
A grid world is a two-dimensional, cell-based environment where the agent starts from one cell and moves toward the terminal cell while collecting as much reward as possible. Grid world environments are useful for applying reinforcement learning algorithms to discover optimal paths and policies for agents on the grid to arrive at the terminal goal in the fewest moves.
Reinforcement Learning Toolbox™ lets you create custom MATLAB® grid world environments for your own applications. To create a custom grid world environment:
Create the grid world model.
Configure the grid world model.
Use the grid world model to create your own grid world environment.
Grid World Models
You can create your own grid world model using the createGridWorld
function. Specify the grid size when creating the GridWorld
object.
The GridWorld
object has the following properties.
Property | Read-Only | Description | ||||||
---|---|---|---|---|---|---|---|---|
GridSize | Yes | Dimensions of the grid world, displayed as an m-by-n array. Here, m represents the number of grid rows and n is the number of grid columns. | ||||||
CurrentState | No | Name of the current state of the agent, specified as a string. You can
use this property to set the initial state of the agent. The agent always starts
from cell The agent
starts from the | ||||||
States | Yes | A string vector containing the state names of the grid world. For
instance, for a 2-by-2 grid world model GW.States = ["[1,1]"; "[2,1]"; "[1,2]"; "[2,2]"]; | ||||||
Actions | Yes | A string vector containing the list of possible actions that the agent
can use. You can set the actions when you create the grid world model by using the
GW = createGridWorld(m,n,moves) Specify
| ||||||
T | No | State transition matrix, specified as a 3-D array.
For instance, consider a 5-by-5 deterministic grid world
object northStateTransition = GW.T(:,:,1) From the above figure, the value of
| ||||||
R | No | Reward transition matrix, specified as a 3-D array. The reward transition matrix
Set up | ||||||
ObstacleStates | No |
The black cells are obstacle states, and you can specify them using the following syntax: GW.ObstacleStates = ["[3,3]";"[3,4]";"[3,5]";"[4,3]"]; For a workflow example, see Train Reinforcement Learning Agent in Basic Grid World. | ||||||
TerminalStates | No |
GW.TerminalStates = "[5,5]"; For a workflow example, see Train Reinforcement Learning Agent in Basic Grid World. |
Grid World Environments
You must create a Markov decision process (MDP) environment using
rlMDPEnv
from the
grid world model from the previous step. MDP is a discrete-time stochastic control process.
It provides a mathematical framework for
modeling decision making in situations where outcomes are partly random and partly under the
control of the decision maker. The agent uses the grid world environment object
rlMDPEnv
to interact with the grid world model object
GridWorld
.
For more information, see rlMDPEnv
and Train Reinforcement Learning Agent in Basic Grid World.