Skip to content
Jambity's Blog

Lecture 9: Policy Gradient Methods

强化学习中的数学原理 | 第九课

RL,强化学习中的数学原理5min read...

之前介绍的方法都是value-based,这节课的方法将是policy-based,policy-based会直接建立一个策略的目标函数,通过优化这个目标函数就可以直接得到最优的策略

会讲 REINFORCE 算法

先前,policy都是用以和为维度的表格来表示的

现在,我们把policy表述成 parameterized functions:

  • Advantage: state space 非常大时,函数形式能优化存储和泛化能力(如果是表格,必须要访问到才能更新对应的概率,但是函数修改参数后会改变更多)
  • 都是等价的写法

Differences between tabular and function representations:

    1. 定义最优策略的方式不一样
    • 表格形式中,对所有state保证
    • 函数形式,则会有一个scalar metrics,要去maximize他
    1. 获取一个action的probability的方式不一样
    • 表格的话直接查表
    • 函数则是代入计算
    1. 更新策略的方式不一样
    • 表格是直接替换表格里的值
    • 函数是改变参数

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 ? There are two cases.

一种是和没有关系,另一种是和有关系

1787899715766

1787900454810

这个有点没看懂

The second metric is average one-step reward or simply average reward. In particular, the metric is

where . Here,

对于 ,先对 求和,再对 加权平均

在论文中还经常遇到第二个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 is the starting state of the trajectory

当跑了无穷多步时,起点在哪已经不重要了

这就和第一种形式统一起来了

实际上也有两种形式,我们把他们一起整理一下:

我们把的两个形式推导一下
  • 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 and

why is this expression useful?

  • Because we can use samples to approximate the gradient!

How to prove the above equation

推导:

首先:

分母乘上去:

Then, we have

省略下标

回顾一下,前面两节我们分别在讲目标函数和目标函数的梯度,接下来我们就会把梯度代入到梯度上升的算法进行优化,会给出第一个policy gradient算法 REINFORCE

  • The gradient-ascent algorithm maximizing is

  • 我们可以用随机梯度来代替真实的梯度

不过这个式子也是不能用的,因为是策略对应的真实的action value,我们没有这个,所以我们要用一个办法近似得到

这里把采样的记作了,我们有几种方法来估计得到这个

  • 第一种,最直观的:Monte-Carlo based Method, REINFORCE
  • 下节课会讲 TD method
Remark 1: 我们该怎么采样估计?

涉及到的随机变量是,我们该怎么对和采样呢?

  • 采样
    • , where the distribution is a long-rum behavior under
  • 采样
    • ,所以的采样就follow at
    • There, the policy gradient method is on-policy
Remark 2: How to interpret this algorithm

Since

the algorithm can be rewritten as

Therefore, we have the important expression of the algorithm:

这个算法就是在通过改变来优化的值

Intuition: When is sufficiently small

  • If , the probability of choosing is enhances:

  • Else if , then

如何证明

Math: When is sufficiently small, 可以一阶泰勒展开, we have


The coefficient can well balance exploration and exploitation. 平衡探索与充分利用,为什么这么说?

  • First, is proportional 成正比 to
    • If is great, then is great
    • 如果之前这个action value大,那我就会给他更大的概率选这个action exploitation
    • Therefore, the algorithm intends to enhance actions with greater
  • Second, is inversely proportional反比 to
    • If is small, then is large
    • 如果之前做概率比较小,接下来会给他更大的概率 exploration
    • Therefore, the algorithm intends to explore actions that have low

回顾一下

1787921001473

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

1787921098529

注意policy update里产生后没有立即更新数据,因为蒙特卡洛法是off-line离线的,需要把所有episode采集完再开始跑,之后TD的方法是on-line的

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

Comments

© Jambity. All rights reserved.......