An introduction to Reinforcement Learning(一)

https://www.freecodecamp.org/news/an-introduction-to-reinforcement-learning-4339519de419/

本文,我们要学的是:

  • 什么是强化学习,为什么reward是强化学习的中心思想
  • 强化学习的三种方法
  • 深度强化学习中”深度“的含义是什么

The Reinforcement Learning Process

在这里插入图片描述
依然以马里奥作为例子。RL的流程如下:

  • Agent从env中接收到state S 0 S0 S0(在这个例子中我们接受到的就是超级马里奥(env)里的游戏第一帧(state))
  • 基于state S 0 S0 S0,agent采取 action A 0 A0 A0(向右)
  • env进入到新的state S 1 S1 S1(新的一帧)
  • env给agent一些reward R 1 R1 R1(没死:+1)

这个RL循环输出一系列 state,action和reward。
agent的目标是最大化期望累积reward。

The central idea of the Reward Hypothesis

强化学习是基于reward假设的思想的。所有的目标都被描述为最大化期望累积reward。
G t = R t + 1 + R t + 2 + . . . G_t=R_{t+1}+R_{t+2}+... Gt=Rt+1+Rt+2+...
也就是
G t = ∑ k = 0 T R t + k + 1 G_t=\sum^{T}_{k=0}R_{t+k+1} Gt=k=0TRt+k+1
但是现实中,我们不能单纯的把rewards加起来。游戏早期的reward
是更可能发生的,因为它们比长期的未来reward要更容易预测。这里就引入 γ \gamma γ,来对reward进行抑制。该值越大,说明我们越重视长期reward,相反,我们更看重短期reward。
那么我们的带衰减的累积期望reward就是:
G t = ∑ k = 0 T γ k R t + k + 1 G_t =\sum^{T}_{k=0}\gamma^k R_{t+k+1} Gt=k=0TγkRt+k+1

Episodic or Continuing tasks

一个任务就是一个RL的一个实例。我们有两种类型的任务:情节式的和连续式的。

Episodic tasks

在这个例子里,我们有一个起始点和一个终点(一个终止state)。这就创建了一个片段:states,actions,rewards和new states的列表。
就拿超级马里奥来说,一个片段开始于游戏的开始,结束于马里奥死掉或者到达终点。

Continuous tasks

这类任务是永久持续的(没有终止state)。在该case下,agent就要学会如何选择最优动作并且同时与env进行交互。
例如,一个agent在进行自动股票交易。对于这个任务来说,没有起始点和终点。agent不断运行知道我们停止它为止。

Monte Carlo vs TD Learning methods

我们有两种学习方式:

  • 在片段的结束收集reward,然后计算最大期望未来reward:蒙特卡洛方法
  • 每一步估计reward:Temporal Difference Learning(TD,时间差学习)

Monte Carlo

每次到达终止状态,agent得到总共累积的reward,看这次到底做的如何。在该方法下,只有游戏结束时才得到reward。
然后我们带着以前的知识开始新一轮的游戏。agent每次迭代之后会做出更好的决策。
V ( S t ) ← V ( S t ) + α [ G t − V ( S t ) ] V(S_{t})\leftarrow V(S_{t})+\alpha [G_t-V(S_{t})] V(St)V(St)+α[GtV(St)]
V ( S t ) V(S_t) V(St)代表从当前state开始的最大期望未来reward。方程左边是该次的 V V V,右边是上次的 V V V
在这里插入图片描述
举个例子,我们考虑一个迷宫环境:

  • 我们总是从同一个起始点开始。
  • 我们终止这次学习当猫吃了老鼠或者老鼠移动了超过20步。
  • 在该次学习的结束,我们有一系列的State,Actions,Rewards和New States。
  • agent会对rewards进行求和。
  • 然后更新 V ( S t ) V(S_t) V(St)
  • 然后带着新知识开始新的游戏。
    随着跑的次数越来越多,agent玩的越来越好。

Temporal Difference Learning : learning at each time step

TD Learning,相反就是不等到游戏结束就更新最大预期未来报酬估计:对于经历中发生的不终止状态都会更新它的价值估计。
这个方法叫做 T D ( 0 ) TD(0) TD(0)或者 one step TD(每一步都更新价值函数)
V ( S t ) ← V ( S t ) ⎵ Previous estimate + α [ R t + 1 ⎵ Reward t+1 + γ V ( S t + 1 ) ⎵ Discounted value on the next step ⎵ TD Target − V ( S t ) ] V(S_{t})\leftarrow \underbrace{V(S_{t})}_{\text{Previous estimate}}+\alpha [\underbrace{\underbrace{R_{t+1}}_{\text{Reward t+1}}+\underbrace{\gamma V(S_{t+1})}_{\text{Discounted value on the next step}}}_{\text{TD Target}}-V(S_t)] V(St)Previous estimate V(St)+α[TD Target Reward t+1 Rt+1+Discounted value on the next step γV(St+1)V(St)]

Exploration/Exploitation trade off

在我们了解不同的解决RL的问题的策略之前,我们必须了解一个重要的概念:探索/利用权衡。

  • 探索是尽可能的得到环境的更多信息。
  • 利用是就已知的知识来最大化reward。

记住,我们的目标是最大化期望累计报酬。但是,我们会因此落入共同陷阱中。
在这里插入图片描述
依然以这个迷宫为例,老鼠周围的小cheese个数是无限的,但是每次只能+1,角落里的cheese+1000,如果仅仅注重reward,那么老鼠只能利用最近的reward(exploitation)。
但如果agent做一点点的探索,它就能发现巨大的reward。

Three approaches to Reinforcement Learning

Value Based

在该方法中,目标是最大化价值函数 V ( s ) V(s) V(s)
价值函数能够告诉我们每个state的最大期望未来报酬。
每个state的价值是agent从该state开始在未来所能累积的reward。
v π ( s ) = E π [ R t + 1 + γ R t + 2 + . . . ∣ S t = s ] v_{\pi}(s)=\mathbb E_{\pi}[R_{t+1}+\gamma R_{t+2}+... | S_t=s] vπ(s)=Eπ[Rt+1+γRt+2+...St=s]
agent会根据价值函数在每一步选择state最大的进行移动。
在这里插入图片描述

Policy Based

该方法,我们想要直接优化一个方针函数 π ( s ) \pi(s) π(s),不使用价值函数。
策略就是定义在给定状态下的agent的行为。
a = π ( s ) a=\pi(s) a=π(s)
有两种策略:

  • 确定的:对于给定的state,我们总是返回同一动作。
  • 随机的:输出一个关于动作的概率分布。

Stochastic policy:  π ( a ∣ s ) = P [ A t = a ∣ S t = s ] \text{Stochastic policy: } \pi(a|s)=\mathbb P[A_t=a|S_t=s] Stochastic policy: π(as)=P[At=aSt=s]
在这里插入图片描述
如上图,策略告诉我们每一步的最优动作。

Model Based

该方法中,我们对环境进行建模。这就意味着我们创建了一个环境行为的模型。
问题是对于每个环境,我们就需要不同的模型表达。所以在本系列中,我们步探讨这种RL。

Introducing Deep Reinforcement Learning

深度强化学习就是引入深度神经网络来解决强化学习问题——所以命名“深度”。
例如,下一章我们会着眼于Q-Learning和Deep Q-Learning。
你会发现在第一种方法中,我们使用传统的算法来创建一个Q table 来帮助我们寻找每个state所采取的动作。
在第二种方法中,我们使用神经网络(来逼近基于state的reward:q value)。
在这里插入图片描述

The authoritative textbook for reinforcement learning by Richard Sutton and Andrew Barto. Contents Preface Series Forward Summary of Notation I. The Problem 1. Introduction 1.1 Reinforcement Learning 1.2 Examples 1.3 Elements of Reinforcement Learning 1.4 An Extended Example: Tic-Tac-Toe 1.5 Summary 1.6 History of Reinforcement Learning 1.7 Bibliographical Remarks 2. Evaluative Feedback 2.1 An -Armed Bandit Problem 2.2 Action-Value Methods 2.3 Softmax Action Selection 2.4 Evaluation Versus Instruction 2.5 Incremental Implementation 2.6 Tracking a Nonstationary Problem 2.7 Optimistic Initial Values 2.8 Reinforcement Comparison 2.9 Pursuit Methods 2.10 Associative Search 2.11 Conclusions 2.12 Bibliographical and Historical Remarks 3. The Reinforcement Learning Problem 3.1 The Agent-Environment Interface 3.2 Goals and Rewards 3.3 Returns 3.4 Unified Notation for Episodic and Continuing Tasks 3.5 The Markov Property 3.6 Markov Decision Processes 3.7 Value Functions 3.8 Optimal Value Functions 3.9 Optimality and Approximation 3.10 Summary 3.11 Bibliographical and Historical Remarks II. Elementary Solution Methods 4. Dynamic Programming 4.1 Policy Evaluation 4.2 Policy Improvement 4.3 Policy Iteration 4.4 Value Iteration 4.5 Asynchronous Dynamic Programming 4.6 Generalized Policy Iteration 4.7 Efficiency of Dynamic Programming 4.8 Summary 4.9 Bibliographical and Historical Remarks 5. Monte Carlo Methods 5.1 Monte Carlo Policy Evaluation 5.2 Monte Carlo Estimation of Action Values 5.3 Monte Carlo Control 5.4 On-Policy Monte Carlo Control 5.5 Evaluating One Policy While Following Another 5.6 Off-Policy Monte Carlo Control 5.7 Incremental Implementation 5.8 Summary 5.9 Bibliographical and Historical Remarks 6. Temporal-Difference Learning 6.1 TD Prediction 6.2 Advantages of TD Prediction Methods 6.3 Optimality of TD(0) 6.4 Sarsa: On-Policy TD Control 6.5 Q-Learning: Off-Policy TD Control 6.6 Actor-Critic Methods 6.7 R-Learning for Undiscounted Continuing Tasks 6.8 Games, Afterstates, and Other Special Cases 6.9 Summary 6.10 Bibliographical and Historical Remarks III. A Unified View 7. Eligibility Traces 7.1 -Step TD Prediction 7.2 The Forward View of TD( ) 7.3 The Backward View of TD( ) 7.4 Equivalence of Forward and Backward Views 7.5 Sarsa( ) 7.6 Q( ) 7.7 Eligibility Traces for Actor-Critic Methods 7.8 Replacing Traces 7.9 Implementation Issues 7.10 Variable 7.11 Conclusions 7.12 Bibliographical and Historical Remarks 8. Generalization and Function Approximation 8.1 Value Prediction with Function Approximation 8.2 Gradient-Descent Methods 8.3 Linear Methods 8.3.1 Coarse Coding 8.3.2 Tile Coding 8.3.3 Radial Basis Functions 8.3.4 Kanerva Coding 8.4 Control with Function Approximation 8.5 Off-Policy Bootstrapping 8.6 Should We Bootstrap? 8.7 Summary 8.8 Bibliographical and Historical Remarks 9. Planning and Learning 9.1 Models and Planning 9.2 Integrating Planning, Acting, and Learning 9.3 When the Model Is Wrong 9.4 Prioritized Sweeping 9.5 Full vs. Sample Backups 9.6 Trajectory Sampling 9.7 Heuristic Search 9.8 Summary 9.9 Bibliographical and Historical Remarks 10. Dimensions of Reinforcement Learning 10.1 The Unified View 10.2 Other Frontier Dimensions 11. Case Studies 11.1 TD-Gammon 11.2 Samuel's Checkers Player 11.3 The Acrobot 11.4 Elevator Dispatching 11.5 Dynamic Channel Allocation 11.6 Job-Shop Scheduling Bibliography Index
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值