skip to content
[Jimjimu Notes]

Chapter 1: Basic Concepts in Reinforcement Learning

/ 6 min read

Table of Contents

A grid-world example

一个网格世界,非常经典的例子 alt text

机器人可以到达相邻的网格,不能进入forbidden的网格,且网格四周有边界

  • 任务:找到一个比较好的路径从起点到终点

State

在网格世界中,state就是agent的位置。比如下图中有9个状态:s1,...,s9s_1, ..., s_9 alt text

Action

对于每个状态,Agent可采取的行动叫做Action。例如:

  • a1a_1: move upward;
  • a2a_2: move rightward;
  • a3a_3: move downward;
  • a4a_4: move leftward.

State transition 状态转移

当agent采取一个action的时候,状态会从一个转移到另一个,这种过程叫做状态转移, 用如下符号表示:

s1a1s2s_1 \xrightarrow{a_1} s_2

其中

  • s1,s2Ss_1, s_2 \in \mathcal{S}
  • a1A(s1)a_1 \in \mathcal{A}(s_1)

State transition定义了Agent和环境交互的规则。比如以下例子: alt text

本课程采用case1

用表格表示state transition

ii行第jj列表示siajsks_i \xrightarrow{a_j} s_k

alt text

局限性:只能表示确定性的情况

State transition probability

用概率(条件概率)去表示state transition

  • Intuition 直觉:At state s1, if we choose action a2, the next state is s2
  • 数学表示:
p(s2s1,a2)=1p(sis1,a2)=0,i2p(s_2 \mid s_1,a_2) = 1 \\ p(s_i \mid s_1,a_2) = 0, \forall i \not = 2 \\

Policy

策略告诉Agent在某个状态下采取什么动作

用箭头表示

alt text

数学表示

也是采用条件概率表示,比如在s1s_1:

π(a1s1)=0π(a2s1)=1π(a3s1)=0π(a4s1)=0π(a5s1)=0\pi(a_1 \mid s_1) = 0 \\ \pi(a_2 \mid s_1) = 1 \\ \pi(a_3 \mid s_1) = 0 \\ \pi(a_4 \mid s_1) = 0 \\ \pi(a_5 \mid s_1) = 0 \\

也有随机的(stochastic)策略 alt text

用表格表示

ii行第jj列表示sis_i的状态下,采取动作aja_j的概率,即π(siaj)\pi(s_i \mid a_j)的数值

alt text

Reward

Reward是一个实数标量

  • A positive reward represents encouragement to take such actions.
  • A negative reward represents punishment to take such actions

比如说,在之前的网格世界,agent想要走出边界,那么我们可以让rbound=1r_{bound} = -1

同样的,可以用表格表示reward alt text

也可以用数学表示,例如: p(r=1s1,a1)=1p(r=-1 \mid s_1,a_1) = 1 and p(r1s1,a1)=0p(r \not = 1 \mid s_1,a_1) = 0

Trajectory and return

轨迹是一个 state-action-reward 链

s1r1a1s2r2a2rTaTsT+1s_1 \xrightarrow[r_1]{a_1} s_2 \xrightarrow[r_2]{a_2} \dots \xrightarrow[r_T]{a_T} s_{T+1}

return是轨迹中所有reward的和,数学上可以用return刻画一个策略的好坏

Discounted return 折扣汇报

为什么需要这么一个东西呢,看以下这种情况,一个轨迹:

s1a2s2a3s8a2s9a5s9s_1 \xrightarrow{a_2} s_2 \xrightarrow{a_3} s_8 \xrightarrow{a_2} s_9 \xrightarrow{a_5} s_9 \dots

此时return发散:

return=0+0+0+1+1+1=return = 0 + 0 + 0 + 1 + 1 + 1 = \dots alt text

由此定义discount rate 折扣因子 γ(0,1)\gamma \in (0,1),则discount return 定义为:

discount return=0+γ0+γ20+γ31+γ41+γ51+=γ3+γ4+γ5+=γ31γ\begin{aligned} \text{discount return} &= 0 + \gamma 0 + \gamma^2 0 + \gamma^3 1 + \gamma^4 1 + \gamma^5 1 + \dots \\ & = \gamma^3 + \gamma^4 + \gamma^5 + \dots \\ & = \frac{\gamma^3}{1-\gamma} \end{aligned}

折扣汇报的作用:

  • 让无限回报成为有限值
  • 平衡近期奖励与远期奖励

γ\gamma 接近 0 时:

γk0\gamma^k\rightarrow0

智能体主要关心马上获得的奖励,表现得比较“短视”。 当 γ\gamma 接近 1 时,远期奖励衰减得比较慢,智能体更愿意为了将来的较大收益暂时放弃当前收益。

Episode

智能体按照某个策略 π\pi 与环境不断交互

StAt,  Rt+1St+1S_t \xrightarrow{A_t,\;R_{t+1}} S_{t+1}

如果最终到达某个终止状态 terminal state,交互就停止。从初始状态到终止状态的trajactory,称为一个 Episode,也叫 trial。

一个episode通常是一个有限的轨迹。

  • 存在明确起点和终点、每次到达终止状态后重新开始的任务,称为episodic tasks
  • 如果任务的轨迹可能是无限的,则称为continuous tasks

在网格世界示例中,我们是否应该在到达目标后停止?

  • 将目标状态视为具有策略的正常状态。智能体仍然可以离开目标状态,并在进入目标状态时获得r = +1的奖励。
  • 我们无需将目标状态与其他状态区分开来,可以将其视为正常状态

Markov decision process (MDP)

Key elements of MDP:

  • Sets:
    • State: the set of states S\mathcal{S}
    • Action: the set of actions A(s)\mathcal{A}(s) is associated for state sSs \in \mathcal{S}.
    • Reward: the set of rewards R(s,a)\mathcal{R}(s, a).
  • Probability distribution (or called system model):
    • State transition probability: at state ss, taking action aa, the probability to transit to state ss' is p(ss,a)p(s'|s, a)
    • Reward probability: at state ss, taking action aa, the probability to get reward rr is p(rs,a)p(r|s, a)
  • Policy: at state ss, the probability to choose action aa is π(as)\pi(a|s)
  • Markov property: memoryless property p(st+1at,st,,a0,s0)=p(st+1at,st),p(s_{t+1}|a_t, s_t, \dots, a_0, s_0) = p(s_{t+1}|a_t, s_t), p(rt+1at,st,,a0,s0)=p(rt+1at,st).p(r_{t+1}|a_t, s_t, \dots, a_0, s_0) = p(r_{t+1}|a_t, s_t).

All the concepts introduced in this lecture can be put in the framework in MDP.

alt text