基本概念介绍
前面已经介绍过,强化学习难入坑的的原因之一就在于概念繁多。下面将进行基本概念的介绍,本章节最好能够理解,不理解也没有关系,但是建议作为参考章节常看常新。后续章节不理解某个概念时,便回来看看,相信一定能够做到常看常新、从而加深你对于概念的理解。下面将进行四个部分的介绍,分别为强化学习的基本过程、强化学习的基本组成内容、强化学习的基本概念以及强化学习的目标。
强化学习的基本过程
前面已经介绍过强化学习的核心过程,在于智能体与环境进行交互,通过给出的奖励反馈作为信号学习的过程。简单地用图片表示如下: 正是在这个与环境的交互过程中,智能体不断得到反馈,目标就是尽可能地让环境反馈的奖励足够大。
强化学习过程的基本组成内容
为了便于理解,我们引入任天堂经典游戏 —— 新超级马里奥兄弟 U,作为辅助理解的帮手。作为一个 2D 横向的闯关游戏,它的状态空间和动作空间无疑是简单的。
1. 智能体 (Agent): 它与环境交互,可以观察到环境并且做出决策,然后反馈给环境。在马里奥游戏中,能操控的这个马里奥本体就是智能体。
2. 环境 (Environment): 智能体存在并且与其交互的世界。新超级马里奥兄弟 U 本身,就是一个环境。
3. 状态 (State):对环境当前所处环境的全部描述,记为
4. 动作 (Action): 智能体可以采取的行为,记为
5. 策略 (Policy): 智能体采取动作的规则,分为确定性策略与随机性策略。确定性策略代表在相同的状态下,智能体所输出的动作是唯一的。而随机性策略哪怕是在相同的状态下,输出的动作也有可能不一样。这么说有点过于抽象了,那么请思考这个问题:在下面这张图的环境中,如果执行确定性策略会发生什么?(提示:着重关注两个灰色的格子)
因此,在强化学习中我们一般使用随机性策略。随机性策略通过引入一定的随机性,使环境能够被更好地探索。同时,如果策略固定 —— 你的对手很容易能预测你的下一步动作并予以反击,这在博弈中是致命的。 随机性策略
这代表着在给定状态 s 下,作出动作
其中,假设
6. 奖励 (Reward): 这是一种反馈信号,用于表现智能体与环境交互后 "表现" 如何。在不同的环境中,我们需要设置不同的奖励。比如,在围棋游戏中,最后赢得游戏才会获得一个奖励。比如在量化交易中,可以直接拿收益亏损作为奖励。拿我们的马里奥游戏举例,吃到金币可以获得较小的奖励,最终通关游戏会获得一个极大的奖励,这样使得智能体以通关为目标、以吃金币为锦上添花。当然了,如果碰到怪物或者是死亡,需要设置一个极大的负奖励,因为这将直接导致游戏结束。
我们可以得出一个结论:每一个奖励
7. 状态转移 (State transition): 环境可不会在原地等你。在你操控马里奥执行一个动作后,比如 "left",那屏幕上显示的画面肯定会改变,这就发生了一个状态转移。状态转移函数记作
状态转移可以是固定的,也可以是随机的,我们通常讨论的是随机的情况。从公式的形式上也可以看出来,这还是一个概率密度函数。这代表着在观测到当前的状态
知道了上述几个概念,构建强化学习的基本过程就尽在掌握之中了。我们可以构建一个 (state,action,reward) 轨迹,即:
i. 观察到状态
ii. 执行动作
iii. 观察新状态
iv. 执行动作
v. 不断迭代......
该序列轨迹写作:
强化学习的基本概念
在阅读了前两个小节后,你可能对于强化学习的基本过程以及基本组成内容有了初步的了解。下面将进行强化学习基本概念的介绍,本章节与 "基本组成内容" 小节是继承关系,请一起阅读。(注:标题真难取,其实上一章就是强化学习的基本元素,这一章为基础元素推导出的基础概念)
1. 回报 (Retrun),需要与奖励区分开来。回报又称为 "未来的累计奖励"(Cumulative future reward),这可以在其定义中窥见端倪:
但是这个定义有一个很明显的问题,未来时刻的奖励和现在的一样重要吗?如果我承诺未来给你 100 块钱,这份承诺在你心里的分量和现在就给你 100 块钱能够等价吗?很明显不能。因此我们引入折扣因子
这是我们在强化学习中经常使用的概念。其中,折扣率是一个超参数,会对强化学习的结果造成一定的影响。
注意格式:如果游戏结束,每一个时刻的奖励都被观测到了 —— 即站在任意时刻,一直到游戏结束的奖励都是可被观测的状态,那么奖励使用小写字母
Fix: 真的理所当然吗?
让我们回顾一下,之前讲述 "奖励" 的定义时,我们得出过一个结论:每一个奖励
i. 状态
ii. 动作
因此,
2. 动作价值函数 (Action-Value Function)
动作价值函数
3. 最优动作价值函数 (Optimal action-value function)
动作价值函数对于回报
我们跨出了历史性的一步。
如果有了
4. 状态价值函数 (State-value function)
在动作价值函数中,
状态价值函数消去了动作
强化学习的基本目标
看完上述内容的你,心里想必有十万个为什么:我是谁?我在哪?我要做什么?
明明最初说好的要训练智能体打游戏,我才耐着性子看下去的!看了这么久了,我光学到了一大堆似是而非的概念,推导并尝试理解了一大堆可能之前都没有接触到过的数学公式,抑或是翻开了尘封已久的《概率论与数理统计》才勉强跟上公式推导及其步骤,却连强化学习怎么训练智能体都不知道!这是诈骗!日内瓦,退钱!
这也是我在学习过程中的心路历程。理解 / 半懂不懂的带过了一堆概念,却连强化学习最基本的任务都不明白。我要干什么,才能训练智能体打游戏?
还记得我们前面提到过的基于价值的学习和基于策略的学习吗?没错,强化学习的最终目标就是通过两者完成的,下面将给出具体阐述。
1. 基于价值的学习。说人话,就是学习
2. 基于策略的学习。说人话,就是学习
通常情况下,学到
总结与展望
在本章节里,我们了解了强化学习的基本过程、组成要素、基本概念以及最终目标,无论你是否真正搞懂每一个知识点,想必已经对强化学习有一个初步的了解了。接下来,我拟从 Q-learning、SARSA 算法等传统强化学习算法开始,推到结合了深度学习的 Deep Q-learning (DQN) , 以及其改进版本 Double DQN (DDQN)、Dueling DQN 等算法,以完成基于价值学习侧的算法介绍。然后,我将从 Reinforce 这一最基础的强化学习算法引入基于策略学习侧的基本理念,然后介绍结合基于策略学习和基于价值学习的演员 - 批评家网络 (Actor-Critic) 架构,并且引出 PPO、DDPG 等算法。
为了不让你的大脑继续过载,下一章节将讲述强化学习基本环境的搭建。