首页 技术 正文
技术 2022年11月21日
0 收藏 342 点赞 3,832 浏览 5646 个字

强化学习读书笔记 – 13 – 策略梯度方法(Policy Gradient Methods)

学习笔记:
Reinforcement Learning: An Introduction, Richard S. Sutton and Andrew G. Barto c 2014, 2015, 2016

参照

需要了解强化学习的数学符号,先看看这里:

策略梯度方法(Policy Gradient Methods)

基于价值函数的思路

\[
\text{Reinforcement Learning} \doteq \pi_* \\
\quad \updownarrow \\
\pi_* \doteq \{ \pi(s) \}, \ s \in \mathcal{S} \\
\quad \updownarrow \\
\begin{cases}
\pi(s) = \underset{a}{argmax} \ v_{\pi}(s' | s, a), \ s' \in S(s), \quad \text{or} \\
\pi(s) = \underset{a}{argmax} \ q_{\pi}(s, a) \\
\end{cases} \\
\quad \updownarrow \\
\begin{cases}
v_*(s), \quad \text{or} \\
q_*(s, a) \\
\end{cases} \\
\quad \updownarrow \\
\text{approximation cases:} \\
\begin{cases}
\hat{v}(s, \theta) \doteq \theta^T \phi(s), \quad \text{state value function} \\
\hat{q}(s, a, \theta) \doteq \theta^T \phi(s, a), \quad \text{action value function} \\
\end{cases} \\
where \\
\theta \text{ – value function's weight vector} \\
\]

策略梯度方法的新思路(Policy Gradient Methods)

\[
\text{Reinforcement Learning} \doteq \pi_* \\
\quad \updownarrow \\
\pi_* \doteq \{ \pi(s) \}, \ s \in \mathcal{S} \\
\quad \updownarrow \\
\pi(s) = \underset{a}{argmax} \ \pi(a|s, \theta) \\
where \\
\pi(a|s, \theta) \in [0, 1] \\
s \in \mathcal{S}, \ a \in \mathcal{A} \\
\quad \updownarrow \\
\pi(a|s, \theta) \doteq \frac{exp(h(s,a,\theta))}{\sum_b exp(h(s,b,\theta))} \\
\quad \updownarrow \\
exp(h(s,a,\theta)) \doteq \theta^T \phi(s,a) \\
where \\
\theta \text{ – policy weight vector} \\
\]

策略梯度定理(The policy gradient theorem)

情节性任务

如何计算策略的价值\(\eta\)
\[
\eta(\theta) \doteq v_{\pi_\theta}(s_0) \\
where \\
\eta \text{ – the performance measure} \\
v_{\pi_\theta} \text{ – the true value function for } \pi_\theta \text{, the policy determined by } \theta \\
s_0 \text{ – some particular state} \\
\]

  • 策略梯度定理
    \[
    \nabla \eta(\theta) = \sum_s d_{\pi}(s) \sum_{a} q_{\pi}(s,a) \nabla_\theta \pi(a|s, \theta) \\
    where \\
    d(s) \text{ – on-policy distribution, the fraction of time spent in s under the target policy } \pi \\
    \sum_s d(s) = 1 \\
    \]

蒙特卡洛策略梯度强化算法(ERINFORCE: Monte Carlo Policy Gradient)

  • 策略价值计算公式
    \[
    \begin{align}
    \nabla \eta(\theta)
    & = \sum_s d_{\pi}(s) \sum_{a} q_{\pi}(s,a) \nabla_\theta \pi(a|s, \theta) \\
    & = \mathbb{E}_\pi \left [ \gamma^t \sum_a q_\pi(S_t,a) \nabla_\theta \pi(a|s, \theta) \right ] \\
    & = \mathbb{E}_\pi \left [ \gamma^t G_t \frac{\nabla_\theta \pi(A_t|S_t, \theta)}{\pi(A_t|S_t, \theta)} \right ]
    \end{align}
    \]

  • Update Rule公式
    \[
    \begin{align}
    \theta_{t+1}
    & \doteq \theta_t + \alpha \gamma^t G_t \frac{\nabla_\theta \pi(A_t|S_t, \theta)}{\pi(A_t|S_t, \theta)} \\
    & = \theta_t + \alpha \gamma^t G_t \nabla_\theta \log \pi(A_t|S_t, \theta) \\
    \end{align}
    \]

  • 算法描述(ERINFORCE: A Monte Carlo Policy Gradient Method (episodic))
    请看原书,在此不做拗述。

带基数的蒙特卡洛策略梯度强化算法(ERINFORCE with baseline)

  • 策略价值计算公式
    \[
    \begin{align}
    \nabla \eta(\theta)
    & = \sum_s d_{\pi}(s) \sum_{a} q_{\pi}(s,a) \nabla_\theta \pi(a|s, \theta) \\
    & = \sum_s d_{\pi}(s) \sum_{a} \left ( q_{\pi}(s,a) – b(s)\right ) \nabla_\theta \pi(a|s, \theta) \\
    \end{align} \\
    \because \\
    \sum_{a} b(s) \nabla_\theta \pi(a|s, \theta) \\
    \quad = b(s) \nabla_\theta \sum_{a} \pi(a|s, \theta) \\
    \quad = b(s) \nabla_\theta 1 \\
    \quad = 0 \\
    where \\
    b(s) \text{ – an arbitrary baseline function, e.g. } b(s) = \hat{v}(s, w) \\
    \]

  • Update Rule公式
    \[
    \delta = G_t – \hat{v}(s, w) \\
    w_{t+1} = w_{t} + \beta \delta \nabla_w \hat{v}(s, w) \\
    \theta_{t+1} = \theta_t + \alpha \gamma^t \delta \nabla_\theta \log \pi(A_t|S_t, \theta) \\
    \]

  • 算法描述
    请看原书,在此不做拗述。

角色评论算法(Actor-Critic Methods)

这个算法实际上是:

  1. 带基数的蒙特卡洛策略梯度强化算法的TD通用化。
  2. 加上资格迹(eligibility traces)

注:蒙特卡洛方法要求必须完成当前的情节。这样才能计算正确的回报\(G_t\)。
TD避免了这个条件(从而提高了效率),可以通过临时差分计算一个近似的回报\(G_t^{(0)} \approx G_t\)(当然也产生了不精确性)。
资格迹(eligibility traces)优化了(计算权重变量的)价值函数的微分值,\(e_t \doteq \nabla \hat{v}(S_t, \theta_t) + \gamma \lambda \ e_{t-1}\)。

  • Update Rule公式
    \[
    \delta = G_t^{(1)} – \hat{v}(S_t, w) \\
    \quad = R_{t+1} + \gamma \hat{v}(S_{t+1}, w) – \hat{v}(S_t, w) \\
    w_{t+1} = w_{t} + \beta \delta \nabla_w \hat{v}(s, w) \\
    \theta_{t+1} = \theta_t + \alpha \gamma^t \delta \nabla_\theta \log \pi(A_t|S_t, \theta) \\
    \]

  • Update Rule with eligibility traces公式
    \[
    \delta = R + \gamma \hat{v}(s', w) – \hat{v}(s', w) \\
    e^w = \lambda^w e^w + \gamma^t \nabla_w \hat{v}(s, w) \\
    w_{t+1} = w_{t} + \beta \delta e_w \\
    e^{\theta} = \lambda^{\theta} e^{\theta} + \gamma^t \nabla_\theta \log \pi(A_t|S_t, \theta) \\
    \theta_{t+1} = \theta_t + \alpha \delta e^{\theta} \\
    where \\
    R + \gamma \hat{v}(s', w) = G_t^{(0)} \\
    \delta \text{ – TD error} \\
    e^w \text{ – eligibility trace of state value function} \\
    e^{\theta} \text{ – eligibility trace of policy value function} \\
    \]

  • 算法描述
    请看原书,在此不做拗述。

针对连续性任务的策略梯度算法(Policy Gradient for Continuing Problems(Average Reward Rate))

  • 策略价值计算公式
    对于连续性任务的策略价值是每个步骤的平均奖赏
    \[
    \begin{align}
    \eta(\theta) \doteq r(\theta)
    & \doteq \lim_{n \to \infty} \frac{1}{n} \sum_{t=1}^n \mathbb{E} [R_t|\theta_0=\theta_1=\dots=\theta_{t-1}=\theta] \\
    & = \lim_{t \to \infty} \mathbb{E} [R_t|\theta_0=\theta_1=\dots=\theta_{t-1}=\theta] \\
    \end{align}
    \]

  • Update Rule公式
    \[
    \delta = G_t^{(1)} – \hat{v}(S_t, w) \\
    \quad = R_{t+1} + \gamma \hat{v}(S_{t+1}, w) – \hat{v}(S_t, w) \\
    w_{t+1} = w_{t} + \beta \delta \nabla_w \hat{v}(s, w) \\
    \theta_{t+1} = \theta_t + \alpha \gamma^t \delta \nabla_\theta \log \pi(A_t|S_t, \theta) \\
    \]

  • Update Rule Actor-Critic with eligibility traces (continuing) 公式
    \[
    \delta = R – \bar{R} + \gamma \hat{v}(s', w) – \hat{v}(s', w) \\
    \bar{R} = \bar{R} + \eta \delta \\
    e^w = \lambda^w e^w + \gamma^t \nabla_w \hat{v}(s, w) \\
    w_{t+1} = w_{t} + \beta \delta e_w \\
    e^{\theta} = \lambda^{\theta} e^{\theta} + \gamma^t \nabla_\theta \log \pi(A_t|S_t, \theta) \\
    \theta_{t+1} = \theta_t + \alpha \delta e^{\theta} \\
    where \\
    R + \gamma \hat{v}(s', w) = G_t^{(0)} \\
    \delta \text{ – TD error} \\
    e^w \text{ – eligibility trace of state value function} \\
    e^{\theta} \text{ – eligibility trace of policy value function} \\
    \]

  • 算法描述(Actor-Critic with eligibility traces (continuing))
    请看原书,在此不做拗述。
    原书还没有完成,这章先停在这里

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,858