开篇引言 / Opening
English
The term dynamic programming (DP) refers to a collection of algorithms that can be used to compute optimal policies given a perfect model of the environment as a Markov decision process (MDP). Classical DP algorithms are of limited utility in reinforcement learning both because of their assumption of a perfect model and because of their great computational expense, but they are still important theoretically. DP provides an essential foundation for understanding the methods in the rest of this book.
中文
动态规划(DP)是一组算法的统称,在给定环境作为MDP的完美模型时,可用于计算最优策略。经典DP算法在强化学习中的实用性有限——既因为假设完美模型,也因为计算代价巨大——但它们在理论上仍然重要。DP为理解本书其余方法提供了必要的基础。
English
The key idea of DP, and of reinforcement learning generally, is the use of value functions to organize and structure the search for good policies. DP algorithms are obtained by turning Bellman equations into assignments, that is, into update rules for improving approximations of the desired value functions.
中文
DP的核心思想(也是强化学习的一般思想)是使用价值函数来组织和构建对好策略的搜索。DP算法通过将Bellman方程转化为赋值操作——即改善所需价值函数近似的更新规则——来获得。
4.1 策略评估(预测)/ Policy Evaluation (Prediction)
English
Computing the state-value function vπ for an arbitrary policy π is called policy evaluation or the prediction problem. If the environment's dynamics are completely known, then the Bellman equation for vπ is a system of |S| simultaneous linear equations in |S| unknowns. We use an iterative method: a sequence of approximations v0, v1, v2, ... where each successive approximation is obtained by using the Bellman equation as an update rule:
中文
计算任意策略π的状态价值函数vπ称为策略评估或预测问题。如果环境动态完全已知,vπ的Bellman方程是|S|个未知数的|S|元联立线性方程组。我们使用迭代方法:近似序列v0, v1, v2, ...,每个后续近似通过使用Bellman方程作为更新规则来获得:
vk+1(s) = Σa π(a|s) Σs',r p(s',r|s,a) [r + γ vk(s')]
English
The sequence {vk} converges to vπ as k→∞. This algorithm is called iterative policy evaluation. Each iteration does an expected update — the new value of each state is computed from the expected values of successor states. In practice, the in-place version (updating values in a single array) usually converges faster.
中文
序列{vk}当k→∞时收敛到vπ。该算法称为迭代策略评估。每次迭代执行一次期望更新——每个状态的新值从后继状态的期望值计算得出。实践中,就地版本(在单个数组中更新值)通常收敛更快。
Iterative Policy Evaluation (in-place)
─────────────────────────────────────
Input: π (policy to evaluate), θ (threshold)
Initialize V(s) arbitrarily, V(terminal) = 0
Loop:
Δ ← 0
For each s ∈ S:
v ← V(s)
V(s) ← Σ_a π(a|s) Σ_{s',r} p(s',r|s,a)[r + γV(s')]
Δ ← max(Δ, |v - V(s)|)
until Δ < θ
4×4网格世界示例:14个非终止状态,每步奖励-1,等概率随机策略。迭代策略评估从k=0(全零)逐步收敛,k=∞时得到每个状态到终止的期望步数的负值。
4.2 策略改进 / Policy Improvement
English
Our reason for computing the value function is to help find better policies. Given a deterministic policy π, we ask: should we change to deterministically choose action a ≠ π(s) in state s? The key criterion is whether qπ(s,a) > vπ(s). If it is better to select a once in s and thereafter follow π, then one would expect the new policy (selecting a every time s is encountered) to be better overall.
中文
计算价值函数的目的是帮助找到更好的策略。给定确定性策略π,我们问:在状态s是否应该改为确定性地选择动作a≠π(s)?关键标准是qπ(s,a) > vπ(s)是否在状态s成立。如果在s选一次a然后遵循π比始终遵循π更好,那么每次都选a的新策略整体上应该更好。
策略改进定理 / Policy Improvement Theorem
English
Let π and π' be any pair of deterministic policies such that qπ(s, π'(s)) ≥ vπ(s) for all s∈S. Then π' must be as good as, or better than, π: vπ'(s) ≥ vπ(s) for all s. Moreover, if there is strict inequality at any state, then there must be strict inequality at that state in the value functions.
中文
设π和π'为任意两个确定性策略,使得对所有s∈S都有qπ(s, π'(s)) ≥ vπ(s)。则π'必定不亚于π:vπ'(s) ≥ vπ(s)对所有s成立。而且,如果在某个状态存在严格不等式,则在该状态的价值函数中也必定存在严格不等式。
贪婪策略 / The Greedy Policy
English
We extend to consider changes at all states to all possible actions, selecting at each state the action that appears best according to qπ. This new greedy policy π' is:
中文
我们扩展到在所有状态考虑所有可能动作的变化,在每个状态选择根据qπ看起来最好的动作。这个新的贪婪策略π'为:
π'(s) = argmaxa qπ(s,a) = argmaxa Σs',r p(s',r|s,a) [r + γ vπ(s')]
English
By construction, the greedy policy meets the conditions of the policy improvement theorem, so it is as good as or better than the original policy. If the new greedy policy is as good as but not better than π, then vπ' = vπ, and it follows that vπ' must satisfy the Bellman optimality equation — meaning both π and π' are optimal policies.
中文
通过构造,贪婪策略满足策略改进定理的条件,因此不亚于原策略。如果新的贪婪策略与原策略一样好但不更好,则vπ'=vπ,由此可得vπ'必定满足Bellman最优方程——意味着π和π'都是最优策略。
4.3 策略迭代 / Policy Iteration
English
Once a policy π has been improved using vπ to yield π', we can compute vπ' and improve again. This produces a sequence of monotonically improving policies and value functions:
中文
一旦策略π通过vπ改进为π',我们可以计算vπ'并再次改进。这产生一个单调递增改进的策略和价值函数序列:
π0 →E vπ₀ →I π1 →E vπ₁ →I π2 →E ... →I π* →E v*
English
Because a finite MDP has only a finite number of policies, this process must converge to an optimal policy in a finite number of iterations. This is called policy iteration. Each policy evaluation is started with the value function for the previous policy, which typically results in fast convergence.
中文
由于有限MDP只有有限多个策略,此过程必定在有限次迭代内收敛到最优策略。这称为策略迭代。每次策略评估从上一个策略的价值函数开始,通常能实现快速收敛。
Jack租车示例:Jack管理两个租车点。每天客户到达租车,$10/辆;可在夜间以$2/辆的成本在两点间转移车辆。策略迭代从"不转移"策略开始,仅几次迭代就收敛到最优策略。
4.4 价值迭代 / Value Iteration
English
One drawback to policy iteration is that each iteration involves policy evaluation, which may itself require multiple sweeps through the state set. The policy evaluation step can be truncated — an important special case is stopping after just one sweep. This algorithm is called value iteration:
中文
策略迭代的一个缺点是每次迭代都包含策略评估,而评估本身可能需要对状态集进行多次扫描。策略评估步骤可以被截断——一个重要的特殊情况是在一次扫描后就停止。这种算法称为价值迭代:
vk+1(s) = maxa Σs',r p(s',r|s,a) [r + γ vk(s')]
English
Value iteration is obtained simply by turning the Bellman optimality equation into an update rule. It effectively combines one sweep of policy evaluation and one sweep of policy improvement in each sweep.
中文
价值迭代仅仅是将Bellman最优方程转化为更新规则。它在每次扫描中有效地结合了策略评估和策略改进各一次扫描。
Value Iteration, for estimating π ≈ π*
─────────────────────────────────────
Algorithm parameter: θ (threshold)
Initialize V(s) arbitrarily, V(terminal) = 0
Loop:
Δ ← 0
For each s ∈ S:
v ← V(s)
V(s) ← max_a Σ_{s',r} p(s',r|s,a)[r + γV(s')]
Δ ← max(Δ, |v - V(s)|)
until Δ < θ
Output deterministic policy:
π(s) = argmax_a Σ_{s',r} p(s',r|s,a)[r + γV(s')]
赌徒问题:赌徒对抛硬币结果下注,正面赢得赌注,反面失去赌注。目标是达到$100。状态是资本s∈{1,...,99},动作是赌注金额。价值迭代揭示了当硬币偏向时(ph=0.4)最优策略呈现的分形结构。
4.5-4.6 异步DP与广义策略迭代 / Asynchronous DP & GPI
English
Asynchronous DP algorithms do not require systematic sweeps of the entire state set. They can update the values of states in any order, using whatever values of other states happen to be available. This gives great flexibility in selecting which states to update, enabling us to improve the value of interesting states first, perhaps those most relevant to the agent's experience.
中文
异步DP算法不需要对整个状态集进行系统性扫描。它们可以以任何顺序更新状态值,使用碰巧可用的其他状态值。这为选择更新哪些状态提供了极大的灵活性,使我们能够优先改善有趣状态(如与智能体经验最相关的状态)的价值。
English
Generalized Policy Iteration (GPI) refers to the general idea of letting policy evaluation and policy improvement interact regardless of the details and granularity of the two processes. Nearly all reinforcement learning methods can be viewed as instances of GPI — each has identifiable policies and value functions, with the policy always being improved relative to the value function and the value function always being driven toward the value function for the policy.
中文
广义策略迭代(GPI)是指让策略评估和策略改进相互交互的一般思想,不论两个过程的具体细节和粒度如何。几乎所有强化学习方法都可以视为GPI的实例——每种方法都有可识别的策略和价值函数,策略总是相对于价值函数改进,价值函数总是被驱动趋向策略的价值函数。
GPI的竞争与协作:评估和改进过程既相互竞争(改进使评估"过时",评估使改进"不足"),又相互协作(各自推动对方趋向正确值)。这种竞争-协作动态是理解强化学习算法的核心。
4.7 DP的效率 / Efficiency of DP
English
DP may be of little practical utility for today's large problems due to the curse of dimensionality: computational requirements grow exponentially with the number of state variables. However, DP has been shown to be polynomially efficient in the size of the state set |S| and the action set |A|. In practice, DP algorithms can be used to solve MDPs with millions of states.
中文
由于维度灾难(计算需求随状态变量数指数增长),DP对当今大型问题的实际效用可能有限。然而,DP已被证明在状态集大小|S|和动作集大小|A|方面是多项式高效的。在实践中,DP算法可用于解决有数百万个状态的MDP。