强化学习中的无模型预测

在这里插入图片描述
本节目录

  在大多是强化学习(reinforcement learning RL)问题中,环境的model都是未知的,也就无法直接做动态规划。一种方法是去学MDP,在这个系列的理解强化学习中的策略迭代和值迭代这篇文章中有具体思路。但这种做法还是会存在很多问题,就是在sample过程中会比较麻烦,如果你随机sample的话就会有某些state你很难sample到,而按照某种策略sample的话,又很难得到真实的转移概率。一旦你的model出现了问题,值迭代和策略迭代都将会出现问题。

  于是就有了Model-free Reinforcement Learning,直接与环境交互,直接从数据中学到model

Model-free Reinforcement Learning

  Model-free Reinforcement Learning需要从数据中estimatevalue是多少(state or state-action pair),接下来拿到cumulative reward的期望,得到这些case之后,再去做model-freecontrol,去optimal当前的policy使得value function最大化。

  那model-freevalue function如何来做prediction呢?

  在model-freeRL中我们无法获取state transitionreward function,我们仅仅是有一些episodes。之前我们是拿这些episodesmodel,在model free的方法中拿这些episode直接学value function 或者是policy,不需要学MDP。这里面两个关键的key steps:1. estimate value function. 2. optimize policy.

Value Function Estimate

  In model-based RL (MDP), the value function is calculated by dynamic programming

v_{\pi}(s)=\mathbb{E_{\pi}}[R_{t+1}+\gamma v_{\pi}(\mathcal{S_{t+1}})|\mathcal{S_{t}=s}]

  在model free的方法中,我们不知道state transition,由此无法计算上述等式的期望。

Monte-Carlo Methods

  Monte-Carlo methods are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. For example, to calculate the circle's surface. As show in following figure:

Monte-Carlo Methods

  对上述方框中均匀撒上一些点,然后用如下等式计算即可:

\text{Circle Surface} = \text{Square Surface} \times \frac{\text{ points in circle}}{\text{points in total}}

Monte-Carlo Value Estimation

  我们有很多episodes,基于这些episode,我们去计算total discounted reward

G_{t}=R_{t+1}+\gamma R_{t+2}+\ldots=\sum_{k=0}^{\infty} \gamma^{k} R_{t+k+1}

  Value functionexpected return可表示为如下数学形式:

V^{\pi}(s) = \mathbb{E} [G_{t}|s_{t}=s,\pi] \\ \approx \frac{1}{N} \sum_{i=1}^{N} G_{i}^{(i)}

  上述方法可总结为两步:1. 使用policy \pistates开始采样 Nepisodes 。2. 计算平均累计奖励(the average of cumulative reward )。可以看出来,这种基于采样的方法,直接一步到位,计算value而不需要计算MDP中的什么状态转移啥的。

  上述思想更加细致、更具体的方法可用如下形式表示:

  • Sample episodes of policy \pi
  • Every time-step t that state s is visited in an episode
    • Increment counter N(s) \leftarrow N(s) +1
    • Increment total return S(s) \leftarrow S(s) +G_{t}
    • Value is estimated by mean return V(s)=S(s)/N(s)
    • By law of large numbers V(s) \leftarrow V^{\pi} as N(s) \rightarrow \infty
Incremental Monte-Carlo Updates
  • Update V(s) incrementally after each episode
  • For each state S_{t} with cumulative return G_{t}

\begin{array}{l} {N\left(S_{t}\right) \leftarrow N\left(S_{t}\right)+1} \\ {V\left(S_{t}\right) \leftarrow V\left(S_{t}\right)+\frac{1}{N\left(S_{t}\right)}\left(G_{t}-V\left(S_{t}\right)\right)} \end{array}

  • For non-stationary problems (i.e. the environment could be varying over time), it can be useful to track a running mean, i.e. forget old episodes

  如果环境的state transitionreward function一直在变,我们把这个环境叫做non-stationary,环境本身肯定叫做stochastic环境。但是如果分布不变,叫做statically environment,但是环境本身的分布会发生变化的话,就需要去忘掉一些老的episode,如果用平均的方法去做的话,老的episode和新的episode一样,它就忘不掉老的episode

V(S_{t}) \leftarrow V(S_{t}) + \alpha (G_{t} - V(S_{t}))

  Monte-Carlo Value Estimation的一些特点:

  1. MC methods learn directly from episodes of experience
  2. MC is model-free: no knowledge of MDP transitions / rewards
  3. MC learns from complete episodes: no bootstrapping (discussed later)
  4. MC uses the simplest possible idea: value = mean return
  5. Caveat: can only apply MC to episodic MDPs i.e., all episodes must terminate

Temporal-Difference Learning

  TD的方法中引入对未来值函数的估计:

G_{t}=R_{t+1}+\gamma R_{t+2}+\ldots=R_{t+1}+\gamma V(S_{t+1})

V(S_{t}) \leftarrow V(S_{t}) + \alpha(R_{t+1}+\gamma V(S_{t+1}) - V(S_{t}))

  TD的算法主要有以下四个特点:

  1. TD methods learn directly from episodes of experience
  2. TD is model-free: no knowledge of MDP transitions / rewards
  3. TD learns from incomplete episodes, by bootstrapping
  4. TD updates a guess towards a guess
Monte Carlo vs. Temporal Difference

  Monte Carlo方法和Temporal Difference方法对比如下:

  • The same goal: learn V_{\pi} from episodes of experience under policy \pi

  • Incremental every-visit Monte-Carlo

    • Update value V(S_{t}) toward actual return G_{t}

V(S_{t}) \leftarrow V(S_{t}) + \alpha(G_{t}-V(S_{t}))

  • Simplest temporal-difference learning algorithm: TD
    • Update value V(S_{t}) toward estimated return R_{t+1} + \gamma V(S_{t+1})
    • TD TargetR_{t+1} + \gamma V(S_{t+1})
    • TD error\delta = R_{t+1} + \gamma V(S_{t+1}) - V(S_{t})
Advantages and Disadvantages of MC vs. TD
  • TD can learn before knowing the final outcome

    • TD can learn online after every step
    • MC must wait until end of episode before return is known
  • TD can learn without the final outcome

    • TD can learn from incomplete sequences
    • MC can only learn from complete sequences
    • TD works in continuing (non-terminating) environments
    • MC only works for episodic (terminating) environments
Bias/Variance Trade-Off
  • Return G_{t} is unbiased estimate of V^{\pi}(S_{t})

  基于当前的策略去采样,然后计算平均值,这样得到的估计是无偏估计。

  • TD target R_{t+1} + \gamma V(S_{t+1}) is biased estimate of V^{\pi}

  TD target中由于存在对未来的估计V(S_{t+1}),这个估计如果是非常准确的,那TD target也是unbiased estimate,但是由于V(S_{t+1})很难估计准确,所以是 biased estimate

  • TD target is of much lower variance than the return

  TD target的方法一般比Return G_{t}要小。Return G_{t} depends on many random actions, transitions and rewards;TD target depends on one random action, transition and reward

Advantages and Disadvantages of MC vs. TD (2)
  • MC has high variance, zero bias

  MC方法具有好的 convergence properties (even with function approximation) 并且 Not very sensitive to initial value 但是需要 Very simple to understand and use。需要多采样去降低variance

  • TD has low variance, some bias

  TD的方法 Usually more efficient than MC ,TD converges to V^{\pi}(S_{t}),but not always with function approximation。并且 More sensitive to initial value than MC。

n-step model-free prediction

  For time constraint, we may jump n-step prediction section and directly head to model-free control

  • Define the n-step return

G_{t}^{n} = R_{t+1} + \gamma R_{t+2} + \cdots +\gamma^{n-1}R_{t+n} + \gamma^{n} V(S_{t+n})

在这里插入图片描述
  • n-step temporal-difference learning

V(S_{t}) \leftarrow V(S_{t}) + \alpha(G_{t}^{(n)} - V(S_{t}))

  有了值函数之后,我们就需要去做策略改进了。

我的微信公众号名称:深度学习与先进智能决策
微信公众号ID:MultiAgent1024
公众号介绍:主要研究分享深度学习、机器博弈、强化学习等相关内容!期待您的关注,欢迎一起学习交流进步!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,302评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,563评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,433评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,628评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,467评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,354评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,777评论 3 387
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,419评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,725评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,768评论 2 314
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,543评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,387评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,794评论 3 300
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,032评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,305评论 1 252
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,741评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,946评论 2 336

推荐阅读更多精彩内容