Main Content

创建自定义网格世界环境

网格世界是一种基于细胞的基于细胞的环境,其中代理从一个电池开始并朝向终端电池移动,同时收集尽可能多的奖励。网格世界环境对于应用强化学习算法,可以在网格上发现最佳路径和政策,以便在最少的移动中到达终端目标。

钢筋学习工具箱™允许您创建自定义MATLAB®网格世界为您自己的应用程序环境。T.O.create a custom grid world environment:

  1. 创建网格世界模型。

  2. 配置网格世界模型。

  3. 使用网格世界模型创建自己的网格世界环境。

Grid World Model

您可以使用自己的网格世界模型creategridworld.功能。创建时指定网格尺寸Gridworld.模型对象。

Gridworld.对象具有以下属性。

财产 R.ead-Only 描述
网格化 是的

网格世界的尺寸,显示为M.-经过-N.大批。这里,M.表示网格行的数量和N.是网格列的数量。

当前状态 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[1,1]默认。

代理人从中开始当前状态O.N.ce you use the reset function in theR.L.MDPEnv环境对象。

状态 是的

包含网格世界的状态名称的字符串矢量。例如,对于2×2网格世界模型GW.,指定以下内容:

gw.states = [“[1,1]”;“[2,1]”;“[1,2]”;“[2,2]”];
行动 是的

一个字符串矢量,包含代理可以使用的可能操作的列表。您可以使用使用时创建网格世界模型时设置操作移动一种R.gument:

gw = creategridworld(m,n,moves)

指定移动as'标准'O.R.'Kings'

移动 GW.Actions.
'标准' ['n';'e';'w']
'Kings' ['n';'e';'w';'n';'nw';'se';'sw']
T. No

状态转换矩阵,指定为3-D阵列。T.是一种概率矩阵,其表示从当前状态移动的代理的可能性S.任何可能的下一个州S'B.yP.erforming action一种

T.可以表示为

T. S. S. ' 一种 的) = P. R. O. B. 一种 B. 一世 L. 一世 T. y S. ' | S. 一种 的)

例如,考虑一个5×5的确定性网格世界对象GW.用细胞中的药剂[3,1]。查看北方方向的状态转换矩阵。

NorthstateTransition = GW.T(:,:1)

从上图,值N.O.R.T.hStateTransition(3,2)由于代理从细胞移动,因此是1[3,1]到细胞[2,1]有行动'n'。A probability of 1 indicates that from a given state, if the agent goes north, it has a 100% chance of moving one cell north on the grid. For an example showing how to set up the state transition matrix, seeT.R.一种一世N.R.einforcement Learning Agent in Basic Grid World

R. No

奖励转换矩阵,指定为3-D阵列。R.确定在环境中执行动作后代理收到的奖励。R.具有与状态转换矩阵相同的形状和尺寸T.

奖励过渡矩阵R.可以表示为

R. = R. S. S. ' 一种 的)

设置R.S.uch that there is a reward to the agent after every action. For instance, you can set up a positive reward if the agent transitions over obstacle states and when it reaches the terminal state. You can also set up a default reward of -11 for all actions the agent takes, independent of the current state and next state. For an example that show how to set up the reward transition matrix, seeT.R.一种一世N.R.einforcement Learning Agent in Basic Grid World

ObstacleStates No

ObstacleStates是在网格世界中无法达到的状态,指定为串向量。考虑以下5×5网格世界模型GW.

黑色细胞是障碍状态,您可以使用以下语法指定它们:

GW.。ObstacleStates = ["[3,3]";“[3,4]”;“[3,5]”;“[4,3]”];

对于工作流示例,请参阅T.R.一种一世N.R.einforcement Learning Agent in Basic Grid World

T.erminalStates No

T.erminalStates一种R.e the final states in the grid world, specified as a string vector. Consider the previous 5-by-5 grid world modelGW.。蓝色单元格是终端状态,您可以通过以下方式指定:

gw.terminalstates =“[5,5]”;

对于工作流示例,请参阅T.R.一种一世N.R.einforcement Learning Agent in Basic Grid World

网格世界环境

您可以使用Markov决策过程(MDP)环境R.L.MDPEnvfrom 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 objectR.L.MDPEnv与网格世界模型对象互动Gridworld.

有关更多信息,请参阅R.L.MDPEnv一种N.dT.R.一种一世N.R.einforcement Learning Agent in Basic Grid World

也可以看看

||

R.elated Topics