当前位置: 首页 > news >正文

RL【3】:Bellman Optimality Equation

系列文章目录


文章目录

  • 系列文章目录
  • 前言
  • Definition of optimal policy
  • Bellman optimality equation
    • Introduction
    • Maximization on the right-hand side
    • Contraction mapping theorem
    • Solution
    • Optimality
  • Analyzing optimal policies
  • 总结


前言

本系列文章主要用于记录 B站 赵世钰老师的【强化学习的数学原理】的学习笔记,关于赵老师课程的具体内容,可以移步:
B站视频:【【强化学习的数学原理】课程:从零开始到透彻理解(完结)】
GitHub 课程资料:Book-Mathematical-Foundation-of-Reinforcement-Learning


Definition of optimal policy

The state value could be used to evaluate if a policy is good or not: if

vπ1(s)≥vπ2(s),∀s∈Sv_{\pi_1}(s) \geq v_{\pi_2}(s), \quad \forall s \in \mathcal{S}vπ1(s)vπ2(s),sS

then π1\pi_1π1 is “better” than π2\pi_2π2.

A policy π∗\pi^*π is optimal if

vπ∗(s)≥vπ(s),∀s∈S,∀π.v_{\pi^*}(s) \geq v_\pi(s), \quad \forall s \in \mathcal{S}, \; \forall \pi.vπ(s)vπ(s),sS,π.


Bellman optimality equation

Introduction

Bellman optimality equation (elementwise form):

v(s)=max⁡π∑aπ(a∣s)(∑rp(r∣s,a)r+γ∑s′p(s′∣s,a)v(s′)),∀s∈Sv(s) = \max_{\pi} \sum_a \pi(a \mid s) \left( \sum_r p(r \mid s,a) r + \gamma \sum_{s'} p(s' \mid s,a) v(s') \right), \quad \forall s \in \mathcal{S}v(s)=maxπaπ(as)(rp(rs,a)r+γsp(ss,a)v(s)),sS

=max⁡π∑aπ(a∣s)q(s,a),s∈S= \max_{\pi} \sum_a \pi(a \mid s) q(s,a), \quad s \in \mathcal{S}=maxπaπ(as)q(s,a),sS

Remarks:

  • p(r∣s,a),p(s′∣s,a)p(r \mid s,a), p(s' \mid s,a)p(rs,a),p(ss,a) are known.
  • v(s),v(s′)v(s), v(s')v(s),v(s) are unknown and to be calculated.
  • π(s)\pi(s)π(s) is known!

结合 Bellman 方程依赖于已知策略,解释为什么在 Bellman 最优性方程 里要取 max⁡π\max_\pimaxπ,以及它和最优策略 π∗\pi^*π 的关系

  1. 回顾:Bellman 方程(依赖已知策略)

    对于一个固定的策略 π\piπ,状态价值函数定义为:

    vπ(s)=∑aπ(a∣s)[∑rp(r∣s,a)r+γ∑s’p(s’∣s,a)vπ(s’)]v_\pi(s) = \sum_a \pi(a \mid s) \Bigg[ \sum_r p(r \mid s,a) r + \gamma \sum_{s’} p(s’ \mid s,a) v_\pi(s’) \Bigg]vπ(s)=aπ(as)[rp(rs,a)r+γsp(ss,a)vπ(s)]

    • 这里 π(a∣s)\pi(a|s)π(as)已知的动作分布,所以 Bellman 方程在这种情况下是 策略评估 (policy evaluation) 工具。
      • 策略 = 对每个状态 sss,给所有可能动作 aaa 分配概率,即一个策略对应了一组“所有状态的动作概率分布”
      • 不同策略对应的就是 不同的动作概率分布集合
        • 策略 π1\pi_1π1

          在状态 sss,可能给动作 a1a_1a1 的概率高一些,给动作 a2a_2a2 的概率低一些。

        • 策略 π2\pi_2π2

          在相同状态 sss,可能恰好相反,给 a1a_1a1 的概率低,给 a2a_2a2 的概率高。

  2. 从策略依赖到最优性

    • 如果我们不想只评估一个具体策略,而是想找到 最优策略,那就需要考虑:对于每个状态 sss,什么样的动作选择(或策略)能最大化长期回报?

    • 于是,状态价值的定义变成:

      v∗(s)=max⁡πvπ(s),∀s∈Sv^*(s) = \max_\pi v_\pi(s), \quad \forall s \in \mathcal{S}v(s)=maxπvπ(s),sS

    • 这里的 max⁡π\max_\pimaxπ 表示:在所有可能的策略中,找到一个能使价值函数最大的策略。

  3. Bellman 最优性方程

    • max⁡π\max_\pimaxπ 引入 Bellman 方程,得到:

      v(s)=max⁡a[∑rp(r∣s,a)r+γ∑s’p(s’∣s,a)v(s’)]v^(s) = \max_a \Bigg[ \sum_r p(r \mid s,a) r + \gamma \sum_{s’} p(s’ \mid s,a) v^(s’) \Bigg]v(s)=maxa[rp(rs,a)r+γsp(ss,a)v(s)]

    • 关键点:

      • 在普通 Bellman 方程里:π(a∣s)\pi(a|s)π(as) 是已知的分布。
      • 在 Bellman 最优性方程里:我们不固定策略,而是 直接在动作层面取最大化,等价于“选择最优动作”。
      • 因此,最优价值函数 v∗(s)v^*(s)v(s) 不再依赖于某个具体的 π\piπ,而是内含了 策略优化的过程
  4. 和最优策略 π∗\pi^*π 的关系

    • 定义:

      π(s)=arg⁡max⁡a[∑rp(r∣s,a)r+γ∑s’p(s’∣s,a)v(s’)]\pi^(s) = \arg\max_a \Bigg[ \sum_r p(r \mid s,a) r + \gamma \sum_{s’} p(s’ \mid s,a) v^(s’) \Bigg]π(s)=argmaxa[rp(rs,a)r+γsp(ss,a)v(s)]

      即最优策略就是在每个状态下选择能使未来回报最大的动作。

    • 换句话说:

      • 普通 Bellman 方程 = 已知策略的价值评估
      • Bellman 最优性方程 = 在所有策略中选择最优的价值函数,从而定义了最优策略。

Bellman optimality equation (matrix-vector form):

v=max⁡π(rπ+γPπv)v = \max_\pi (r_\pi + \gamma P_\pi v)v=maxπ(rπ+γPπv)

where the elements corresponding to sss or s′s's are

[rπ]s≜∑aπ(a∣s)∑rp(r∣s,a)r,[r_\pi]_s \triangleq \sum_a \pi(a \mid s) \sum_r p(r \mid s,a) r,[rπ]saπ(as)rp(rs,a)r,

[Pπ]s,s′=p(s′∣s)≜∑aπ(a∣s)∑s′p(s′∣s,a)[P_\pi]{s,s'} = p(s' \mid s) \triangleq \sum_a \pi(a \mid s) \sum{s'} p(s' \mid s,a)[Pπ]s,s=p(ss)aπ(as)sp(ss,a)

Here max⁡π\max_\pimaxπ is performed elementwise.

Maximization on the right-hand side

Solve the Bellman optimality equation

必须先考虑右边的式子,即先有某个最优策略 π\piπ,然后才有最优的状态价值 v(s)v(s)v(s)

  • elementwise form

    v(s)=max⁡π∑aπ(a∣s)(∑rp(r∣s,a)r+γ∑s′p(s′∣s,a)v(s′)),∀s∈Sv(s) = \max_{\pi} \sum_a \pi(a \mid s) \left( \sum_r p(r \mid s,a) r + \gamma \sum_{s'} p(s' \mid s,a) v(s') \right), \quad \forall s \in \mathcal{S}v(s)=maxπaπ(as)(rp(rs,a)r+γsp(ss,a)v(s)),sS

    • Fix v′(s)v'(s)v(s) first and solve π\piπ:

      v(s)=max⁡π∑aπ(a∣s)q(s,a)v(s) = \max_\pi \sum_a \pi(a \mid s) q(s,a)v(s)=maxπaπ(as)q(s,a)

    • Inspired by the above example, considering that ∑aπ(a∣s)=1\sum_a \pi(a \mid s) = 1aπ(as)=1, we have

      max⁡π∑aπ(a∣s)q(s,a)=max⁡a∈A(s)q(s,a),\max_\pi \sum_a \pi(a \mid s) q(s,a) = \max_{a \in \mathcal{A}(s)} q(s,a),maxπaπ(as)q(s,a)=maxaA(s)q(s,a),

    • where the optimality is achieved when

      π(a∣s)={1,a=a∗0,a≠a∗\pi(a \mid s) = \begin{cases} 1, & a = a^* \\ 0, & a \neq a^* \end{cases}π(as)={1,0,a=aa=a

    • where a∗=arg⁡max⁡aq(s,a)a^* = \arg\max_a q(s,a)a=argmaxaq(s,a).

  • matrix-vector form

    v=max⁡π(rπ+γPπv)v = \max_\pi (r_\pi + \gamma P_\pi v)v=maxπ(rπ+γPπv)

    • Let

      f(v):=max⁡π(rπ+γPπv).f(v) := \max_\pi (r_\pi + \gamma P_\pi v).f(v):=maxπ(rπ+γPπv).

    • Then, the Bellman optimality equation becomes

      v=f(v)v = f(v)v=f(v)

    • where

      [f(v)]s=max⁡π∑aπ(a∣s)q(s,a),s∈S.[f(v)]s = \max\pi \sum_a \pi(a \mid s) q(s,a), \quad s \in \mathcal{S}.[f(v)]s=maxπaπ(as)q(s,a),sS.

Contraction mapping theorem

Fixed point:

x∈Xx \in XxX is a fixed point of f:X→Xf : X \to Xf:XX if f(x)=xf(x) = xf(x)=x

Contraction mapping (or contractive function):

fff is a contraction mapping if ∥f(x1)−f(x2)∥≤γ∥x1−x2∥\| f(x_1) - f(x_2) \| \leq \gamma \| x_1 - x_2 \|f(x1)f(x2)γx1x2, where γ∈(0,1)\gamma \in (0,1)γ(0,1).

  • γ\gammaγ must be strictly less than 111 so that many limits such as γk→0\gamma^k \to 0γk0 as k→∞k \to \inftyk hold.
  • Here ∥⋅∥\| \cdot \| can be any vector norm.

Contraction mapping theorem

For any equation that has the form of x=f(x)x = f(x)x=f(x), if fff is a contraction mapping, then

  • Existence: There exists a fixed point x∗x^*x satisfying f(x∗)=x∗f(x^*) = x^*f(x)=x.
  • Uniqueness: The fixed point x∗x^*x is unique.
  • Algorithm: Consider a sequence {xk}\{x_k\}{xk} where xk+1=f(xk)x_{k+1} = f(x_k)xk+1=f(xk), then xk→x∗x_k \to x^*xkx as k→∞k \to \inftyk. Moreover, the convergence rate is exponentially fast.

Solution

Let’s come back to the Bellman optimality equation:

v=f(v)=max⁡π(rπ+γPπv)v = f(v) = \max_\pi (r_\pi + \gamma P_\pi v)v=f(v)=maxπ(rπ+γPπv)

Contraction Property:

  • f(v)f(v)f(v) is a contraction mapping satisfying

    ∥f(v1)−f(v2)∥≤γ∥v1−v2∥\| f(v_1) - f(v_2) \| \leq \gamma \| v_1 - v_2 \|f(v1)f(v2)γv1v2

  • where γ\gammaγ is the discount rate!

Existence, Uniqueness, and Algorithm:

  • For the BOE v=f(v)=max⁡π(rπ+γPπv)v = f(v) = \max_\pi (r_\pi + \gamma P_\pi v)v=f(v)=maxπ(rπ+γPπv), there always exists a solution v∗v^*v and the solution is unique. The solution could be solved iteratively by

    vk+1=f(vk)=max⁡π(rπ+γPπvk)v_{k+1} = f(v_k) = \max_\pi (r_\pi + \gamma P_\pi v_k)vk+1=f(vk)=maxπ(rπ+γPπvk)

  • This sequence {vk}\{v_k\}{vk} converges to v∗v^*v exponentially fast given any initial guess v0v_0v0. The convergence rate is determined by γ\gammaγ.

Optimality

Suppose v∗v^*v is the solution to the Bellman optimality equation. It satisfies

v∗=max⁡π(rπ+γPπv∗)v^* = \max_\pi (r_\pi + \gamma P_\pi v^*)v=maxπ(rπ+γPπv)

Suppose

π∗=arg⁡max⁡π(rπ+γPπv∗)\pi^* = \arg\max_\pi (r_\pi + \gamma P_\pi v^*)π=argmaxπ(rπ+γPπv)

Then

v∗=rπ∗+γPπ∗v∗v^* = r_{\pi^*} + \gamma P_{\pi^*} v^*v=rπ+γPπv

Therefore, π∗\pi^*π is a policy and v∗=vπ∗v^* = v_{\pi^*}v=vπ is the corresponding state value.

Policy Optimality

  • Suppose that v∗v^*v is the unique solution to v=max⁡π(rπ+γPπv),v = \max_\pi (r_\pi + \gamma P_\pi v),v=maxπ(rπ+γPπv),
    and vπv_\pivπ is the state value function satisfying vπ=rπ+γPπvπv_\pi = r_\pi + \gamma P_\pi v_\pivπ=rπ+γPπvπ for any given policy π\piπ, then

    v≥vπ,∀πv^ \geq v_\pi, \quad \forall \pivvπ,π

Greedy Optimal Policy

  • For any s∈Ss \in \mathcal{S}sS, the deterministic greedy policy

    π(a∣s)={1,a=a(s)0,a≠a(s)\pi^(a \mid s) = \begin{cases} 1, & a = a^(s) \\ 0, & a \neq a^(s) \end{cases}π(as)={1,0,a=a(s)a=a(s)

  • is an optimal policy solving the BOE. Here,

    ∗a(s)=arg⁡max⁡aq(s,a),∗*a^(s) = \arg\max_a q^(s,a),*a(s)=argmaxaq(s,a),

  • where q(s,a):=∑rp(r∣s,a)r+γ∑s′p(s′∣s,a)v∗(s′)q^(s,a) := \sum_r p(r \mid s,a) r + \gamma \sum_{s'} p(s' \mid s,a) v^*(s')q(s,a):=rp(rs,a)r+γsp(ss,a)v(s)

  • Proof

    π(s)=arg⁡max⁡π∑aπ(a∣s)(∑rp(r∣s,a)r+γ∑s′p(s′∣s,a)v(s′))\pi^(s) = \arg\max_\pi \sum_a \pi(a \mid s) \left( \sum_r p(r \mid s,a) r + \gamma \sum_{s'} p(s' \mid s,a) v^(s') \right)π(s)=argmaxπaπ(as)(rp(rs,a)r+γsp(ss,a)v(s))

对公式的概括

  1. v∗v^*v 的意义

    • v∗v^*v 是一个“理想值表”,它告诉你:从每个状态出发,如果以后一直做出最优选择,能拿到的总回报是多少

    • 它满足一个自洽的关系式(Bellman 最优性方程):

      v∗(s)=max⁡a[即时奖励+γ×未来价值]v^*(s) = \max_a \Big[\text{即时奖励} + \gamma \times \text{未来价值}\Big]v(s)=maxa[即时奖励+γ×未来价值]

  2. π∗\pi^*π 的意义

    • π∗\pi^*π 是“最优策略”,它规定了:在每个状态下应该采取哪个动作,才能保证总回报不比任何其他策略差
    • 从公式上看,π∗\pi^*π 就是选择能让 v∗v^*v 达到最大的那个动作(也就是“贪心选择”)。
  3. Policy Optimality 定理

    • 对于任意其他策略 π\piπ,它的价值函数 vπv_\pivπ 都不会超过 v∗v^*v
    • v∗v^*v 是所有策略里能实现的最高水平,它一定支配所有其他策略的价值表。
  4. Greedy Optimal Policy 定理

    • 只要你已经有了 v∗v^*v,那么直接在每个状态里“选那个让回报最大化的动作”就能得到 π∗\pi^*π
    • 最优策略其实就是“贪心地”选动作,但前提是这个贪心是基于正确的 v∗v^*v

更进一步的解释

  1. 为什么要先有 v∗v^*v 才能得到 π∗\pi^*π
    • 因为 π∗\pi^*π 的定义依赖于“未来回报”,而未来回报就是由 v∗v^*v 描述的。
    • 一旦知道了 v∗v^*v,最优策略就能“顺理成章”地通过贪心法则推出来。
  2. 为什么 v∗v^*v 比任何 vπv_\pivπ 都大?
    • vπv_\pivπ 是“固定策略下”的表现。
    • v∗v^*v 是在每一步都挑选最优动作的表现。
    • 显然,如果你随时都能选最好的动作,你的表现不可能比其他任何固定策略差
  3. 为什么贪心策略一定最优?
    • 因为 Bellman 方程已经保证了:在 v∗v^*v 下,每个状态的最优价值都等于“选择最优动作”得到的回报。
    • 所以只要你在每个状态都执行这个“最优动作”,整个过程的价值函数自然等于 v∗v^*v
    • 也就是说:贪心 + 正确的价值表 = 全局最优策略

Analyzing optimal policies

What factors determine the optimal policy?

  • It can be clearly seen from the BOE

    v(s)=max⁡π∑aπ(a∣s)(∑rp(r∣s,a)r+γ∑s′p(s′∣s,a)v(s′))v(s) = \max_\pi \sum_a \pi(a \mid s) \left( \sum_r p(r \mid s,a) r \;+\; \gamma \sum_{s'} p(s' \mid s,a) v(s') \right)v(s)=maxπaπ(as)(rp(rs,a)r+γsp(ss,a)v(s))

  • that there are three factors:

    • Reward design: rrr
    • System model: p(s′∣s,a),p(r∣s,a)p(s' \mid s,a), \; p(r \mid s,a)p(ss,a),p(rs,a)
    • Discount rate: γ\gammaγ
  • In this equation, v(s),v(s′),π(a∣s)v(s), v(s'), \pi(a \mid s)v(s),v(s),π(as) are unknowns to be calculated.

Optimal Policy Invariance

  • Consider a Markov decision process with v∗∈R∣S∣v^* \in \mathbb{R}^{|\mathcal{S}|}vRS as the optimal state value satisfying

    v∗=max⁡π(rπ+γPπv∗).v^* = \max_\pi (r_\pi + \gamma P_\pi v^*).v=maxπ(rπ+γPπv).

  • If every reward rrr is changed by an affine transformation to ar+bar + bar+b, where a,b∈Ra, b \in \mathbb{R}a,bR and a≠0a \neq 0a=0, then the corresponding optimal state value v′v'v is also an affine transformation of v∗v^*v:

    v′=av∗+b1−γ1,v' = a v^* + \frac{b}{1-\gamma} \mathbf{1},v=av+1γb1,

    • where γ∈(0,1)\gamma \in (0,1)γ(0,1) is the discount rate and 1=[1,…,1]T\mathbf{1} = [1, \ldots, 1]^T1=[1,,1]T.
  • Consequently, the optimal policies are invariant to the affine transformation of the reward signals.


总结

Bellman 最优性方程刻画了在所有策略中选择最优策略的价值函数,它保证存在唯一的最优状态价值 v∗v^*v,并且通过对每个状态下的动作取最大化(贪心原则)即可导出最优策略 π∗\pi^*π,同时最优策略的性质只依赖于奖励设计、环境转移模型和折扣因子,而对奖励的仿射变换保持不变。


文章转载自:

http://aBuTtheL.qzpsk.cn
http://Zj9iKo3N.qzpsk.cn
http://MlLmy2fT.qzpsk.cn
http://g4yRYE7w.qzpsk.cn
http://1zxaKCcg.qzpsk.cn
http://9Btz0ctH.qzpsk.cn
http://u1rf7Grd.qzpsk.cn
http://o5OmfnvY.qzpsk.cn
http://9wMSnX12.qzpsk.cn
http://xqmMDDPH.qzpsk.cn
http://3asuxSKR.qzpsk.cn
http://EI81iLt6.qzpsk.cn
http://UGpyT00e.qzpsk.cn
http://KUNM7Err.qzpsk.cn
http://x45JgTvN.qzpsk.cn
http://NSJnWVaP.qzpsk.cn
http://Bp30EsY0.qzpsk.cn
http://lrfyqqHc.qzpsk.cn
http://GoLXIUbf.qzpsk.cn
http://Ta64lj9V.qzpsk.cn
http://XtXFSRiQ.qzpsk.cn
http://JzOwRqig.qzpsk.cn
http://os9rjalC.qzpsk.cn
http://axPIm1Dr.qzpsk.cn
http://d0s3vS9t.qzpsk.cn
http://HBQLxYbx.qzpsk.cn
http://XaIz3zCH.qzpsk.cn
http://AZUalGaE.qzpsk.cn
http://l2PlyBIS.qzpsk.cn
http://nTrjyJZR.qzpsk.cn
http://www.dtcms.com/a/368329.html

相关文章:

  • Apache Ranger 详细介绍
  • 计算机网络IP协议
  • Git rm 命令与系统 rm 命令的区别详解
  • More Effective C++ 条款30:代理类
  • 织信低代码:用更聪明的方式,把想法变成现实!
  • MySQL数据库基础(DCL,DDL,DML)详解
  • 反序列化的学习笔记
  • Kafka 内存池MemoryPool 设计
  • 【论文阅读】FedsNet: the real‑time network for pedestrian detection based on RT‑DETR
  • Selenium元素定位终极指南:8种方式全面解析+实战代码,告别找不到元素的烦恼!
  • 【MFC Picture Control 控件属性】
  • 迁移学习实战:基于 ResNet18 的食物分类
  • python用selenium怎么规避检测?
  • Rust 的生命周期与借用检查:安全性深度保障的基石
  • 面试 TOP101 贪心专题题解汇总Java版(BM95 —— BM96)
  • 软件启动时加配置文件 vs 不加配置文件
  • 工业跨网段通信解决方案:SG-NAT-410 网关,无需改参数,轻松打通异构 IP 网络
  • Elasticsearch-java 使用例子
  • 我改写的二分法XML转CSV文件程序速度追上了张泽鹏先生的
  • GPU测速方法
  • OpenCV C++ 色彩空间详解:转换、应用与 LUT 技术
  • 前端笔记2025
  • 跨境电商:如何提高电商平台数据抓取效率?
  • python + Flask模块学习 2 接收用户请求并返回json数据
  • K8S-Pod(上)
  • 【代码随想录day 23】 力扣 93.复原IP地址
  • 数据结构:栈和队列(下)
  • SAP官方授权供应商名单2025
  • 结构体简介
  • UE4 Mac构建编译报错 no template named “is_void_v” in namespace “std”