强化学习笔记之gradient ascent(二)

一般而言,Actor的策略就是gradient ascent
Actor和Environment、Reward的关系如下:
强化学习笔记之gradient ascent(二)
在一个回合episode中,这些state和action组成一条轨迹:
Trajectory τ={s1,a1,s2,a2,,sT,aT} \textbf {Trajectory} \space \tau = \lbrace s_1,a_1,s_2,a_2,\dots,s_T,a_T \rbrace
Agent一般是一个神经网络,θ是它的参数,输出是action和对应的概率,如在这个外星人入侵的小游戏中,输出是三个离散的量:左移、右移和开火,0.7、0.2、0.1分别对应他们被执行的概率。
强化学习笔记之gradient ascent(二)
那么整个轨迹被sample到的概率为:
pθ(τ)=p(s1)pθ(a1s1)p(s2s1,a1)pθ(a2s2)p(s3s2,a1)=p(s1)pθ(atst)p(st+1st,at) \begin{aligned} p_\theta(\tau)&=p(s_1)p_\theta(a_1|s_1)p(s_2|s_1,a_1)p_\theta(a_2|s_2)p(s_3|s_2,a_1)\dots \\ &=p(s_1)\prod p_\theta(a_t|s_t)p(s_{t+1}|s_t,a_t) \end{aligned}

在这个过程中,Actor会不断地根据环境反馈的reward来更新他的策略。那么在这条轨迹中可以获得reward为:
强化学习笔记之gradient ascent(二)

Gradient Ascent

ok,我们要做的就是使得Rˉθ\bar R_\theta最大化,采用的方法是梯度法,即求出 Rˉθ\triangledown \bar R_\theta,计算如下:
强化学习笔记之gradient ascent(二)
式中,N为采样数,T为步数。采样N笔τ\tau然后求平均。
通过引入log,将累乘变成累加。
然后使用计算出来的Rˉθ\triangledown \bar R_\theta去更新θ,η为学习速率,从而使得学习到参数会趋向于获取更大的reward。
θθ+ηRˉθ \theta\larr\theta+\eta \triangledown \bar R_\theta

这样,在实施的时候,如果一个action获得的reward越大,在更新参数θ后,Actor就会越倾向于sample这个action。
强化学习笔记之gradient ascent(二)

问题-改进

但是这样的更新策略还存在一些问题,actor执行action的依据是概率,如果某个action一直不被sample到,那么machine就永远不知道执行这个action可以获得的reward是多少。而所有action的概率加起来和为1,那么其他被sample到的action的概率会不断增加,没有被sample到的action的概率则会不断减小。这样machine就容易沉迷在容易获取的小reward中,而失去探索未知的动力。
强化学习笔记之gradient ascent(二)
为了解决这个问题,只需要让你的reward不要永远是正定的,因此引入一个基础偏移量,将R(τn)R(\tau^n)改为R(τn)bR(\tau^n)-b,这样reward就会有正有负,那些只能获得较小reward(比如小于b)的action的概率就不会永远增大,这就增加了其他action被sample到的概率。
通常取bE[R(τ)]b \approx E[R(\tau)]