Lecture 9: Policy Gradient Methods
强化学习中的数学原理 | 第九课

之前介绍的方法都是
value-based,这节课的方法将是policy-based,policy-based会直接建立一个策略的目标函数,通过优化这个目标函数就可以直接得到最优的策略会讲 REINFORCE 算法
先前,policy都是用以
现在,我们把policy表述成 parameterized functions:
- Advantage: state space 非常大时,函数形式能优化存储和泛化能力(如果是表格,必须要访问到
才能更新对应的概率,但是函数修改参数后会改变更多) 都是等价的写法
Differences between tabular and function representations:
-
- 定义最优策略的方式不一样
- 表格形式中,对所有state保证
- 函数形式,则会有一个scalar metrics,要去maximize他
-
- 获取一个action的probability的方式不一样
- 表格的话直接查表
- 函数则是代入计算
-
- 更新策略的方式不一样
- 表格是直接替换表格里的值
- 函数是改变参数
The basic idea of the policy gradient is simple
- First, metrics(度量) 一个目标函数:
,来定义最优策略 - Second, gradient-based optimization algorithms to search for optimal policies:
尽管思路看起来很简单,但实际做的时候会遇到复杂的情况:
- What appropriate metrics should be used?
- How to calculate the gradient of the metrics
一般我们会遇到两大metrics:
The first metric is the average state value or simply called average value. In particular, the metric is defined as
- 是state value的加权平均
是权重,且 - The metric can alse be written as
where - Vector-product form:
接下来讲 How to select the distribution
一种是


这个有点没看懂
The second metric is average one-step reward or simply average reward. In particular, the metric is
where
对于
,先对 求和,再对 加权平均
在论文中还经常遇到第二个reward的另一种形式:
- Suppose an agent follows a given policy and generate a trajectory with the rewards as
- The average single-step reward along this trajectory is
where
当跑了无穷多步时,起点在哪已经不重要了
这就和第一种形式统一起来了
实际上
我们把 的两个形式推导一下
- It starts from
and then and
前面我们讲了 metrics,我对这一块还没有太熟悉,继续往后听是这么应用的
接下来就要对这些metrics求gradient,之后就可以用梯度上升的方法来优化我们的policy
提前讲一下,计算 gradient是整个policy gradient methods里最复杂的部分!That’s because:
- first, we need to distinguish different metrics
( 指不同s的权重和policy没有关系,前面有提到过权重和policy无关和有关两种情况) - second, 我们要区分 discounted and undiscounted cases.
关于梯度的计算,不会讲太多的细节,具体细节可以看书
Summary of the results about the gradients:
where
can be- 这里的 ‘
’ 其实有3种情况: 是states的权重
A compact and useful form of the gradient:
where
why is this expression useful?
- Because we can use samples to approximate the gradient!
推导:
首先:
分母乘上去:
Then, we have
回顾一下,前面两节我们分别在讲目标函数和目标函数的梯度,接下来我们就会把梯度代入到梯度上升的算法进行优化,会给出第一个policy gradient算法 REINFORCE
- The gradient-ascent algorithm maximizing
is
- 我们可以用随机梯度来代替真实的梯度
不过这个式子也是不能用的,因为
这里把采样的记作
- 第一种,最直观的:Monte-Carlo based Method,
REINFORCE - 下节课会讲 TD method
涉及到的随机变量是
- 采样
, where the distribution is a long-rum behavior under
- 采样
,所以 的采样就follow at- There, the policy gradient method is on-policy
Since
the algorithm can be rewritten as
Therefore, we have the important expression of the algorithm:
这个算法就是在通过改变
Intuition: When
- If
, the probability of choosing is enhances:
- Else if
, then
如何证明
Math: When
The coefficient
- First,
is proportional 成正比 to- If
is great, then is great - 如果之前这个action value大,那我就会给他更大的概率选这个action
exploitation - Therefore, the algorithm intends to enhance actions with greater
- If
- Second,
is inversely proportional反比 to- If
is small, then is large - 如果之前做
概率比较小,接下来会给他更大的概率exploration - Therefore, the algorithm intends to explore actions that have low
- If
回顾一下

- 如果
用蒙特卡洛法来估计,这就是REINFORCE

注意policy update里产生
核心是一个优化问题,思路较为简单,但在看里面的每一项时相当复杂,需要进一步熟悉学习