Chapter 9 On-policy Prediction with Approximation

本文为《Reinforcement Learning: An Introduction》读书笔记

之前学习的方法都是基于表格的方法,现在要用approximation来替换表格。

本书后面的两个重点:
1. update target
2. updte distribution

9.1 Value-function Approximation

Machine learning methods that learn to mimic input-output examples in this way are called supervised learning methods, and when the outputs are numbers, like u, the process is often called function approximation

正因为学习approximation function的过程是监督学习过程,所以介意使用任意函数来做监督学习,比如神经网络。

9.2 The Prediction Objective ( VE¯¯¯¯¯¯¯¯ V E ¯ )

Mean Squared Value Error,即 VE¯¯¯¯¯¯¯¯ V E ¯

VE¯¯¯¯¯¯¯¯(w)sSμ(s)[vπ(s)v^(s,w)]2 V E ¯ ( w ) ≐ ∑ s ∈ S μ ( s ) [ v π ( s ) − v ^ ( s , w ) ] 2

其中 v^(s,w) v ^ ( s , w ) 为 approximate value; vπ(s) v π ( s ) 为true value; μ(s) μ ( s ) 表示处于状态s的时间百分比,在 on-policy training μ(s) μ ( s ) 被称为 on-policy distribution
这也是本章要讲的内容
The on-policy distribution in episodic tasks
对于连续任务, on-policy distribution就是在 π π 下的状态分布。

9.3 Stochastic-gradient and Semi-gradient Methods

在梯度下降方法中,使用权重向量 w(w1,w2,,wd)T w ≐ ( w 1 , w 2 , ⋯ , w d ) T ,来approximate value function v^(s,w) v ^ ( s , w )

Stochastic gradient-descent (SGD)

wt+1wt12[vπ(St)v^(St,wt)]2=wt+α[vπ(St)v^(St,wt)]v^(St,wt) w t + 1 ≐ w t − 1 2 ▽ [ v π ( S t ) − v ^ ( S t , w t ) ] 2 = w t + α [ v π ( S t ) − v ^ ( S t , w t ) ] ▽ v ^ ( S t , w t )

因为 vπ(s) v π ( s ) 并不是已知的,我们使用 unbiased estimate Ut U t 来代替它。
wt+1wt+α[Utv^(St,wt)]v^(St,wt) w t + 1 ≐ w t + α [ U t − v ^ ( S t , w t ) ] ▽ v ^ ( S t , w t )

在蒙特卡洛方法中, Ut U t 是可以计算出来的, UtGt U t ≐ G t ,所以梯度下降版本的蒙特卡洛 state-value prediction 保证能找到局部最优
Gradient Monte Carlo Algorithm for Estimating

如果使用 Bootstrapping 就不会得到这样的保证。
Bootstrapping将不会产生真正的梯度下降方法,原因是targets,如n-step returns Gt:t+n G t : t + n 或DP target a,s,rπ(a|St)p(s,r|St,a)[r+γv^(s,wt)] ∑ a , s ′ , r π ( a | S t ) p ( s ′ , r | S t , a ) [ r + γ v ^ ( s ′ , w t ) ] 都依赖于权重向量 wt w t 的当前值,这表示target将是有偏的,所以不会产生真正的梯度下降方法。

上面说到的这种方法,因此被称为 semi-gradient methods

虽然不保证收敛,但是使用Semi-gradient可以显著提高学习速度,而且允许连续和在线学习

Semi-gradient TD(0),使用 UtRt+1+γv^(St+1,wt) U t ≐ R t + 1 + γ v ^ ( S t + 1 , w t )
Semi-gradient TD(0) for estimating

State aggregation

状态聚合是一种简单形式的广义函数逼近,其中状态被分组在一起,每个组具有一个估计值(权重向量w的一个分量)。
状态聚类是一种特殊的SGD,这里每个state group的梯度都等于1。

9.4 Linear Methods

使用线性函数作为 approximation function,来逼近 v^(s,w) v ^ ( s , w ) 。其中 x(s) x ( s ) 被称为 feature vector,用来表示状态s

v^(s,w)wTx(s)i=1dwixi(s) v ^ ( s , w ) ≐ w T x ( s ) ≐ ∑ i = 1 d w i x i ( s )

SGD

wt+1wt+α[Utv^(St,wt)]x(St) w t + 1 ≐ w t + α [ U t − v ^ ( S − t , w t ) ] x ( S t )

semi-gradient TD(0)

wt+1wt+α(Rt+1+γwTtxt+1wTtxt)xt=wt+α(Rt+1xtxt(xtγxt+1)Twt) w t + 1 ≐ w t + α ( R t + 1 + γ w t T x t + 1 − w t T x t ) x t = w t + α ( R t + 1 x t − x t ( x t − γ x t + 1 ) T w t )

当更新达到稳定的时候,可以得到

E[wt+1|wt]=wt+α(bAwt) E [ w t + 1 | w t ] = w t + α ( b − A w t )

其中

bAE[Rt+1xt]RdE[xt(xtγxt+1)]TRd×Rd b ≐ E [ R t + 1 x t ] ∈ R d A ≐ E [ x t ( x t − γ x t + 1 ) ] T ∈ R d × R d

对于上式,因为已经达到稳定状态,所以必然收敛到权重向量 wTD w T D

bAwTDbwTD=0=AwTDA1b b − A w T D = 0 ⇒ b = A w T D ⇒ w T D ≐ A − 1 b

linear semi-gradient TD(0) 被证明是收敛到 TD fixed point的,书上有详细证明。而且在 TD fiexed point,在连续的情形下 VE¯¯¯¯¯¯¯¯ V E ¯ 被证明是在可能的最低误差的有限扩展范围内

VE¯¯¯¯¯¯¯¯(wTD)!11γminwVE¯¯¯¯¯¯¯¯(w) V E ¯ ( w T D ) ≤ ! 1 1 − γ min w V E ¯ ( w )

One-step semi-gradient action-value 方法,如 semi-gradient Sarsa(0)也收敛于类似的fixed point和类似的bound。

对于其他更新分布,使用function approximation的bootstrapping方法实际上可能会发散到无穷大。

n-step semi-gradient TD for estimating

wt+nwt+n1+α[Gt:t+nv^(St,wt+n1)]v^(St,wt+n1),0tT, w t + n ≐ w t + n − 1 + α [ G t : t + n − v ^ ( S t , w t + n − 1 ) ] ∇ v ^ ( S t , w t + n − 1 ) , 0 ≤ t ≤ T ,

Gt:t+nRt+1+γRt+2++γn1Rt+n+γnv^(St+n,wt+n1),0tTn G t : t + n ≐ R t + 1 + γ R t + 2 + ⋯ + γ n − 1 R t + n + γ n v ^ ( S t + n , w t + n − 1 ) , 0 ≤ t ≤ T − n

9.5 Feature Construction for Linear Methods

A limitation of the linear form is that it cannot take into account any interactions between features, such as the presence of feature i being good only in the absence of feature j.

9.5.1 Polynomials

使用多项式 逼近

x(s)=(1,s1,s2,s1s2,s21,s22,s1s22,s21s2,s21s22)T x ( s ) = ( 1 , s 1 , s 2 , s 1 s 2 , s 1 2 , s 2 2 , s 1 s 2 2 , s 1 2 s 2 , s 1 2 s 2 2 ) T

把上面的两个变量扩展到 k 个,则
si(s)=j=1ksci,jj s i ( s ) = ∏ j = 1 k s j c i , j

这些特征构成了n阶k维多项式,包含 (n+1)k ( n + 1 ) k 个不同的特征

9.5.2 Fourier Basis

s=(s1,s2,,sk)Txi(s)=cos(πsTci) s = ( s 1 , s 2 , ⋯ , s k ) T x i ( s ) = cos ⁡ ( π s T c i )

其中 ci=(ci1,,cik) c i = ( c 1 i , ⋯ , c k i ) , 有 cij0,,n c j i ∈ 0 , ⋯ , n for j=1,,k j = 1 , ⋯ , k and i=0,,(n+1)k i = 0 , ⋯ , ( n + 1 ) k

9.5.3 Coarse Coding

粗糙编码。表示有重叠的特征的状态。对每个训练状态,包含这个状态的所有圆相当于是特征的权重,区别在在于它们的重叠
Coarse coding
用圆来代表特征,一个状态(落到其中的某个点)与很多圆相交,就受到这么多状态的影响。学习的时候也会影响该点所涉及的所有状态

9.5.4 Tile Coding

如下图所示,每个这样的划分被称为 tiling,每个划分中的元素被称为 tile
在只有一个tiling的时候只有利用了state aggregation,只有使用multiple tiling才能使用到Coarse Coding的优势。从下图看出,每个tiling都有一个偏移。这里通常设置step-size为 α=1/n α = 1 / n
Multiple, overlapping grid-tilings
但是有个问题,当所有的offset都是一样的时候会有artifact产生,所以可以使用非对称的偏移来避免这个问题。w表示tile width,n表示tilings的数量,w/n表示基本单元。

In particular, for a continuous space of dimension k, a good choice is to use the first odd integers (1,3,5,7,…,2k-1), with n (the number of tilings) set to an integer power of 2 greater than or equal to 4k.

Why tile asymmetrical offsets are preferred

9.5.5 Radial Basis Functions

Radial basis functions (RBFs)

xi(s)exp(||sci||22δ2i) x i ( s ) ≐ exp ⁡ ( − | | s − c i | | 2 2 δ i 2 )

One-dimensional radial basis functions

9.6 Selecting Step-Size Parameters Manually

A good rule of thumb for setting the step-size parameter of linear SGD methods is then

α(τE[xTx])1 α ≐ ( τ E [ x T x ] ) − 1

9.7 Nonlinear Function Approximation: Arti cial Neural Networks

使用神经网络来做函数逼近

9.8 Least-Squares TD

上面降到的方法都是迭代法,现在用代数的方式一次算出结果。而且LSTD的数据利用率高

计算出A和b,然后一次性计算出 wt w t 。跟上面讲的TD(0)一样有fixed point

Least-Squares TD algorithm

A^tk=0t1xk(xkγxk+1)T+εIbt^k=0t1Rt+1xk A ^ t ≐ ∑ k = 0 t − 1 x k ( x k − γ x k + 1 ) T + ε I b t ^ ≐ ∑ k = 0 t − 1 R t + 1 x k

最终有

wtA^1tb^t w t ≐ A ^ t − 1 b ^ t

但是LSTD的计算复杂性很高,这里A在最后计算的时候是要求逆的,需要时间复杂度是 O(d3) O ( d 3 ) ,但是这里对A的计算是外积加和形式,所以可以写成增量更新的形式,计算复杂度变成了 O(d2) O ( d 2 )

A^1t=(A^t1+xt(xtγxt+1)T)1=A^1t1A^1t1xt(xtγxt+1)TA^1t11+(xtγxt+1)TA^1t1xt A ^ t − 1 = ( A ^ t − 1 + x t ( x t − γ x t + 1 ) T ) − 1 = A ^ t − 1 − 1 − A ^ t − 1 − 1 x t ( x t − γ x t + 1 ) T A ^ t − 1 − 1 1 + ( x t − γ x t + 1 ) T A ^ t − 1 − 1 x t

LSTD for estimating
all with only O(d2) O ( d 2 ) memory and per-step computation

9.9 Memory-based Function Approximation

非参数化方法。把训练样本保存在内存中。当有查询需求的时候,取出一组样本用来计算查询状态的估计值。也称作lazy learning。这里主要说local-learning,只使用查询状态的邻居来估计查询状态的值。其中有nearest neighbor method;weighted average methods;locally weighted regression。主要的好处是不受预先定义的函数形式的约束。主要的问题是加速最近邻居的查询,可以使用 k-d tree来加速。

9.10 Kernel-based Function Approximation

kernel function根据memory中状态与查询状态的距离,给予状态不同的权重。核方法还是Memory-based methods。
Kernel regression

v^(s,D)=sDk(s,s)g(s) v ^ ( s , D ) = ∑ s ′ ∈ D k ( s , s ′ ) g ( s ′ )

D is the set of stored examples
g(s’) denotes the target for state s’ in a stored example

线性参数回归方法也可以被看做是核方法,只不过使用的是线性核函数

k(s,s)=x(s)Tx(s) k ( s , s ′ ) = x ( s ) T x ( s ′ )

“kernel trick”:它允许在扩展特征的高维空间中有效地工作,而实际上仅使用一组存储的训练示例。

9.11 Looking Deeper at On-policy Learning: Interest and Emphasis

现在的算法对于遇到的所有状态都给予相同的重视程度。但事实上,我们会更加重视某些states。即对不同的feature有不同的关注度。

interest It I t :非负的随机变量,表示在时刻t我们对准确估计状态的感兴趣的程度
Emphasis Mt M t :用来强调和弱化t时刻的学习

The general n-step learning rule

wt+nwt+n1+αMt[Gt:t+nv^(St,wt+n1)]v^(St,wt+n1),0tTMt=It+γnMtn,0t<T w t + n ≐ w t + n − 1 + α M t [ G t : t + n − v ^ ( S − t , w t + n − 1 ) ] ∇ v ^ ( S t , w t + n − 1 ) , 0 ≤ t ≤ T M t = I t + γ n M t − n , 0 ≤ t < T

总结

Semi-gradient TD methods are not true gradient methods.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值