
---


在强化学习中，状态价值函数、动作价值函数以及贝尔曼方程构成了整个马尔可夫决策过程（MDP）和序列决策理论的数学基石。无论是基础的动态规划，还是高级的深度强化学习（如 PPO、TD3、MADDPG），其本质都是对这些核心方程的近似与求解。

以下是关于这些概念的严格数学定义与推导。

## 一、 理论前提与符号定义

为了进行严谨的推导，我们需要先界定随机变量与系统动力学。

1. **马尔可夫决策过程 (MDP)**：定义为一个元组 $\langle \mathcal{S}, \mathcal{A}, p, \gamma \rangle$。
    
    - $S_t \in \mathcal{S}$ 为 $t$ 时刻的状态随机变量，$A_t \in \mathcal{A}$ 为动作随机变量。
        
    - $p(s', r | s, a) \doteq \mathbb{P}(S_{t+1}=s', R_{t+1}=r \mid S_t=s, A_t=a)$ 是环境的联合动力学函数，表示在状态 $s$ 执行动作 $a$ 后，转移到下一状态 $s'$ 并获得即时奖励 $r$ 的概率。
        
    - $\gamma \in [0, 1]$ 是折扣因子。
        
2. **策略 (Policy)**：$\pi(a|s) \doteq \mathbb{P}(A_t=a | S_t=s)$，表示在状态 $s$ 下选择动作 $a$ 的概率分布。
    
3. **折扣回报 (Discounted Return)**：定义为从时刻 $t$ 开始到回合结束所能获得的折扣奖励总和，记为随机变量 $G_t$：
    
    $$G_t \doteq R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \dots = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1}$$
    
    这里存在一个极其重要的**递归结构**：
    
    $$G_t = R_{t+1} + \gamma \left( R_{t+2} + \gamma R_{t+3} + \dots \right) = R_{t+1} + \gamma G_{t+1}$$
    

## 二、 价值函数的严格定义

强化学习的目标是最大化期望回报。由于环境转移和策略本身都具有随机性，$G_t$ 是一个随机变量。我们通过对其求数学期望来评估状态或动作的好坏。

### 1. 状态价值函数 (State-Value Function) $v_\pi(s)$

定义为在策略 $\pi$ 下，从状态 $s$ 出发所能获得的**期望回报**：

$$v_\pi(s) \doteq \mathbb{E}_\pi [G_t \mid S_t = s]$$

**物理意义**：评价在给定策略下，智能体处于状态 $s$ 有多“好”。它是对未来无穷步奖励的一个标量压缩。

### 2. 动作价值函数 (Action-Value Function) $q_\pi(s, a)$

定义为在策略 $\pi$ 下，从状态 $s$ 出发，**首先执行动作 $a$**，随后遵循策略 $\pi$ 所能获得的期望回报：

$$q_\pi(s, a) \doteq \mathbb{E}_\pi [G_t \mid S_t = s, A_t = a]$$

**物理意义**：不仅评价当前状态的好坏，还评估在该状态下采取某个特定动作的优劣。

### 3. $v_\pi$ 与 $q_\pi$ 的内在联系

根据全概率公式（对动作 $a$ 进行边缘化），状态价值等于在该状态下所有可能动作价值的期望：

$$v_\pi(s) = \sum_{a \in \mathcal{A}} \pi(a|s) q_\pi(s, a)$$

## 三、 贝尔曼期望方程的推导 (Bellman Expectation Equations)

贝尔曼方程的核心思想是动态规划（Dynamic Programming）中的最优子结构：**当前状态的价值可以由下一状态的价值来表达**。这就是时序差分学习（TD Learning）中“自举（Bootstrapping）”操作的数学根源。

### 1. 推导状态价值函数的贝尔曼期望方程

利用回报的递归性 $G_t = R_{t+1} + \gamma G_{t+1}$，将期望展开：

$$\begin{align*} v_\pi(s) &= \mathbb{E}_\pi [G_t \mid S_t = s] \\ &= \mathbb{E}_\pi [R_{t+1} + \gamma G_{t+1} \mid S_t = s] \end{align*}$$

现在，我们需要根据随机变量发生的先后顺序将期望 $\mathbb{E}_\pi$ 具体化。从 $S_t=s$ 出发，首先根据策略 $\pi$ 采样动作 $a$，然后根据环境动力学 $p$ 采样下一个状态 $s'$ 和奖励 $r$：

$$\begin{align*} v_\pi(s) &= \sum_{a} \pi(a|s) \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma \mathbb{E}_\pi [G_{t+1} \mid S_{t+1} = s'] \right] \end{align*}$$

注意到最后一项 $\mathbb{E}_\pi [G_{t+1} \mid S_{t+1} = s']$ 严格等价于 $v_\pi(s')$，代入即得**状态价值的贝尔曼期望方程**：

$$v_\pi(s) = \sum_{a} \pi(a|s) \sum_{s', r} p(s', r \mid s, a) \big[ r + \gamma v_\pi(s') \big]$$

### 2. 推导动作价值函数的贝尔曼期望方程

同样的逻辑，考察 $q_\pi(s, a)$。此时当前的动作 $a$ 已经给定，因此最外层不需要对动作按照策略求期望，直接根据环境动力学展开：

$$\begin{align*} q_\pi(s, a) &= \mathbb{E}_\pi [G_t \mid S_t = s, A_t = a] \\ &= \mathbb{E}_\pi [R_{t+1} + \gamma G_{t+1} \mid S_t = s, A_t = a] \\ &= \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma \mathbb{E}_\pi [G_{t+1} \mid S_{t+1} = s'] \right] \end{align*}$$

同样，这里的 $\mathbb{E}_\pi [G_{t+1} \mid S_{t+1} = s']$ 就是 $v_\pi(s')$：

$$q_\pi(s, a) = \sum_{s', r} p(s', r \mid s, a) \big[ r + \gamma v_\pi(s') \big]$$

为了得到一个纯粹关于 $q$ 的递归方程，我们将前文提到的公式 $v_\pi(s') = \sum_{a'} \pi(a'|s') q_\pi(s', a')$ 代入，得到**动作价值的贝尔曼期望方程**：

$$q_\pi(s, a) = \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma \sum_{a'} \pi(a'|s') q_\pi(s', a') \right]$$

## 四、 贝尔曼最优方程 (Bellman Optimality Equations)

解决强化学习问题的最终目标是寻找**最优策略 $\pi_*$**。当存在一个策略，其在所有状态下的价值都不低于其他任何策略时，该策略即为最优策略。

- **最优状态价值函数**：$v_*(s) = \max_\pi v_\pi(s)$
    
- **最优动作价值函数**：$q_*(s, a) = \max_\pi q_\pi(s, a)$
    

在最优策略下，智能体不再遵循某个概率分布 $\pi(a|s)$ 去盲目采样动作，而是**确定性地选择具有最高期望回报的动作**。因此，公式中的求和 $\sum_{a} \pi(a|s)$ 被 $\max_a$ 操作所取代。

### 1. 贝尔曼最优方程的推导

最优状态价值必须等于在该状态下执行最优动作所获得的价值：

$$v_*(s) = \max_{a \in \mathcal{A}} q_*(s, a)$$

将其代入前文的动作价值表达式，得到**最优状态价值的贝尔曼最优方程**：

$$v_*(s) = \max_{a} \sum_{s', r} p(s', r \mid s, a) \big[ r + \gamma v_*(s') \big]$$

反过来，考察最优动作价值。即使当前动作 $a$ 给定，到达下一个状态 $s'$ 后，由于遵循的是最优策略，未来的动作依然是使得 $q$ 最大的动作。将 $v_*(s') = \max_{a'} q_*(s', a')$ 代入，得到**最优动作价值的贝尔曼最优方程**：

$$q_*(s, a) = \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma \max_{a'} q_*(s', a') \right]$$

## 五、 方程的理论意义与算法映射

上述方程虽然是精确的解析形式，但它们构成了几乎所有主流强化学习算法的演进基石：

1. **动态规划 (DP) 的基础**：如果环境模型 $p(s',r|s,a)$ 完全已知，贝尔曼方程构成了一个非线性方程组。通过**策略评估 (Policy Evaluation)** 和**价值迭代 (Value Iteration)**，可以直接将其转化为更新规则（即将等号化为赋值符号 $\leftarrow$）来精确求解。
    
2. **向无模型 (Model-Free) 与 TD 学习的过渡**：当环境模型 $p$ 未知时，我们无法精确计算期望。因此引出了**时序差分学习 (TD Learning)**。
    
    - 以 Q-Learning 为例，其核心更新公式：
        
        $$Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha \left[ R_{t+1} + \gamma \max_{a'} Q(S_{t+1}, a') - Q(S_t, A_t) \right]$$
        
        本质上就是对**贝尔曼最优方程 $q_*$** 的随机近似。由于无法遍历 $p(s', r|s, a)$，算法通过在环境中采样真实的经验 $(S_t, A_t, R_{t+1}, S_{t+1})$ 来近似期望值，而 $[R_{t+1} + \gamma \max_{a'} Q(S_{t+1}, a')]$ 正是贝尔曼目标的经验样本，即 TD Target。





在强化学习中，你前一个问题中提到的**贝尔曼方程**（Bellman Equation）描述了价值函数必须满足的理论**等式（Identity）**。而**贝尔曼回溯**（Bellman Backup）则是将这一静态等式转化为动态算法操作（Algorithmic Operation）的具体过程。

“回溯（Backup）”一词形象地描述了信息的流动方向：**状态 $s$ 的价值，是通过“回溯（拉回）”其后续状态 $s'$ 的价值以及即时奖励 $r$ 来更新的**。在图模型或备份图（Backup Diagram）中，信息沿着时间箭头逆向传播。

以下是关于贝尔曼回溯的严格数学定义与算法分类。

## 一、 数学抽象：贝尔曼算子 (Bellman Operators)

要严谨地定义贝尔曼回溯，最精确的工具是**算子理论**。

我们将所有可能的状态价值函数构成一个向量空间 $\mathcal{V} \subset \mathbb{R}^{|\mathcal{S}|}$。贝尔曼回溯本质上是对当前价值函数向量 $v \in \mathcal{V}$ 应用一个映射算子 $\mathcal{T}$，生成一个新的价值函数向量 $v'$ 的过程。

**一次贝尔曼回溯 (One Bellman Backup)** 的数学表达为：

$$v_{k+1} \leftarrow \mathcal{T} v_k$$

根据目标的不同，存在两种核心的算子（对应两种回溯）：

### 1. 贝尔曼期望回溯 (Bellman Expectation Backup)

用于**策略评估（Policy Evaluation）**。其对应的算子为 $\mathcal{T}^\pi: \mathcal{V} \to \mathcal{V}$，定义为：

$$(\mathcal{T}^\pi v)(s) \doteq \sum_{a \in \mathcal{A}} \pi(a|s) \sum_{s', r} p(s', r \mid s, a) [r + \gamma v(s')]$$

这一步操作强行要求当前状态的价值等于未来的期望价值。

### 2. 贝尔曼最优回溯 (Bellman Optimality Backup)

用于**价值迭代（Value Iteration）**，直接寻找最优价值。其对应的算子为 $\mathcal{T}^*: \mathcal{V} \to \mathcal{V}$，定义为：

$$(\mathcal{T}^* v)(s) \doteq \max_{a \in \mathcal{A}} \sum_{s', r} p(s', r \mid s, a) [r + \gamma v(s')]$$

这一步操作假设在当前状态执行最优动作，并以此回溯价值。

## 二、 回溯的实现分类：全期望与采样

在实际算法中，由于环境模型 $p(s',r|s,a)$ 的已知与否，贝尔曼回溯在执行时分为两种截然不同的形态：

### 1. 期望回溯 / 全回溯 (Expected / Full Backup)

- **适用场景：** 基于模型的动态规划（Dynamic Programming）。环境动力学 $p$ 完全已知。
    
- **操作方式：** 针对给定的状态 $s$，算法必须**展开所有可能的动作分支以及所有可能的下一状态转移分支**，计算其加权期望（或取最大值）。
    
- **计算复杂度：** $\mathcal{O}(|\mathcal{A}| |\mathcal{S}|)$ 单次状态更新。这就是为什么面对高维或连续状态空间时，DP 会遭遇“维度灾难（Curse of Dimensionality）”。
    

### 2. 采样回溯 (Sample Backup)

- **适用场景：** 无模型强化学习（Model-Free RL），如蒙特卡洛（MC）和时序差分（TD）。环境动力学未知，或状态空间过大无法遍历。
    
- **操作方式：** 不展开所有概率分支，而是让智能体在环境中实际执行（或从 Replay Buffer 中采样），获得一条具体的转移经验数据 $(S_t, A_t, R_{t+1}, S_{t+1})$。然后仅沿着这条**单一的采样轨迹**进行价值的“拉回”。
    
- **例如 Q-Learning 的采样最优回溯：**
    
    $$Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha \Big[ \underbrace{R_{t+1} + \gamma \max_{a'} Q(S_{t+1}, a')}_{\text{Sample Backup Target}} - Q(S_t, A_t) \Big]$$
    
    采样回溯用经验样本代替了复杂的概率求和期望，虽然引入了方差，但打破了对已知环境模型的依赖，使得在大规模连续空间（如多智能体、机器人控制）中结合深度学习成为可能。
    

## 三、 回溯深度的扩展 (Multi-step Backups)

标准的贝尔曼回溯是**单步回溯（1-step backup）**，即只看未来一步 $s'$，然后立刻利用现有的 $v(s')$ 进行自举（Bootstrapping）。我们也可以将其推广到任意深度：

1. **$n$ 步回溯 ($n$-step Backup):**
    
    收集真实的 $n$ 步奖励，然后用第 $n+1$ 步的状态价值进行自举。
    
    目标：$G_{t:t+n} = R_{t+1} + \gamma R_{t+2} + \dots + \gamma^{n-1} R_{t+n} + \gamma^n V(S_{t+n})$
    
2. **$\lambda$-回溯 ($\lambda$-Backup):**
    
    著名的 $\text{TD}(\lambda)$ 算法的核心。它是所有 $n$ 步回溯（从 $n=1$ 到 $n=\infty$）的指数加权平均，权重为 $(1-\lambda)\lambda^{n-1}$。这在偏差（Bias，单步回溯大）和方差（Variance，无限步回溯大）之间提供了严谨的数学权衡机制。
    

## 四、 理论收敛保证：压缩映射

为什么反复执行贝尔曼回溯 $v_{k+1} \leftarrow \mathcal{T} v_k$ 最终能找到正确的价值函数？这有着极其严密的泛函分析支撑。

在配备了无穷范数（极大值范数） $\|v\|_\infty = \max_s |v(s)|$ 的度量空间中，可以证明无论是 $\mathcal{T}^\pi$ 还是 $\mathcal{T}^*$，都是一个$\gamma$-压缩映射 ($\gamma$-Contraction Mapping)。

对于任意两个价值函数 $u, v \in \mathcal{V}$，应用一次回溯后，它们之间的最大差距必定缩小 $\gamma$ 倍（$\gamma < 1$ 是折扣因子）：

$$\| \mathcal{T}u - \mathcal{T}v \|_\infty \le \gamma \| u - v \|_\infty$$

根据**巴拿赫不动点定理 (Banach Fixed-Point Theorem)**，既然回溯算子是压缩映射，那么：

1. 存在**唯一的不动点**（即真实的 $v_\pi$ 或最优的 $v_*$）。
    
2. 无论从什么初始价值猜测 $v_0$ 开始，无限次反复应用回溯操作 $\lim_{k \to \infty} \mathcal{T}^k v_0$，必然绝对收敛到该唯一不动点。
    

这也是所有基于价值（Value-based）的强化学习算法能够在数学上站得住脚的根本原因。









---





下面默认讨论**固定策略 $\pi$ 下的 policy evaluation**。这是区分 **Bellman error**, **projected Bellman error**, **TD-error** 最清晰的设定。控制问题中只需把 $T^\pi$ 换成最优 Bellman 算子 $T^*$，或把 $V$换成 $Q$。

---

# 1. 基本设定：Bellman 方程

有限状态 MDP，固定策略 $\pi$。定义：
$$
P_\pi(s'|s)=\sum_a \pi(a|s)P(s'|s,a),  
$$
$$
r_\pi(s)=\mathbb E_\pi[R_{t+1}\mid S_t=s].  
$$
状态价值函数为：
$$
v_\pi(s)
=
\mathbb E_\pi  
\left[  
\sum_{k=0}^{\infty}\gamma^k R_{t+k+1}  
\mid S_t=s  
\right].  
$$
对应的 Bellman 方程是：
$$
v_\pi = T_\pi v_\pi,  
$$
其中 Bellman operator 为：
$$
(T_\pi v)(s)
=
r_\pi(s)  
+  
\gamma \sum_{s'}P_\pi(s'|s)v(s').  
$$
向量形式：
$$
T_\pi v
=
r_\pi+\gamma P_\pi v.  
$$
**真值函数 $v_\pi$ 是 Bellman 方程的固定点**。==Bellman equation 在完整状态空间上由真值函数唯一满足；Bellman error 则是衡量某个近似值函数偏离这个方程的残差。==**Fujimoto 等人也明确将 Bellman error 定义为 Bellman 方程两侧之差，并指出 Bellman equation 在所有状态—动作对上由真值函数唯一满足。**(https://proceedings.mlr.press/v162/fujimoto22a/fujimoto22a.pdf)

---

# 2. Bellman error：Bellman 方程残差

给定任意近似值函数 $v$，其 **Bellman error** 或 **Bellman residual** 定义为：
$$
\boxed{  
\mathcal B(v)
=
T_\pi v-v.  
}  
$$
逐状态写为：
$$
\boxed{  
\mathcal B(v)(s)
=
 r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s')
-
v(s).  
}  
$$
如果：
$$
\mathcal B(v)(s)=0,\qquad \forall s,  
$$
则：
$$
v=T_\pi v.  
$$
**在Discounted MDP 中**，**Bellman operator 是 contraction(收缩映射不)**，因此固定点(fix point)唯一，于是：
$$
v=v_\pi.  
$$
所以：
$$
\boxed{  
\text{Bellman error 为 0}  
\Longleftrightarrow  
\text{满足 Bellman 方程}  
\Longleftrightarrow  
v=v_\pi.  
}  
$$
常见的标量目标是 **mean-square Bellman error, MSBE**：
$$
\boxed{  
\mathrm{MSBE}(v)
=
|T_\pi v-v|_D^2.  
}  
$$
其中 $D$ 是某个状态分布的对角矩阵，例如：
$$
D=\operatorname{diag}(d(s)).  
$$
范数定义为：
$$
||x||_D^2=x^\top D x=\sum_s d(s)x(s)^2.  
$$
==Sutton、Szepesvári 和 Maei 在 GTD/TDC 论文中把真值函数满足的 Bellman equation 写为 $V=R+\gamma PV=TV$，并把近似函数满足 Bellman 方程的均方残差定义为 MSBE：$||V_\theta-TV_\theta||_D^2$。==(https://icml.cc/Conferences/2009/papers/546.pdf)

---

# 3. TD-error：单个样本上的随机 Bellman 残差估计

**TD-error 是单个 transition 上的瞬时误差**：
$$
\boxed{  
\delta_t
=
 R_{t+1}  
+  
\gamma V(S_{t+1})
-
V(S_t).  
}  
$$
如果 $V=v_\theta$，则：
$$
\delta_t(\theta)
=
 R_{t+1}  
+  
\gamma v_\theta(S_{t+1})
-
v_\theta(S_t).  
$$
Sutton 与 Barto 在 eligibility traces 章节中给出 **state-value prediction 的 TD error**：
$$
\delta_t=R_{t+1}+\gamma V_t(S_{t+1})-V_t(S_t),  
$$
并说明 backward view $TD(\lambda)$ 中该全局 TD-error 会按 eligibility traces 更新最近访问过的状态。(https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf)

---

## 3.1 **TD-error 与 Bellman error 的关系**

TD-error 是随机变量。对当前状态 $S_t=s$ 条件取期望：
$$
\begin{aligned}  
\mathbb E[\delta_t\mid S_t=s]  
&=  
\mathbb E[  
R_{t+1}  
+  
\gamma V(S_{t+1})
-
V(S_t)  
\mid S_t=s]  
\\  
&=  
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)V(s')
-
V(s)  
\\  
&=  
(T_\pi V)(s)-V(s).  
\end{aligned}  
$$
因此：
$$
\boxed{  
\mathbb E[\delta_t\mid S_t=s]
=
\mathcal B(V)(s).  
}  
$$
也就是说：
$$
\boxed{  
\text{TD-error 是 Bellman error 的单样本随机估计。}  
}  
$$
但要注意：
$$
\delta_t  
\neq  
\mathcal B(V)(S_t)  
$$
一般不逐样本相等。因为 $\delta_t$依赖具体采样到的 $R_{t+1}$ 和 $S_{t+1}$，**而 Bellman error 是对这些随机性的条件期望。**

---

# 4. Mean Squared TD error 不等于 MSBE

很多混淆来自下面两个量：
$$
\mathrm{MSBE}(V)
=
\mathbb E_{S\sim d}  
\left[  
\left(  
\mathbb E[\delta\mid S]  
\right)^2  
\right],  
$$
而 mean squared TD error 是：
$$
\mathrm{MSTDE}(V)
=
\mathbb E[\delta^2].  
$$
由**条件方差**分解：
$$
\mathbb E[\delta^2]
=
\mathbb E  
\left[  
\left(  
\mathbb E[\delta\mid S]  
\right)^2  
\right]  
+  
\mathbb E  
\left[  
\operatorname{Var}(\delta\mid S)  
\right].  
$$
因此：
$$
\boxed{  
\mathrm{MSTDE}(V)
=
\mathrm{MSBE}(V)  
+  
\mathbb E[\operatorname{Var}(\delta\mid S)].  
}  
$$
这说明：
$$
\boxed{  
\text{squared TD-error 包含 Bellman error 之外的环境随机性噪声。}  
}  
$$
所以最小化单样本 squared TD-error 并不等价于最小化 MSBE。Sutton 等人的 GTD/TDC 论文中也特别指出，在某些例子中 squared TD error 可能很大，而 expected TD error，也就是 Bellman error，却可以为零；这正说明单样本平方 TD 误差和 Bellman 残差不是同一个对象。==(https://icml.cc/Conferences/2009/papers/546.pdf)

---

# 5. 函数近似空间与投影

现在考虑线性函数近似：
$$
v_\theta(s)=\phi(s)^\top\theta.  
$$
令**特征矩阵（state-feature embeding matrix）** 为：
$$
\Phi
=
\begin{bmatrix}  
\phi(s_1)^\top\\  
\phi(s_2)^\top\\  
\vdots\\  
\phi(s_{|\mathcal S|})^\top  
\end{bmatrix}.  
$$
因此：
$$
v_\theta=\Phi\theta.  
$$
==**所有可表示的值函数**  构成一个**线性子空间**：
$$
\mathcal V
=
\{v_\theta:\theta\in\mathbb R^d\}
=
\operatorname{span}(\Phi).  
$$
问题在于：
$$
T_\pi v_\theta  
$$
通常不在 $\mathcal V$ 中。

==也就是说，即使 $v_\theta$ 可由特征表示，**Bellman 更新**后的函数：
$$
T_\pi v_\theta
=
r_\pi+\gamma P_\pi \Phi\theta  
$$
也不一定能写成：
$$
\Phi\theta'  
$$
的形式。==

因此，不能直接要求：
$$
v_\theta=T_\pi v_\theta.  
$$
因为**右侧可能落在函数近似空间之外**。

==**这就是 projected Bellman error 出现的原因。**==


---
核心问题是：**线性函数近似把值函数限制在一个低维线性子空间中，但 Bellman 算子一般不会把这个子空间映射回自身。因此，精确 Bellman 方程 $v=T_\pi v$ 在近似空间内通常无解，只能改成 projected Bellman equation。**

### 1. 线性函数近似到底在做什么？

设有限状态空间为：
$$
\mathcal S=\{s_1,s_2,\dots,s_{|\mathcal S|}\}.  
$$

每个状态 $s$ 对应一个特征向量：
$$
\phi(s)\in\mathbb R^d.  
$$
线性价值函数近似为：
$$
v_\theta(s)=\phi(s)^\top\theta,  
\qquad \theta\in\mathbb R^d.  
$$
对所有状态同时写成向量形式：

$$
v_\theta=  
\begin{bmatrix}  
v_\theta(s_1)\\  
v_\theta(s_2)\\  
\vdots\\  
v_\theta(s_{|\mathcal S|})  
\end{bmatrix}
=
\begin{bmatrix}  
\phi(s_1)^\top\\  
\phi(s_2)^\top\\  
\vdots\\  
\phi(s_{|\mathcal S|})^\top  
\end{bmatrix}  
\theta.  
$$
令：
$$
\Phi
=
\begin{bmatrix}  
\phi(s_1)^\top\\  
\phi(s_2)^\top\\  
\vdots\\  
\phi(s_{|\mathcal S|})^\top  
\end{bmatrix}  
\in\mathbb R^{|\mathcal S|\times d}.  
$$
于是：
$$
\boxed{  
v_\theta=\Phi\theta.  
}  
$$
这里 $v_\theta\in\mathbb R^{|\mathcal S|}$，而$\theta\in\mathbb R^d$。

如果 $d<<|\mathcal S|$，那么不是所有状态价值向量都能被表示。能被表示的所有价值函数为：
$$
\mathcal V
=
\{\Phi\theta:\theta\in\mathbb R^d\}.  
$$
严格说：
$$
\boxed{  
\mathcal V=\operatorname{Col}(\Phi),  
}  
$$
即 $\Phi$ 的**列空间**。很多 RL 文献也写作 $\operatorname{span}(\Phi)$，但更准确地说是 $\Phi$ 的 column span，不是行向量 $\phi(s_i)^\top$ 的 span。Sutton 与 Barto 在函数近似章节中正是用特征向量 $\mathbf x(s)$ 与参数 $\mathbf w$ 表示线性价值函数，并把可表示的价值函数集合看作一个低维子空间；Sutton、Szepesvári 和 Maei 在 GTD 论文中也使用 $V_\theta=\Phi\theta$ 与投影 Bellman 误差来分析线性 TD。([Stanford University](https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf?utm_source=chatgpt.com "Reinforcement Learning: An Introduction"))

---

### 2. 为什么 $\mathcal V$是线性子空间？

因为对任意两个可表示的值函数：
$$
v_{\theta_1}=\Phi\theta_1,  
\qquad  
v_{\theta_2}=\Phi\theta_2,  
$$
以及任意标量 $(a,b)$，有：
$$
a v_{\theta_1}+b v_{\theta_2}
=
 a\Phi\theta_1+b\Phi\theta_2
=
\Phi(a\theta_1+b\theta_2).  
$$
由于：


$$
a\theta_1+b\theta_2\in\mathbb R^d,  
$$

所以：
$$
a v_{\theta_1}+b v_{\theta_2}\in\mathcal V.  
$$
因此：
$$
\boxed{  
\mathcal V=\{\Phi\theta:\theta\in\mathbb R^d\}  
}  
$$
对线性组合封闭，是 $\mathbb R^{|\mathcal S|}$ 中的一个线性子空间。

直观上，完整的 tabular 值函数空间是：

$$
\mathbb R^{|\mathcal S|}.  
$$

每个状态一个自由参数。但线性函数近似只允许：


$$
v_\theta(s)=\phi(s)^\top\theta.  
$$
因此所有状态价值必须共享同一个参数 $\theta$。这会把可表示的函数限制在一个低维平面 / 子空间中。

---

### 3. Bellman 算子作用在哪里？

固定策略 $\pi$ 下，Bellman 算子为：
$$
(T_\pi v)(s)
=
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s').  
$$
向量形式：


$$
\boxed{  
T_\pi v=r_\pi+\gamma P_\pi v.  
}  
$$

其中：


$$
r_\pi\in\mathbb R^{|\mathcal S|},  
\qquad  
P_\pi\in\mathbb R^{|\mathcal S|\times |\mathcal S|}.  
$$

如果：


$$
v=v_\theta=\Phi\theta,  
$$

那么 Bellman 更新为：

$$
\boxed{  
T_\pi v_\theta
=
r_\pi+\gamma P_\pi\Phi\theta.  
}  
$$

这个向量仍然属于完整空间：


$$
\mathbb R^{|\mathcal S|}.  
$$


但不一定属于近似空间：


$$
\mathcal V=\operatorname{Col}(\Phi).  
$$


Sutton、Szepesvári 和 Maei 在讨论 MSPBE 时指出，TD 方法常收敛到组合算子 $\Pi T$ 的 fixed point，而不是直接满足 $V_\theta=TV_\theta$；这正是因为 $TV_\theta$ 一般不在函数近似空间中，需要投影回该空间。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

### 4. 为什么 $T_\pi v_\theta$ 通常不在 $\mathcal V$ 中？

要使：

$$
T_\pi v_\theta\in\mathcal V,  
$$


必须存在某个 $\theta'$，使得：


$$
T_\pi v_\theta=\Phi\theta'.  
$$


也就是：


$$
r_\pi+\gamma P_\pi\Phi\theta=\Phi\theta'.  
$$

这要求 Bellman 更新后的向量仍然能由同一组特征线性表示。

但一般情况下不成立。原因有两个。

---

### 4.1 奖励向量 $r_\pi$ 可能不在 $\operatorname{Col}(\Phi)$

如果 $r_\pi\notin\operatorname{Col}(\Phi)$，那么即使 $\gamma=0$，也有：


$$
T_\pi v_\theta=r_\pi.  
$$


此时 $T_\pi v_\theta$ 已经不在 $\mathcal V$ 中。

换言之，近似空间若无法表示奖励结构，Bellman target 就可能立刻跳出近似空间。

---

### 4.2 转移矩阵 $P_\pi$ 可能不保持特征子空间不变

即使：


$$
v_\theta=\Phi\theta\in\mathcal V,  
$$

也未必有：


$$
P_\pi\Phi\theta\in\mathcal V.  
$$

要保证对所有 $\theta$ 都成立，需要：


$$
\boxed{  
P_\pi \operatorname{Col}(\Phi)\subseteq \operatorname{Col}(\Phi).  
}  
$$

也就是说，特征子空间必须在 $P_\pi$ 作用下保持不变。这是一个很强的条件，一般不会满足。

因此，通常：

[
$$
\boxed{  
T_\pi \mathcal V \nsubseteq \mathcal V.  
}  
$$
也就是 Bellman 算子不会把近似空间映射回近似空间。

---

### 5. 一个最小例子：Bellman 更新跳出近似空间

设只有两个状态：


$$
\mathcal S={s_1,s_2}.  
$$

使用一个常数特征：


$$
\phi(s_1)=1,  
\qquad  
\phi(s_2)=1.  
$$

于是：


$$
\Phi=  
\begin{bmatrix}  
1\\  
1  
\end{bmatrix}.  
$$


所有可表示的值函数为：


$$
v_\theta=  
\Phi\theta
=
\begin{bmatrix}  
\theta\\  
\theta  
\end{bmatrix}.  
$$

因此：
$$
\mathcal V

\left\{  
\begin{bmatrix}  
c\\  
c  
\end{bmatrix}  
:c\in\mathbb R  
\right\}.  
$$

这是一维子空间，只能表示两个状态价值相同的函数。

现在令：

$$
\gamma=0,  
$$
并令奖励为：


$$
r_\pi=  
\begin{bmatrix}  
1\\  
0  
\end{bmatrix}.  
$$
Bellman 算子变成：

$$
T_\pi v=r_\pi.  
$$
所以：


$$
T_\pi v_\theta=  
\begin{bmatrix}  
1\\  
0  
\end{bmatrix}.  
$$

但：


$$
\begin{bmatrix}  
1\\  
0  
\end{bmatrix}  
\notin  
\left\{  
\begin{bmatrix}  
c\\  
c  
\end{bmatrix}  
:c\in\mathbb R  
\right\}.  
$$
因此不存在 $\theta'$，使得：
$$
\Phi\theta'=  
\begin{bmatrix}  
1\\  
0  
\end{bmatrix}.  
$$
这说明：


$$
\boxed{  
v_\theta\in\mathcal V  
\quad\not\Rightarrow\quad  
T_\pi v_\theta\in\mathcal V.  
}  
$$


---

### 6. 为什么不能直接要求 $v_\theta=T_\pi v_\theta$？

精确 Bellman 方程是：


$$
v=T_\pi v.  
$$

在完整 tabular 空间 $\mathbb R^{|\mathcal S|}$ 中，折扣 Bellman 算子有唯一固定点：


$$
v_\pi=T_\pi v_\pi.  
$$

但是线性函数近似要求：


$$
v_\theta\in\mathcal V.  
$$

如果真值函数 $v_\pi\notin\mathcal V$，则不存在 $\theta$ 使：


$$
\Phi\theta=v_\pi.  
$$

于是也通常不存在 $\theta$ 使：


$$
\Phi\theta=T_\pi\Phi\theta.  
$$

原因不是 Bellman 方程本身不存在解，而是**解可能不在近似空间中**。

换句话说：


$$
\boxed{  
\text{完整空间中有 fixed point，但受限近似空间中未必有 exact Bellman fixed point。}  
}  
$$

所以如果直接最小化或要求：

$$
v_\theta=T_\pi v_\theta,  
$$
等价于要求一个低维子空间中的向量精确等于一个通常落在子空间外的向量。这一般不可能。

---

### 7. 几何图像：Bellman target 在空间外

可以把：

$$
\mathcal V=\operatorname{Col}(\Phi)  
$$
想成 $\mathbb R^{|\mathcal S|}$ 中的一个低维平面。

当前近似值函数：
$$
v_\theta  
$$
在这个平面上。

Bellman 更新：

$$
T_\pi v_\theta  
$$
通常落在平面外。

于是无法直接把 $v_\theta$ 调到等于 $T_\pi v_\theta$，因为 $v_\theta$ 被限制在平面上。

因此合理做法是：

1. 先计算完整 Bellman target：
   
$$
T_\pi v_\theta.  
$$
2. 把它投影回近似空间：
   
$$
\Pi T_\pi v_\theta.  
$$
3. 要求当前近似值函数等于这个投影：
   
$$
v_\theta=\Pi T_\pi v_\theta.  
$$
这就是 projected Bellman equation。

Sutton、Szepesvári 和 Maei 将 MSPBE 写成 $||V_\theta-\Pi T V_\theta||_D^2$，并说明梯度 TD 方法以该目标为基础；后续关于 generalized projected Bellman error 的论文也把 PBE 视为 Bellman error 经由某种投影得到的量。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

### 8. 投影算子 $\Pi_D$ 的定义

令 $D=\operatorname{diag}(d(s))$ 表示状态分布权重。定义 (D)-加权范数：

$$
||x||_D^2=x^\top D x

\sum_s d(s)x(s)^2.  
$$
对任意 $y\in\mathbb R^{|\mathcal S|}$，其到近似空间 $\mathcal V$ 的投影定义为：

$$
\boxed{  
\Pi_D y
=
\arg\min_{v\in\mathcal V}||y-v||_D^2.  
}  
$$

由于：


$$
v=\Phi w,  
$$

所以：


$$
\Pi_D y=\Phi w^*,  
$$

其中：
$$
w^*
=
\arg\min_w  
||y-\Phi w||_D^2.  
$$
展开目标：

$$
J(w)
=
(y-\Phi w)^\top D(y-\Phi w).  
$$
对 (w) 求导：

$$
\nabla_w J(w)
=
-2\Phi^\top D(y-\Phi w).  
$$

令梯度为 0：

$$
\Phi^\top D(y-\Phi w)=0.  
$$

得到正规方程：


$$
\Phi^\top D\Phi w=\Phi^\top D y.  
$$


若：

$$
\Phi^\top D\Phi  
$$


可逆，则：


$$
w^*
=
(\Phi^\top D\Phi)^{-1}\Phi^\top D y.  
$$


因此投影算子为：


$$
\boxed{  
\Pi_D
=
\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D.  
}  
$$


所以：


$$
\boxed{  
\Pi_D y
=
\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D y.  
}  
$$

---

### 9. Projected Bellman equation

由于 $T_\pi v_\theta$ 不一定在 $\mathcal V$ 中，因此改为要求：


$$
\boxed{  
v_\theta=\Pi_D T_\pi v_\theta.  
}  
$$

这叫 **projected Bellman equation**。

代入 $v_\theta=\Phi\theta$，得到：
$$
\boxed{  
\Phi\theta
=
\Pi_D  
\left(  
r_\pi+\gamma P_\pi\Phi\theta  
\right).  
}  
$$
它表示：
$$
\text{当前近似值函数}

\text{Bellman 更新后再投影回近似空间的函数}.  
$$
几何上，这是在近似空间内部寻找一个 fixed point：
$$
\boxed{  
v_\theta
=
(\Pi_D T_\pi)v_\theta.  
}  
$$
注意 fixed point 的算子已经不是：
$$
T_\pi,  
$$
而是：

$$
\Pi_D T_\pi.  
$$

---

### 10. Projected Bellman error

由于 projected Bellman equation 是：

$$
v_\theta=\Pi_D T_\pi v_\theta,  
$$

因此 projected Bellman error 定义为：


$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Pi_D T_\pi v_\theta-v_\theta.  
}  
$$


又因为：


$$
v_\theta\in\mathcal V,  
$$

所以：


$$
\Pi_D v_\theta=v_\theta.  
$$


因此：


$$
\begin{aligned}  
\Pi_D T_\pi v_\theta-v_\theta  
&=  
\Pi_D T_\pi v_\theta-\Pi_D v_\theta  
\\  
&=  
\Pi_D(T_\pi v_\theta-v_\theta).  
\end{aligned}  
$$


所以：


$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Pi_D(T_\pi v_\theta-v_\theta).  
}  
$$
这说明：


$$
\boxed{  
\text{projected Bellman error 是 Bellman error 在近似空间中的投影。}  
}  
$$

对应的均方目标为：


$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
 ||\Pi_D(T_\pi v_\theta-v_\theta)||_D^2
=
||\Pi_D T_\pi v_\theta-v_\theta||_D^2.  
}  
$$

---

### 11. 与 TD fixed point 的关系

线性 $TD(0)$ 的更新是：


$$
\theta_{t+1}
=
\theta_t+\alpha \delta_t\phi(S_t),  
$$
其中：

$$
\delta_t
=
 R_{t+1}  
+  
\gamma \phi(S_{t+1})^\top\theta
-
\phi(S_t)^\top\theta.  
$$

取期望：

$$
\mathbb E[\delta_t\phi(S_t)]
=
\Phi^\top D(T_\pi v_\theta-v_\theta).  
$$

TD fixed point 满足：


$$
\boxed{  
\mathbb E[\delta_t\phi(S_t)]=0.  
}  
$$

也就是：


$$
\Phi^\top D(T_\pi v_\theta-v_\theta)=0.  
$$
这表示 Bellman residual 与所有特征方向正交。

而这等价于：

$$
\boxed{  
\Pi_D(T_\pi v_\theta-v_\theta)=0.  
}  
$$
也就是：


$$
\boxed{  
v_\theta=\Pi_D T_\pi v_\theta.  
}  
$$
因此：


$$
\boxed{  
\text{线性 TD 的 fixed point 正是 projected Bellman equation 的解。}  
}  
$$

Sutton、Szepesvári 和 Maei 的 GTD 论文明确将 conventional TD 的收敛点与 projected Bellman equation / MSPBE 联系起来，并通过 MSPBE 构造真正的随机梯度 TD 方法。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

### 12. 原文中几句话的逐句解释

### 12.1 “所有可表示的值函数构成一个线性子空间”

即：

$$
\mathcal V=\{\Phi\theta:\theta\in\mathbb R^d\}.  
$$
因为任意两个可表示函数的线性组合仍然可表示：

$$
a\Phi\theta_1+b\Phi\theta_2=\Phi(a\theta_1+b\theta_2).  
$$
所以它是线性子空间。

---

### 12.2 “$T_\pi v_\theta$ 通常不在 $\mathcal V$ 中”

因为：

$$
T_\pi v_\theta
=
r_\pi+\gamma P_\pi\Phi\theta.  
$$
这个向量属于完整空间：

$$
\mathbb R^{|\mathcal S|},  
$$

但不一定能写成：

$$
\Phi\theta'.  
$$
只有在很特殊的情况下，例如：

$$
r_\pi\in\operatorname{Col}(\Phi),  
$$
并且：

$$
P_\pi\operatorname{Col}(\Phi)\subseteq\operatorname{Col}(\Phi),  
$$

才可能保证 Bellman 更新不离开近似空间。

---

### 12.3 “不能直接要求 $v_\theta=T_\pi v_\theta$”

因为左侧：

$$
v_\theta  
$$
一定在近似空间 $\mathcal V$ 中，而右侧：

$$
T_\pi v_\theta  
$$

可能在 $\mathcal V$ 外。

若右侧在空间外，则不存在任何参数 $\theta$ 可以让二者相等。

因此，精确 Bellman equation 在近似空间中通常无解。

---

### 12.4 “这就是 projected Bellman error 出现的原因”

因为不能要求：

$$
v_\theta=T_\pi v_\theta,  
$$
所以改为要求：

$$
v_\theta=\Pi_D T_\pi v_\theta.  
$$
对应误差就是：


$$
\Pi_D T_\pi v_\theta-v_\theta.  
$$

这就是 projected Bellman error。

---
### 13. 最核心总结

线性函数近似把值函数限制在：

$$
\mathcal V=\operatorname{Col}(\Phi)  
$$
中。
Bellman 算子把当前近似值函数变成：
$$
T_\pi v_\theta=r_\pi+\gamma P_\pi\Phi\theta.  
$$
但一般：

$$
T_\pi v_\theta\notin\mathcal V.  
$$
因此不能要求： 
$$
v_\theta=T_\pi v_\theta.  
$$
只能先把 Bellman 更新投影回近似空间：


$$
\Pi_D T_\pi v_\theta,  
$$
再要求：


$$
v_\theta=\Pi_D T_\pi v_\theta.  
$$

对应误差为：


$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Pi_D(T_\pi v_\theta-v_\theta).  
}  
$$

对应平方目标为：


$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
||\Pi_D(T_\pi v_\theta-v_\theta)||_D^2.  
}  
$$
一句话概括：
$$
\boxed{  
\text{Bellman error 衡量完整 Bellman 方程残差；projected Bellman error 衡量该残差在可表示函数空间中的分量。}  
}  
$$

---


---
---


# 6. Projection operator $\Pi_D$

定义 $D-加权投影$：
$$
\Pi_D y
=
\arg\min_{v\in \mathcal V}||y-v||_D^2.  
$$
$$
\mathcal V
=
\{v_\theta:\theta\in\mathbb R^d\}
=
\operatorname{span}(\Phi).  
$$
在线性函数近似下：
$$
\boxed{  
\Pi_D
=
\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D.  
}  
$$
**它把任意向量 $y\in\mathbb R^{|\mathcal S|}$ 投影到特征空间**：
$$
\mathcal V=\operatorname{span}(\Phi).  
$$
直观上：
$$
T_\pi v_\theta  
$$
可能在函数空间外，所以先把它投影回来：
$$
\Pi_D T_\pi v_\theta.  
$$
然后比较：
$$
v_\theta  
$$
和
$$
\Pi_D T_\pi v_\theta.  
$$
---

# 7. Projected Bellman error：投影 Bellman 残差

**Projected Bellman error, PBE** 定义为：
$$
\boxed{  
\mathcal B_{\Pi}(v_\theta)
=
\Pi_D T_\pi v_\theta - v_\theta.  
}  
$$
由于 $v_\theta\in\mathcal V$，有：
$$
\Pi_D v_\theta=v_\theta.  
$$
所以：
$$
\Pi_D T_\pi v_\theta-v_\theta
=
 \Pi_D T_\pi v_\theta-\Pi_D v_\theta
=
\Pi_D(T_\pi v_\theta-v_\theta).  
$$
因此：
$$
\boxed{  
\mathcal B_{\Pi}(v_\theta)
=
\Pi_D\mathcal B(v_\theta).  
}  
$$
也就是说：
$$
\boxed{  
\text{projected Bellman error 是 Bellman error 在函数近似空间中的投影。}  
}  
$$
对应的均方目标是：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
||v_\theta-\Pi_D T_\pi v_\theta||_D^2.  
}  
$$
**Sutton、Szepesvári 和 Maei 明确指出，许多算法收敛到组合算子 $\Pi T$ 的 $fixed\ point$，即 $V_\theta=\Pi T V_\theta$，并把目标函数定义为 mean-square projected Bellman error：$\mathrm{MSPBE}(\theta)=||V_\theta-\Pi T V_\theta||_D^2$。**(https://icml.cc/Conferences/2009/papers/546.pdf)

---
# 8. TD fixed point 与 projected Bellman equation

Projected Bellman equation 是：
$$
\boxed{  
v_\theta
=
\Pi_D T_\pi v_\theta.  
}  
$$
等价地：
$$
\boxed{  
\Pi_D(T_\pi v_\theta-v_\theta)=0.  
}  
$$
这就是：
$$
\boxed{  
\mathcal B_{\Pi}(v_\theta)=0.  
}  
$$
满足这个方程的参数称为 TD fixed point。

与真正 Bellman equation 相比：
$$
v=T_\pi v  
$$
**projected Bellman equation 只要求 Bellman 更新在投影回函数空间后与当前近似值函数一致。**

几何上：

- **Bellman equation 要求 $v$ 与 $Tv$ 完全相同**；
  
- **projected Bellman equation 要求 $v$ 与 $Tv$ 在函数近似空间中的投影相同**。
  

---

# 9. MSBE 与 MSPBE 的几何区别

设：
$$
v_\theta\in\mathcal V.  
$$
Bellman update 后：
$$
T_\pi v_\theta  
$$
通常在 $\mathcal V$ 外。

MSBE 衡量：
$$
\boxed{  
||T_\pi v_\theta-v_\theta||_D^2.  
}  
$$
这是从 $v_\theta$ 到完整 Bellman target $T_\pi v_\theta$ 的距离。

MSPBE 衡量：
$$
\boxed{  
||\Pi_D T_\pi v_\theta-v_\theta||_D^2.  
}  
$$
这是从 $v_\theta$ 到投影后的 Bellman target 的距离。
因此：
$$
\boxed{  
\mathrm{MSBE}  
\text{ 看完整 Bellman residual；}  
}  
$$
$$
\boxed{  
\mathrm{MSPBE}  
\text{ 只看函数近似空间内可表达的 Bellman residual 分量。}  
}  
$$
Sutton 等人的论文中用图示比较了 RMSBE 和 RMSPBE 的几何关系，并把二者分别作为不同 Bellman-error objective functions 来讨论。(https://icml.cc/Conferences/2009/papers/546.pdf)

---
# 10. MSPBE 与 expected TD update 的代数关系

令：
$$
v_\theta=\Phi\theta.  
$$
定义 **Bellman residual**：
$$
b_\theta
=
T_\pi v_\theta-v_\theta.  
$$
则 projected Bellman error 为：
$$
\Pi_D b_\theta.  
$$
MSPBE 为：
$$
\mathrm{MSPBE}(\theta)
=
||\Pi_D b_\theta||_D^2.  
$$
代入投影矩阵：
$$
\Pi_D
=
\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D.  
$$
令：
$$
C=\Phi^\top D\Phi.  
$$
则：
$$
\begin{aligned}  
\mathrm{MSPBE}(\theta)  
&=  
b_\theta^\top D\Phi  
(\Phi^\top D\Phi)^{-1}  
\Phi^\top D b_\theta  
\\  
&=  
(\Phi^\top D b_\theta)^\top  
C^{-1}  
(\Phi^\top D b_\theta).  
\end{aligned}  
$$
定义：
$$
g(\theta)
=
\Phi^\top D  
(T_\pi v_\theta-v_\theta).  
$$
于是：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
g(\theta)^\top C^{-1}g(\theta).  
}  
$$
而：
$$
g(\theta)
=
\mathbb E[\delta_t(\theta)\phi(S_t)].  
$$
证明如下：
$$
\begin{aligned}  
\mathbb E[\delta_t\phi(S_t)]  
&=  
\sum_s d(s)\phi(s)  
\mathbb E[\delta_t\mid S_t=s]  
\\  
&=  
\sum_s d(s)\phi(s)  
\left[  
(T_\pi v_\theta)(s)-v_\theta(s)  
\right]  
\\  
&=  
\Phi^\top D(T_\pi v_\theta-v_\theta)  
\\  
&=  
g(\theta).  
\end{aligned}  
$$
所以：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta\phi]^\top  
(\mathbb E[\phi\phi^\top])^{-1}  
\mathbb E[\delta\phi].  
}  
$$
Sutton 等人的 GTD/TDC 论文给出同样关系：$\mathbb E[\delta\phi]=\Phi^\top D(TV_\theta-V_\theta)$，并以 MSPBE 为梯度TD方法的目标函数。(https://icml.cc/Conferences/2009/papers/546.pdf)

---

# 11. TD-error 与 projected Bellman error 的关系

TD-error 是：
$$
\delta_t
=
 R_{t+1}  
+  
\gamma v_\theta(S_{t+1})
-
v_\theta(S_t).  
$$
**它本身是一个标量随机样本。**

但 TD 更新不是直接令：
$$
\delta_t=0.  
$$

线性 $TD(0)$ 的更新方向是：
$$
\Delta\theta_t
=
\alpha\delta_t\phi(S_t).  
$$

取期望：
$$
\mathbb E[\Delta\theta_t]/\alpha
=
 \mathbb E[\delta_t\phi(S_t)]

\Phi^\top D(T_\pi v_\theta-v_\theta).  
$$
TD fixed point 满足：
$$
\boxed{  
\mathbb E[\delta_t\phi(S_t)]=0.  
}  
$$
这等价于：
$$
\Phi^\top D(T_\pi v_\theta-v_\theta)=0.  
$$
**由于 $T_\pi v_\theta-v_\theta$ 与所有特征方向正交，说明 Bellman residual 在函数近似空间中的投影为 0：**
$$
\Pi_D(T_\pi v_\theta-v_\theta)=0.  
$$
因此：
$$
\boxed{  
\mathbb E[\delta\phi]=0  
\Longleftrightarrow  
\mathrm{MSPBE}(\theta)=0  
\Longleftrightarrow  
v_\theta=\Pi_D T_\pi v_\theta.  
}  
$$
**这解释了为什么普通 TD 与 projected Bellman equation 密切相关：TD 更新的期望方向正是投影 Bellman residual 的特征坐标形式。**

---

# 12. 三者的核心区别

| 概念                      | 数学对象               |   是否随机 | 是否依赖函数近似投影 | 典型形式                                        |
| ----------------------- | ------------------ | -----: | ---------: | ------------------------------------------- |
| TD-error                | 单个 transition 上的误差 |      是 |          否 | $\delta_t=R_{t+1}+\gamma V(S_{t+1})-V(S_t)$ |
| Bellman error           | Bellman 方程残差       | 否，是期望量 |          否 | $T_\pi v-v$                                 |
| projected Bellman error | 投影后的 Bellman 残差    | 否，是期望量 |          是 | $\Pi_D (T_\pi v_\theta-v_\theta)$           |

更简洁地：
$$
\boxed{  
\text{TD-error 是样本级误差。}  
}  
$$
$$
\boxed{  
\text{Bellman error 是期望 Bellman 方程残差。}  
}  
$$
$$
\boxed{  
\text{projected Bellman error 是函数近似空间中的 Bellman 方程残差。}  
}  
$$
---

# 13. 为什么 Bellman error 不是 value error？

还需要区分：
$$
\text{Bellman error}  
$$
和
$$
\text{value error}.  
$$
value error 是：
$$
v-v_\pi.  
$$
Bellman error 是：
$$
T_\pi v-v.  
$$
由于：
$$
T_\pi v_\pi=v_\pi,  
$$
有：
$$
\begin{aligned}  
T_\pi v-v  
&=  
r+\gamma P_\pi v-v  
\\  
&=  
r+\gamma P_\pi(v_\pi+\Delta)-(v_\pi+\Delta)  
\\  
&=  
r+\gamma P_\pi v_\pi-v_\pi  
+  
\gamma P_\pi\Delta-\Delta  
\\  
&=  
\gamma P_\pi\Delta-\Delta,  
\end{aligned}  
$$
其中：
$$
\Delta=v-v_\pi.  
$$
所以：
$$
\boxed{  
\mathcal B(v)
=
-(I-\gamma P_\pi)(v-v_\pi).  
}  
$$
**也就是说，Bellman error 是 value error 经过线性算子 $-(I-\gamma P_\pi)$ 变换后的量。**
**Bellman error 为 0 意味着 value error 为 0；但 Bellman error 的大小不一定可靠反映 value error 的大小。**
Fujimoto 等人指出，Bellman error 作为 value prediction accuracy 的替代指标可能很差：**Bellman 方程两侧的误差可能发生抵消，有限数据中甚至可能存在许多低 Bellman error 但低准确性的解。**(https://proceedings.mlr.press/v162/fujimoto22a/fujimoto22a.pdf)

---

# 14. 一个小例子：TD-error 与 Bellman error 的差别

假设某状态 $s$ 有两个可能后继状态：
$$
s_1',s_2',  
$$
概率各为：
$$
\frac12.  
$$
奖励都为 0。当前估计满足：
$$
V(s)=0,  
$$
$$
V(s_1')=1,  
\qquad  
V(s_2')=-1,  
$$
且：
$$
\gamma=1.  
$$
那么 Bellman error 为：
$$
\mathcal B(V)(s)
=
 0+\frac12 V(s_1')+\frac12V(s_2')-V(s)
=
 \frac12(1)+\frac12(-1)-0
$$
但单个样本 TD-error 是：

若采样到 $s_1'$：
$$
\delta=1.  
$$
若采样到 $s_2'$：
$$
\delta=-1.  
$$
所以：
$$
\mathbb E[\delta\mid s]=0,  
$$
但：
$$
\mathbb E[\delta^2\mid s]=1.  
$$
因此：
$$
\boxed{  
\text{Bellman error 可以为 0，但 squared TD-error 不为 0。}  
}  
$$
**这正是“期望误差”和“单样本平方误差”的区别。**

---

# 15. Bellman error、projected Bellman error、TD-error 的关系图

可以用以下链条理解：
$$
\delta_t
=
 R_{t+1}  
+  
\gamma v(S_{t+1})
-
v(S_t)  
$$
是样本级随机量。

**对 $S_t=s$ 条件取期望**：
$$
\mathbb E[\delta_t\mid S_t=s]
=
(T_\pi v)(s)-v(s)  
$$
**得到 Bellman error。**

**再把 Bellman error 投影到函数近似空间：**
**$$\Pi_D(T_\pi v_\theta-v_\theta)$$**
**得到 projected Bellman error。**

**乘上特征并对样本取期望：**
$$
\mathbb E[\delta_t\phi(S_t)]
=
\Phi^\top D(T_\pi v_\theta-v_\theta)  
$$
**得到 TD 更新的期望方向。**

所以：
$$
\boxed{  
\text{TD-error}  
\ \xrightarrow{\text{条件期望}}\  
\text{Bellman error}  
\ \xrightarrow{\text{投影}}\  
\text{projected Bellman error}.  
}  
$$

---

# 16. 总结
**Bellman error**：
$$
\boxed{  
\mathcal B(v)=T_\pi v-v.  
}  
$$
**表示值函数是否满足 Bellman 方程。若全状态 Bellman error 为 0，则 $v=v_\pi$。**

**TD-error**：
$$
\boxed{  
\delta_t=R_{t+1}+\gamma V(S_{t+1})-V(S_t).  
}  
$$
**表示单个样本 transition 上的瞬时 Bellman 残差。其条件期望等于 Bellman error：**
$$
\boxed{  
\mathbb E[\delta_t\mid S_t=s]
=
\mathcal B(V)(s).  
}  
$$
**Projected Bellman error**：
$$
\boxed{  
\mathcal B_\Pi(v_\theta)
=
 \Pi_D T_\pi v_\theta-v_\theta
=
\Pi_D(T_\pi v_\theta-v_\theta).  
}  
$$
表示在函数近似空间中，当前近似值函数与投影 Bellman 更新之间的差异。对应目标：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
||v_\theta-\Pi_D T_\pi v_\theta||_D^2.  
}  
$$
在线性函数逼近下：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta\phi]^\top  
\mathbb E[\phi\phi^\top]^{-1}  
\mathbb E[\delta\phi].  
}  
$$
最终关系可以压缩成一句话：
$$
\boxed{  
\text{TD-error 是样本级 Bellman 残差；Bellman error 是其条件期望；projected Bellman error 是 Bellman 残差在函数近似空间中的投影。}  
}  
$$


---

后面的关键数学点有两个：
- **第一，$\delta_t$ 的条件期望才是 Bellman error，而 $\delta_t^2$的期望不是 MSBE；**
- **第二，线性 TD 的期望更新方向等价于 projected Bellman error 的特征坐标形式。**
下面给出一个统一、严格的解释。默认讨论**固定策略 $\pi$ 下的 policy evaluation**，即估计 $v_\pi$。这样最容易看清三者关系：
$$
\boxed{  
\text{TD-error 是样本级误差；Bellman error 是期望 Bellman 残差；projected Bellman error 是 Bellman 残差在函数近似空间中的投影。}  
}  
$$

 **projected Bellman error**，对应目标函数常称 **MSPBE**：mean squared projected Bellman error。Sutton、Szepesvári、Maei 在 GTD/TDC 论文中正是围绕 MSBE、MSPBE 与 TD 期望更新之间的关系建立梯度 TD 方法。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

# 1. 基本设定：Bellman operator

给定 MDP：
$$
(\mathcal S,\mathcal A,P,R,\gamma),  
\qquad 0\le \gamma<1.  
$$
固定策略 $\pi$。策略 $\pi$ 诱导状态转移矩阵：
$$
P_\pi(s'|s)=
\sum_a \pi(a|s)P(s'|s,a).  
$$
策略下的期望即时奖励为：
$$
r_\pi(s)
=
\mathbb E_\pi[R_{t+1}\mid S_t=s].  
$$
价值函数定义为：
$$
v_\pi(s)
=
\mathbb E_\pi  
\left[  
\sum_{k=0}^{\infty}\gamma^kR_{t+k+1}  
\mid S_t=s  
\right].  
$$
**Bellman operator** 定义为：
$$
(T_\pi v)(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)v(s').  
$$
向量形式为：
$$
T_\pi v
=
r_\pi+\gamma P_\pi v.  
$$
真实价值函数满足 Bellman 方程：
$$
\boxed{  
v_\pi=T_\pi v_\pi.  
}  
$$
也就是：
$$
v_\pi

r_\pi+\gamma P_\pi v_\pi.  
$$
因此：
$$
(I-\gamma P_\pi)v_\pi=r_\pi,  
$$
$$
\boxed{  
v_\pi=(I-\gamma P_\pi)^{-1}r_\pi.  
}  
$$
在 $\gamma<1$ 时，$T_\pi$ 是压缩映射，Bellman 方程有唯一固定点；这也是 Bellman error 作为“方程残差”的基础。Sutton 与 Barto 的教材将 TD error 写作 $R_{t+1}+\gamma V(S_{t+1})-V(S_t)$，并以 Bellman 方程为 TD 学习的基本依据。([Stanford University](https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf?utm_source=chatgpt.com "Reinforcement Learning: An Introduction"))

---

# 2. Bellman error：Bellman 方程残差

给定任意近似价值函数 $v$，**Bellman error** 定义为：
$$
\boxed{  
\mathcal B(v)=T_\pi v-v.  
}  
$$
逐状态写为：
$$
\boxed{  
\mathcal B(v)(s)
=
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s')
-
v(s).  
}  
$$
如果：
$$
\mathcal B(v)=0,  
$$
则：
$$
T_\pi v-v=0,  
$$
也就是：
$$
v=T_\pi v.  
$$
由于 Bellman 方程固定点唯一，所以：
$$
\boxed{  
\mathcal B(v)=0  
\Longleftrightarrow  
v=v_\pi.  
}  
$$
**==因此，Bellman error 衡量的是：==**
$$
\boxed{  
\text{当前价值函数 }v\text{ 是否满足 Bellman 方程。}  
}  
$$
常见标量目标是 **mean squared Bellman error, MSBE**：
$$
\boxed{  
\mathrm{MSBE}(v)
=
||T_\pi v-v||_D^2.  
}  
$$
其中 $D=\operatorname{diag}(d(s))$ 是某个状态分布对应的对角矩阵，定义：
$$
||x||_D^2
=
 x^\top D x
=
\sum_s d(s)x(s)^2.  
$$
所以：
$$
\mathrm{MSBE}(v)
=
\sum_s d(s)  
\left[  
r_\pi(s)+\gamma\sum_{s'}P_\pi(s'|s)v(s')-v(s)  
\right]^2.  
$$
Sutton、Szepesvári、Maei 将 MSBE 写作 $||V_\theta-TV_\theta||_D^2$，并将其与 MSPBE 和 TD 更新方向进行区分。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

# 3. Bellman error 与 value error 的关系

value error 是：
$$
v-v_\pi.  
$$
Bellman error 是：
$$
T_\pi v-v=r_\pi+\gamma P_\pi v -v.  
$$
二者不是同一个量，但存在严格关系。令：
$$
\Delta=v-v_\pi.  
$$
**因为：**
$$
T_\pi v=r_\pi+\gamma P_\pi v,  
$$
$$
T_\pi v_\pi=r_\pi+\gamma P_\pi v_\pi=v_\pi.  
$$
于是：
$$
\begin{aligned}  
\mathcal B(v)  
&=  
T_\pi v-v  
\\  
&=  
r_\pi+\gamma P_\pi v-v  
\\  
&=  
r_\pi+\gamma P_\pi(v_\pi+\Delta)-(v_\pi+\Delta)  
\\  
&=  
r_\pi+\gamma P_\pi v_\pi-v_\pi  
+  
\gamma P_\pi\Delta-\Delta  
\\  
&=  
\gamma P_\pi\Delta-\Delta  
\\  
&=  
-(I-\gamma P_\pi)\Delta.  
\end{aligned}  
$$
因此：
$$
\boxed{  
\mathcal B(v)
=
-(I-\gamma P_\pi)(v-v_\pi).  
}  
$$
等价地：
$$
\boxed{  
v-v_\pi
=
-(I-\gamma P_\pi)^{-1}\mathcal B(v).  
}  
$$
所以 Bellman error 为 0 一定意味着 value error 为 0。

**但是，Bellman error 的大小不总是可靠反映 value error 的大小，尤其在函数近似、离策略数据、有限数据下更明显。** **Fujimoto 等人的论文专门指出，Bellman error 可能是较差的 value prediction accuracy 指标，低 Bellman error 不必然意味着低 value error。**([Proceedings of Machine Learning Research](https://proceedings.mlr.press/v162/fujimoto22a/fujimoto22a.pdf?utm_source=chatgpt.com "Why Should I Trust You, Bellman? The Bellman Error is a Poor ..."))

---

# 4. TD-error：单样本 Bellman 残差

TD-error 定义为：
$$
\boxed{  
\delta_t
=
 R_{t+1}  
+  
\gamma V(S_{t+1})
-
V(S_t).  
}  
$$
如果使用参数化价值函数 $v_\theta$，则：
$$
\boxed{  
\delta_t(\theta)
=
 R_{t+1}  
+  
\gamma v_\theta(S_{t+1})
-
v_\theta(S_t).  
}  
$$
TD-error 是**单个 transition** 上的随机量：
$$
(S_t,R_{t+1},S_{t+1}).  
$$
**Bellman error 是对下一状态和奖励随机性的==期望==之后得到的量。**

对 $S_t=s$ 条件取期望：
$$
\begin{aligned}  
\mathbb E[\delta_t\mid S_t=s]  
&=  
\mathbb E[  
R_{t+1}  
+
\gamma V(S_{t+1})
-
 V(S_t)  
\mid S_t=s]  
\\  
&=  
\mathbb E[R_{t+1}\mid S_t=s]  
+
\gamma  
\mathbb E[V(S_{t+1})\mid S_t=s]
-
V(s)  
\\  
&=  
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)V(s')
-
V(s)  
\\  
&=  
(T_\pi V)(s)-V(s)  
\\  
&=  
\mathcal B(V)(s).  
\end{aligned}  
$$
因此：
$$
\boxed{  
\mathbb E[\delta_t\mid S_t=s]
=
\mathcal B(V)(s).  
}  
$$
这说明：
$$
\boxed{  
\text{TD-error 是 Bellman error 的单样本随机估计。}  
}  
$$
Feng 等人的 Bellman equation 论文也明确指出，采样 Bellman target 与当前估计之差就是 temporal-difference 或 TD error，其期望是 Bellman error。([realworld-sdm.github.io](https://realworld-sdm.github.io/paper/36.pdf?utm_source=chatgpt.com "A Kernel Loss for Solving the Bellman Equation"))

---

# 5. 重要区别：$\mathbb E[\delta^2]$ 不是 MSBE

容易混淆的是：
$$
\mathbb E[\delta_t^2]  
$$
和：
$$
\mathrm{MSBE}(V)
=
\mathbb E_{S\sim d}  
\left[  
\left(  
\mathbb E[\delta_t\mid S_t=S]  
\right)^2  
\right].  
$$
二者不相同。

由**条件方差**分解：
$$
\mathbb E[\delta_t^2\mid S_t=s]
=
\left(  
\mathbb E[\delta_t\mid S_t=s]  
\right)^2  
+
\operatorname{Var}(\delta_t\mid S_t=s).  
$$
对 $S_t\sim d$ 取期望：
$$
\begin{aligned}  
\mathbb E[\delta_t^2]  
&=  
\mathbb E_{S\sim d}  
\left[  
\left(  
\mathbb E[\delta_t\mid S_t=S]  
\right)^2  
\right]  
+
\mathbb E_{S\sim d}  
\left[  
\operatorname{Var}(\delta_t\mid S_t=S)  
\right]  
\\  
&=  
\mathrm{MSBE}(V)  
+
\mathbb E_{S\sim d}  
\left[  
\operatorname{Var}(\delta_t\mid S_t=S)  
\right].  
\end{aligned}  
$$
所以：
$$
\boxed{  
\mathbb E[\delta_t^2]
=
\mathrm{MSBE}(V)  
+
\text{transition/reward noise}.  
}  
$$
因此：
$$
\boxed{  
\text{最小化 squared TD-error 不等价于最小化 MSBE。}  
}  
$$
这也是 Bellman residual minimization 在 model-free setting 中会遇到困难的根源之一。**Bellman residual 的随机梯度估计通常需要“double sampling”：同一状态下需要两个独立的下一状态样本**；
Zhu 和 Ying 的 PMLR 论文明确指出，model-free Bellman residual minimization 的主要挑战是 double sampling problem，即只给一个下一状态样本时，无法构造无偏 SGD 梯度。([Proceedings of Machine Learning Research](https://proceedings.mlr.press/v107/zhu20a.html?utm_source=chatgpt.com "An Attempt to Address Double Sampling"))

---

# 6. 用例子说明 TD-error 与 Bellman error 的区别

设某状态 $s$ 的奖励恒为 0，有两个后继状态：
$$
P(s_1'|s)=\frac12,  
\qquad  
P(s_2'|s)=\frac12.  
$$
设：
$$
V(s)=0,  
$$
$$
V(s_1')=1,  
\qquad  
V(s_2')=-1,  
$$
并令：
$$
\gamma=1.  
$$
Bellman error 为：
$$
\begin{aligned}  
\mathcal B(V)(s)  
&=  
0+  
\frac12V(s_1')  
+
\frac12V(s_2')
-
V(s)  
\\  
&=  
\frac12(1)+\frac12(-1)-0  
\\  
&=  
0.  
\end{aligned}  
$$
但是单样本 TD-error 为：
若采样到 $s_1'$：
$$
\delta=1.  
$$
若采样到 $s_2'$：
$$
\delta=-1.  
$$
所以：
$$
\mathbb E[\delta\mid s]=0,  
$$
但：
$$
\mathbb E[\delta^2\mid s]=1.  
$$
因此：
$$
\boxed{  
\text{Bellman error 可以为 0，但 squared TD-error 仍然大于 0。}  
}  
$$
根本原因是：**Bellman error 是条件均值(期望)，TD-error 是含有环境随机性的样本量**。

---

# 7. 函数近似空间：为什么需要 projected Bellman error

现在考虑线性函数近似：
$$
v_\theta(s)=\phi(s)^\top\theta.  
$$
令特征矩阵(state embeding)为：
$$
\Phi
=
\begin{bmatrix}  
\phi(s_1)^\top\\  
\phi(s_2)^\top\\  
\vdots\\  
\phi(s_{|\mathcal S|})^\top  
\end{bmatrix}.  
$$
于是：
$$
v_\theta=\Phi\theta.  
$$
**所有可表示的价值函数构成一个线性子空间**：(由$\Phi$线性表示)
$$
\mathcal V
=
 \{ \Phi\theta:\theta\in\mathbb R^d\}
=
\operatorname{span}(\Phi).  
$$
问题在于，即使：
$$
v_\theta\in \mathcal V,  
$$
==Bellman 更新(PE)：
$$
T_\pi v_\theta
=
r_\pi+\gamma P_\pi\Phi\theta  
$$
通常不在 $\mathcal V$ 中。==

也就是说：
$$
T_\pi v_\theta  
\notin \operatorname{span}(\Phi)  
$$
通常成立。

因此，不能期待在线性函数近似空间中找到精确满足：
$$
v_\theta=T_\pi v_\theta  
$$
的解。

==更自然的要求是：
$$
T_\pi v_\theta  
$$
投影回函数近似空间后与 $v_\theta$ 一致。==

这就得到 projected Bellman equation。

---
# 8. 投影算子 $\Pi_D$ 的推导

给定任意向量 $y\in\mathbb R^{|\mathcal S|}$，希望找到函数近似空间中最接近 $y$ 的向量(向$span\{\Phi\}$做投影)：
$$
\Pi_D y
=
\arg\min_{\hat v\in\mathcal V}||y-\hat v||_D^2.  
$$
**其中 $D=\operatorname{diag}(d(s))$ 是某个状态分布对应的对角矩阵。**
因为 $\hat v=\Phi w$，等价于求：
$$
w^*
=
\arg\min_w  
(y-\Phi w)^\top D(y-\Phi w).  
$$
对 $w$ 求导：
$$
\nabla_w  
(y-\Phi w)^\top D(y-\Phi w)
=
-2\Phi^\top D(y-\Phi w).  
$$
令导数为 0：
$$
\Phi^\top D(y-\Phi w)=0.  
$$
即：
$$
\Phi^\top D y-\Phi^\top D\Phi w=0.  
$$
所以：
$$
\Phi^\top D\Phi w=\Phi^\top D y.  
$$
若：
$$
C=\Phi^\top D\Phi  
$$
可逆，则：
$$
w^*
=
(\Phi^\top D\Phi)^{-1}\Phi^\top D y.  
$$
因此：
$$
\Pi_D y
=
 \Phi w^*
=
\{\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D\} y.  
$$
所以投影矩阵为：
$$
\boxed{  
\Pi_D
=
\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D.  
}  
$$
这个投影是 **D-加权内积下的正交投影**。

---

# 9. Projected Bellman error：投影 Bellman 残差

Projected Bellman equation 是：
$$
\boxed{  
v_\theta=\Pi_D T_\pi v_\theta.  
}  
$$
因此 **projected Bellman error** 定义为：
$$
\boxed{  
\mathcal B_\Pi(v_\theta)
=
\Pi_D T_\pi v_\theta-v_\theta.  
}  
$$
由于 $v_\theta\in\operatorname{span}(\Phi)$，有：
$$
\Pi_D v_\theta=v_\theta.  
$$
所以：
$$
\begin{aligned}  
\mathcal B_\Pi(v_\theta)  
&=  
\Pi_D T_\pi v_\theta-v_\theta  
\\  
&=  
\Pi_D T_\pi v_\theta-\Pi_D v_\theta  
\\  
&=  
\Pi_D(T_\pi v_\theta-v_\theta).  
\end{aligned}  
$$
因此：
$$
\boxed{  
\mathcal B_\Pi(v_\theta)
=
\Pi_D\mathcal B(v_\theta).  
}  
$$
**这就是名称中的 “projected” 的含义：**
$$
\boxed{  
\text{projected Bellman error 是 Bellman error 在函数近似空间中的投影。}  
}  
$$
对应均方目标是：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
||v_\theta-\Pi_D T_\pi v_\theta||_D^2.  
}  
$$
Sutton、Szepesvári、Maei 明确将许多TD方法的收敛点解释为 $\Pi T$ 的 fixed point，即 $V_\theta=\Pi T V_\theta$，并将 $||V_\theta-\Pi T V_\theta||_D^2$ 定义为 mean-square projected Bellman error。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

# 10. MSBE 与 MSPBE 的几何区别

**Bellman error**：
$$
T_\pi v_\theta-v_\theta.  
$$
**Projected Bellman error**：
$$
\Pi_D(T_\pi v_\theta-v_\theta).  
$$
所以：
$$
\mathrm{MSBE}(\theta)
=
||T_\pi v_\theta-v_\theta||_D^2.  
$$
而：
$$
\mathrm{MSPBE}(\theta)
=
||\Pi_D(T_\pi v_\theta-v_\theta)||_D^2.  
$$
几何上：
- **MSBE 衡量完整 Bellman residual；**
- **MSPBE 只衡量 Bellman residual 在函数近似空间 $\operatorname{span}(\Phi)$ 中的分量；**
- **Bellman residual 中垂直于函数空间的部分，MSPBE 不惩罚。**
因此：
$$
\boxed{  
\mathrm{MSPBE}(\theta)=0  
}  
$$
不一定意味着：
$$
\boxed{  
\mathrm{MSBE}(\theta)=0.  
}  
$$
它只意味着：
$$
\Pi_D(T_\pi v_\theta-v_\theta)=0.  
$$
**即 Bellman residual 与特征空间正交。**

**这正是函数近似情形下 TD fixed point 的含义：==不是完全满足 Bellman 方程，而是满足 projected Bellman equation。==**

---
# 11. MSPBE 的代数推导
令：
$$
v_\theta=\Phi\theta.  
$$
定义 Bellman residual：
$$
b_\theta
=
T_\pi v_\theta-v_\theta.  
$$
也就是：
$$
b_\theta
=
r_\pi+\gamma P_\pi\Phi\theta-\Phi\theta.  
$$
Projected Bellman error：
$$
\Pi_D b_\theta.  
$$
MSPBE：
$$
\mathrm{MSPBE}(\theta)
=
||\Pi_D b_\theta||_D^2.  
$$
由投影矩阵：
$$
\Pi_D
=
\Phi C^{-1}\Phi^\top D,  
\qquad  
C=\Phi^\top D\Phi.  
$$
有：
$$
\Pi_D b_\theta
=
\Phi C^{-1}\Phi^\top D b_\theta.  
$$
于是：
$$
\begin{aligned}  
\mathrm{MSPBE}(\theta)  
&=  
(\Pi_D b_\theta)^\top D(\Pi_D b_\theta)  
\\  
&=  
\left(  
\Phi C^{-1}\Phi^\top D b_\theta  
\right)^\top  
D  
\left(  
\Phi C^{-1}\Phi^\top D b_\theta  
\right)  
\\  
&=  
b_\theta^\top D\Phi C^{-1}  
\Phi^\top D\Phi  
C^{-1}\Phi^\top D b_\theta  
\\  
&=  
b_\theta^\top D\Phi C^{-1}  
C  
C^{-1}\Phi^\top D b_\theta  
\\  
&=  
b_\theta^\top D\Phi C^{-1}\Phi^\top D b_\theta.  
\end{aligned}  
$$
令：
$$
g(\theta)=\Phi^\top D b_\theta.  
$$
则：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
g(\theta)^\top C^{-1}g(\theta).  
}  
$$
这一步很重要，因为：
$$
g(\theta)  
$$
**恰好等于 TD 更新的期望方向**。
$$
\begin{aligned}  
\mathbb E[\delta_t\phi(S_t)]  
&=  
\sum_s d(s)\phi(s)  
\mathbb E[\delta_t\mid S_t=s]  
\\  
&=  
\sum_s d(s)\phi(s)  
\left[  
(T_\pi v_\theta)(s)-v_\theta(s)  
\right]  
\\  
&=  
\Phi^\top D(T_\pi v_\theta-v_\theta)  
\\  
&=  
\Phi^\top D b_\theta  
\\  
&=  
g(\theta).  
\end{aligned}  
$$
---
# 12. $\mathbb E[\delta\phi]$ 与 $projected\ Bellman\ error$ 的关系
线性函数近似下：
$$
v_\theta(s)=\phi(s)^\top\theta.  
$$
其中：
$$
\nabla v_\theta=\phi
$$
TD-error 为：
$$
\delta_t(\theta)
=
 R_{t+1}  
+
\gamma \phi(S_{t+1})^\top\theta
-
\phi(S_t)^\top\theta.  
$$
**考虑 $TD(0)$ 更新：**
$$
\theta_{t+1}
=
\theta_t+\alpha\delta_t\phi(S_t).  
$$
**其期望更新方向为**：
$$
\mathbb E[\delta_t\phi(S_t)].  
$$
推导：
$$
\begin{aligned}  
\mathbb E[\delta_t\phi(S_t)]  
&=  
\sum_s d(s)\phi(s)  
\mathbb E[\delta_t\mid S_t=s]  
\\  
&=  
\sum_s d(s)\phi(s)  
\left[  
(T_\pi v_\theta)(s)-v_\theta(s)  
\right]  
\\  
&=  
\Phi^\top D(T_\pi v_\theta-v_\theta)  
\\  
&=  
\Phi^\top D b_\theta  
\\  
&=  
g(\theta).  
\end{aligned}  
$$
**其中 $D=\operatorname{diag}(d(s))$ 是某个状态分布（如stationary distribution）对应的对角矩阵。** 因此：
$$
\boxed{  
\mathbb E[\delta_t\phi(S_t)]
=
 g(\theta)
=
\Phi^\top D(T_\pi v_\theta-v_\theta).  
}  
$$
代入 MSPBE 表达式：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta\phi]^\top  
C^{-1}  
\mathbb E[\delta\phi].  
}  
$$
其中：
$$
C=\mathbb E[\phi(S_t)\phi(S_t)^\top].  
$$
所以：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta\phi]^\top  
\left(  
\mathbb E[\phi\phi^\top]  
\right)^{-1}  
\mathbb E[\delta\phi].  
}  
$$
这就是 TD-error 与 projected Bellman error 之间最重要的数学联系。Sutton、Szepesvári、Maei 的 GTD/TDC 论文正是利用该结构，**构造真正对 MSPBE 做随机梯度下降的算法**。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---
# 13. TD fixed point：为什么普通 TD 对应 **projected Bellman equation**
普通线性 $TD(0)$ 的期望更新为：
$$
\mathbb E[\Delta\theta]
=
\alpha\mathbb E[\delta\phi].  
$$
**若算法收敛到某个固定点 $\theta_{\mathrm{TD}}$，则期望更新为 0**：
$$
\boxed{  
\mathbb E[\delta\phi]=0.  
}  
$$
等价于：
$$
\Phi^\top D(T_\pi v_\theta-v_\theta)=0.  
$$
这表示 **Bellman residual**：
$$
T_\pi v_\theta-v_\theta  
$$
**与所有特征方向在 D-内积下正交**（向量垂直于平面$span\{\Phi\}$）。
也就是：
$$
\Pi_D(T_\pi v_\theta-v_\theta)=0.  
$$
所以：
$$
\boxed{  
v_\theta=\Pi_D T_\pi v_\theta.  
}  
$$
因此：
$$
\boxed{  
\text{普通线性 TD 的 fixed point 是 projected Bellman equation 的解。}  
}  
$$
**这也解释了为什么 TD 通常不直接最小化 MSBE，而是求解一个投影 Bellman 固定点**。 Sutton 等人的论文也将 conventional TD 的收敛点与 projected Bellman equation 联系起来，并指出 gradient TD 方法将 MSPBE 作为显式目标。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

# 14. **为什么普通 TD 不是 MSBE 的梯度下降？**

MSBE 为：
$$
\mathrm{MSBE}(\theta)
=
||T_\pi v_\theta-v_\theta||_D^2.  
$$
令：
$$
b_\theta=T_\pi v_\theta-v_\theta.  
$$
线性情况下：
$$
b_\theta
=
 r_\pi+\gamma P_\pi\Phi\theta-\Phi\theta
=
r_\pi-(\Phi-\gamma P_\pi\Phi)\theta.  
$$
对 $\theta$ 求梯度：
$$
\nabla_\theta \mathrm{MSBE}(\theta)
=
2(\gamma P_\pi\Phi-\Phi)^\top D b_\theta.  
$$
或者写成：
$$
\nabla_\theta \mathrm{MSBE}(\theta)
=
-2(\Phi-\gamma P_\pi\Phi)^\top D(T_\pi v_\theta-v_\theta).  
$$
而 $TD(0)$ 的期望更新方向是：
$$
\mathbb E[\delta\phi]
=
\Phi^\top D(T_\pi v_\theta-v_\theta).  
$$
两者不同：
$$
\Phi^\top D b_\theta  
\neq  
(\Phi-\gamma P_\pi\Phi)^\top D b_\theta.  
$$
所以：
$$
\boxed{  
\text{普通 TD(0) 不是 MSBE 的梯度下降。}  
}  
$$
**它的期望更新只使用当前状态特征 $\phi(S_t)$，而 MSBE 梯度还涉及 Bellman target 对参数的导数，即下一状态特征项 $\gamma\phi(S_{t+1})$ 的期望。**

---

# 15. 为什么 MSBE 梯度估计有 double-sampling 问题？

MSBE 是：
$$
\mathrm{MSBE}(\theta)
=
\mathbb E_S  
\left[  
\left(  
\mathbb E[\delta_t(\theta)\mid S_t=S]  
\right)^2  
\right].  
$$
对 $\theta$ 求梯度会出现：
$$
\nabla_\theta  
\left(  
\mathbb E[\delta\mid S=s]  
\right)^2
=
2  
\mathbb E[\delta\mid S=s]  
\nabla_\theta  
\mathbb E[\delta\mid S=s].  
$$
也就是需要估计两个条件期望的乘积：
$$
\mathbb E[\delta\mid s]  
\cdot  
\mathbb E[\nabla_\theta \delta\mid s].  
$$
一个单样本 transition 给出的是：
$$
\delta  
\nabla_\theta\delta.  
$$
其条件期望是：
$$
\mathbb E[\delta\nabla_\theta\delta\mid s],  
$$
一般不等于：
$$
\mathbb E[\delta\mid s]  
\mathbb E[\nabla_\theta\delta\mid s].  
$$
==原因是同一个**下一状态样本**同时出现在两个因子中，产生相关性==。若要构造无偏估计，需要在同一状态 $s$下采样两个独立的下一状态：
$$
S'_{(1)},S'_{(2)}.  
$$
**这就是 double-sampling problem。Zhu 和 Ying 对 Bellman residual minimization 的论述中明确指出，在 model-free setting 中，一个下一状态样本通常不够，进行无偏 SGD 需要两个独立下一状态样本。**([Proceedings of Machine Learning Research](https://proceedings.mlr.press/v107/zhu20a.html?utm_source=chatgpt.com "An Attempt to Address Double Sampling"))

---
# 16. 三者的数学层级关系

可以用以下链条理解：
$$
\delta_t
=
 R_{t+1}  
+  
\gamma v(S_{t+1})
-
v(S_t)  
$$
是样本级随机误差。
**条件期望得到 Bellman error**：
$$
\mathbb E[\delta_t\mid S_t=s]
=
(T_\pi v)(s)-v(s).  
$$
向量形式：
$$
\mathcal B(v)=T_\pi v-v.  
$$
投影到函数近似空间：
$$
\mathcal B_\Pi(v_\theta)
=
\Pi_D(T_\pi v_\theta-v_\theta).  
$$
乘以特征并取期望：
$$
\mathbb E[\delta\phi]
=
\Phi^\top D(T_\pi v_\theta-v_\theta)=g(\theta)
$$
**这就是 projected Bellman error 的坐标形式**。
所以：
$$
\boxed{  
\text{TD-error}  
\ \xrightarrow{\text{条件期望}}\  
\text{Bellman error}  
\ \xrightarrow{\text{投影}}\  
\text{projected Bellman error}.  
}  
$$


下面把 **projected Bellman error 的坐标形式** 从 value-space 形式一步一步推出来。核心结论先给出：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
 \Pi_D(T_\pi v_\theta-v_\theta)
=
\Phi C^{-1}\mathbb E[\delta_t(\theta)\phi_t]  
}  
$$
其中：
$$
\boxed{  
C=\mathbb E[\phi_t\phi_t^\top]=\Phi^\top D\Phi  
}  
$$

而它在特征基 $\Phi$ 下的**坐标向量**是：

$$
\boxed{  
w_\theta
=
C^{-1}\mathbb E[\delta_t(\theta)\phi_t].  
}  
$$


对应的均方 projected Bellman error 是：


$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta_t\phi_t]^\top  
C^{-1}  
\mathbb E[\delta_t\phi_t].  
}  
$$

Sutton、Szepesvári 和 Maei 在 GTD/TDC 论文中正是将 MSPBE 写成这种 expectation form，并指出它与 expected TD update $\mathbb E[\delta\phi]$ 的关系只差一个 feature covariance inverse。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

## 1. 从 value-space 的 PBE 开始

线性函数近似为：
$$
v_\theta=\Phi\theta.  
$$
Bellman residual 是：
$$
b_\theta
=
T_\pi v_\theta-v_\theta.  
$$
Projected Bellman error 定义为：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
 \Pi_D(T_\pi v_\theta-v_\theta)
=
\Pi_D b_\theta.  
}  
$$
这里 $\Pi_D$ 是到特征空间
$$
\mathcal V=\operatorname{Col}(\Phi)  
$$
上的 $D$-加权正交投影：
$$
\boxed{  
\Pi_D
=
\Phi(\Phi^\top D\Phi)^{-1}\Phi^\top D.  
}  
$$
令：
$$
C=\Phi^\top D\Phi.  
$$
则：
$$
\Pi_D=\Phi C^{-1}\Phi^\top D.  
$$
因此：
$$
\begin{aligned}  
\mathrm{PBE}(\theta)  
&=  
\Pi_D b_\theta  
\\  
&=  
\Phi C^{-1}\Phi^\top D b_\theta  
\\  
&=  
\Phi C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
\end{aligned}  
$$
所以：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Phi C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
}  
$$
这仍然是一个 **value-space vector**，维度是：
$$
|\mathcal S|.  
$$

---

## 2. 什么叫“坐标形式”？

因为：
$$
\mathrm{PBE}(\theta)\in \operatorname{Col}(\Phi),  
$$
所以它一定可以写成：
$$
\mathrm{PBE}(\theta)=\Phi w_\theta.  
$$
**其中 $w_\theta\in\mathbb R^d$ 就是 projected Bellman error 在特征基下的坐标**。
由上式：
$$
\mathrm{PBE}(\theta)
=
\Phi C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
$$
因此坐标向量为：
$$
\boxed{  
w_\theta
=
C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
}  
$$
也就是：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
 \Phi w_\theta,  
\qquad  
w_\theta
=
C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
}  
$$
注意这里的坐标不是简单的
$$
\Phi^\top D(T_\pi v_\theta-v_\theta),  
$$
而是：
$$
C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
$$
原因是 $\Phi$ 的列通常不是 $D$-正交归一基。若特征满足：
$$
\Phi^\top D\Phi=I,  
$$
则 $C=I$，此时坐标才退化为：
$$
w_\theta=\Phi^\top D(T_\pi v_\theta-v_\theta).  
$$
---

## 3. 用 TD-error 表示坐标

TD-error 为：
$$
\delta_t(\theta)
=
 R_{t+1}  
+  
\gamma \phi(S_{t+1})^\top\theta
-
\phi(S_t)^\top\theta.  
$$
简写：
$$
\phi_t=\phi(S_t),  
\qquad  
\phi_{t+1}=\phi(S_{t+1}).  
$$
则：
$$
\delta_t(\theta)
=
 R_{t+1}  
+  
\gamma \phi_{t+1}^\top\theta
-
\phi_t^\top\theta.  
$$
现在计算：
$$
\mathbb E[\delta_t(\theta)\phi_t].  
$$
逐状态展开：
$$
\begin{aligned}  
\mathbb E[\delta_t(\theta)\phi_t]  
&=  
\sum_s d(s)\phi(s)  
\mathbb E[\delta_t(\theta)\mid S_t=s]  
\\  
&=  
\sum_s d(s)\phi(s)  
\left[  
(T_\pi v_\theta)(s)-v_\theta(s)  
\right]  
\\  
&=  
\Phi^\top D(T_\pi v_\theta-v_\theta).  
\end{aligned}  
$$
因此：
$$
\boxed{  
\Phi^\top D(T_\pi v_\theta-v_\theta)
=
\mathbb E[\delta_t(\theta)\phi_t].  
}  
$$
代入上一节坐标表达式：
$$
\boxed{  
w_\theta
=
C^{-1}\mathbb E[\delta_t(\theta)\phi_t].  
}  
$$
所以：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Phi C^{-1}\mathbb E[\delta_t(\theta)\phi_t].  
}  
$$
这就是 projected Bellman error 的核心坐标形式。

---

## 4. 用 $A\theta-b$ 形式表示

在线性 TD 文献中，常定义：
$$
A
=
\mathbb E[\phi_t(\phi_t-\gamma\phi_{t+1})^\top],  
$$
$$
b
=
\mathbb E[R_{t+1}\phi_t],  
$$
$$
C
=
\mathbb E[\phi_t\phi_t^\top].  
$$
TD-error 乘以特征：
$$
\begin{aligned}  
\mathbb E[\delta_t\phi_t]  
&=  
\mathbb E[  
(R_{t+1}+\gamma\phi_{t+1}^\top\theta-\phi_t^\top\theta)\phi_t  
]  
\\  
&=  
\mathbb E[R_{t+1}\phi_t]  
+  
\gamma\mathbb E[\phi_t\phi_{t+1}^\top]\theta
-
 \mathbb E[\phi_t\phi_t^\top]\theta  
\\  
&=  
b
-
\mathbb E[\phi_t(\phi_t-\gamma\phi_{t+1})^\top]\theta  
\\  
&=  
b-A\theta.  
\end{aligned}  
$$
因此：
$$
\boxed{  
\mathbb E[\delta_t\phi_t]=b-A\theta.  
}  
$$
所以 PBE 的坐标向量也可以写为：
$$
\boxed{  
w_\theta
=
C^{-1}(b-A\theta).  
}  
$$
于是 value-space projected Bellman error 为：


$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Phi C^{-1}(b-A\theta).  
}  
$$
如果使用相反符号定义 residual：
$$
v_\theta-\Pi_D T_\pi v_\theta,  
$$
则对应坐标为：
$$
\boxed{  
C^{-1}(A\theta-b).  
}  
$$
符号不同，但平方目标相同。

---

## 5. MSPBE 的坐标形式

MSPBE 定义为：
$$
\mathrm{MSPBE}(\theta)
=
||\mathrm{PBE}(\theta)||_D^2.  
$$

由：
$$
\mathrm{PBE}(\theta)=\Phi w_\theta,  
$$
得到：
$$
\begin{aligned}  
\mathrm{MSPBE}(\theta)  
&=  
|\Phi w_\theta|_D^2  
\\  
&=  
(\Phi w_\theta)^\top D(\Phi w_\theta)  
\\  
&=  
w_\theta^\top \Phi^\top D\Phi w_\theta  
\\  
&=  
w_\theta^\top C w_\theta.  
\end{aligned}  
$$
代入：
$$
w_\theta=C^{-1}\mathbb E[\delta_t\phi_t],  
$$
得到：
$$
\begin{aligned}  
\mathrm{MSPBE}(\theta)  
&=  
(C^{-1}g_\theta)^\top C(C^{-1}g_\theta)  
\\  
&=  
g_\theta^\top C^{-1}g_\theta,  
\end{aligned}  
$$
其中：
$$
g_\theta=\mathbb E[\delta_t\phi_t].  
$$
因此：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta_t\phi_t]^\top  
C^{-1}  
\mathbb E[\delta_t\phi_t].  
}  
$$
又因为：
$$
\mathbb E[\delta_t\phi_t]=b-A\theta,  
$$
所以：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
(b-A\theta)^\top C^{-1}(b-A\theta).  
}  
$$
等价地，如果残差方向写成 $A\theta-b$，则：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
(A\theta-b)^\top C^{-1}(A\theta-b).  
}  
$$
Sutton 等人的 GTD/TDC 论文中给出的 MSPBE expectation form 正是：
$$
\mathbb E[\delta\phi]^\top  
\mathbb E[\phi\phi^\top]^{-1}  
\mathbb E[\delta\phi],  
$$
其中 $C=\mathbb E[\phi\phi^\top]$。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

## 6. 为什么 $\mathbb E[\delta\phi]$ 不是 PBE 的“真正坐标”？

需要区分两个量：
$$
g_\theta=\mathbb E[\delta_t\phi_t]  
$$
和：
$$
w_\theta=C^{-1}g_\theta.  
$$
其中：
$$
g_\theta
=
\Phi^\top D(T_\pi v_\theta-v_\theta)  
$$
是 Bellman residual 与各个特征方向的 $D$-内积，也就是**投影正规方程的右侧量**。
而真正使得：
$$
\mathrm{PBE}(\theta)=\Phi w_\theta  
$$
成立的坐标是：
$$
w_\theta=C^{-1}g_\theta.  
$$
原因是特征列向量通常不是正交归一基。对于非正交基，向量与基向量的内积不是坐标本身，必须乘以 Gram matrix 的逆：
$$
C^{-1}.  
$$
这里：
$$
C=\Phi^\top D\Phi  
$$
就是特征列在 $D$-内积下的 Gram matrix。

因此：
$$
\boxed{  
g_\theta=\mathbb E[\delta\phi]  
\text{ 是 expected TD update；}  
}  
$$

$$
\boxed{  
w_\theta=C^{-1}g_\theta  
\text{ 才是 PBE 在特征空间中的坐标。}  
}  
$$


---

## 7. TD fixed point 的坐标条件

Projected Bellman equation 是：
$$
v_\theta=\Pi_D T_\pi v_\theta.  
$$
等价于：
$$
\mathrm{PBE}(\theta)=0.  
$$
由于：
$$
\mathrm{PBE}(\theta)=\Phi C^{-1}(b-A\theta),  
$$
若 $\Phi$ 满列秩且 $C$ 可逆，则：
$$
\mathrm{PBE}(\theta)=0  
$$
等价于：
$$
b-A\theta=0.  
$$
即：
$$
\boxed{  
A\theta=b.  
}  
$$
这就是线性 TD fixed point 的正规方程形式。
换句话说，TD fixed point 满足：
$$
\boxed{  
\mathbb E[\delta_t(\theta)\phi_t]=0.  
}  
$$
也就是：
$$
\boxed{  
b-A\theta=0.  
}  
$$
其解为：
$$
\boxed{  
\theta_{\mathrm{TD}}=A^{-1}b  
}  
$$
在 $A$ 可逆时成立。

---
## 8. 最终总结

Projected Bellman error 的 value-space 形式是：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Pi_D(T_\pi v_\theta-v_\theta).  
}  
$$
投影算子为：
$$
\boxed{  
\Pi_D=\Phi C^{-1}\Phi^\top D,  
\qquad  
C=\Phi^\top D\Phi.  
}  
$$
因此：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
\Phi C^{-1}\Phi^\top D(T_\pi v_\theta-v_\theta).  
}  
$$
由于：
$$
\boxed{  
\Phi^\top D(T_\pi v_\theta-v_\theta)
=
 \mathbb E[\delta_t\phi_t]
=
b-A\theta,  
}  
$$
所以：
$$
\boxed{  
\mathrm{PBE}(\theta)
=
 \Phi C^{-1}\mathbb E[\delta_t\phi_t]
=
\Phi C^{-1}(b-A\theta).  
}  
$$
它在特征空间中的坐标向量为：

$$
\boxed{  
w_\theta
=
 C^{-1}\mathbb E[\delta_t\phi_t]
=
C^{-1}(b-A\theta).  
}  
$$
对应的均方目标为：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
 \mathbb E[\delta_t\phi_t]^\top  
C^{-1}  
\mathbb E[\delta_t\phi_t]
=
(b-A\theta)^\top C^{-1}(b-A\theta).  
}  
$$
一句话概括：
$$
\boxed{  
\text{PBE 的坐标形式就是：先用 }\mathbb E[\delta\phi]\text{ 得到 Bellman residual 在特征方向上的内积，再乘 }C^{-1}\text{ 转成真正的特征坐标。}  
}  
$$



---

---
# 17. 控制问题中的对应形式

如果是动作价值函数 $q(s,a)$，固定策略 $\pi$ 下：
$$
(T_\pi q)(s,a)
=
r(s,a)  
+  
\gamma  
\sum_{s'}P(s'|s,a)  
\sum_{a'}\pi(a'|s')q(s',a').  
$$
Bellman error：
$$
\mathcal B(q)(s,a)
=
(T_\pi q)(s,a)-q(s,a).  
$$
TD-error：
$$
\delta_t
=
 R_{t+1}  
+  
\gamma q(S_{t+1},A_{t+1})
-
q(S_t,A_t),  
$$
其中：
$$
A_{t+1}\sim \pi(\cdot|S_{t+1}).  
$$
若是最优控制，则 Bellman optimality operator 为：
$$
(T_* q)(s,a)
=
r(s,a)  
+  
\gamma  
\sum_{s'}P(s'|s,a)  
\max_{a'}q(s',a').  
$$
对应 Q-learning TD-error：
$$
\delta_t
=
 R_{t+1}  
+  
\gamma\max_{a'}Q(S_{t+1},a')
p-
Q(S_t,A_t).  
$$
此时 Bellman error 是 optimal Bellman residual：
$$
T_*Q-Q.  
$$
Projected Bellman error 则是：
$$
\Pi(T_*Q-Q),  
$$
但由于 $T_*$ 含 $\max$，非线性和不可微问题会更加复杂。

---
# 18. 三者对照表

| 概念                    | 数学形式                                                  | 层级              |   是否随机 | 主要用途                          |
| ----------------------- | --------------------------------------------------------- | ----------------- | ---------: | --------------------------------- |
| TD-error                | $\delta_t=R_{t+1}+\gamma V(S_{t+1})-V(S_t)$               | 单样本 transition |         是 | 在线更新信号                      |
| Bellman error           | $\mathcal B(v)=T_\pi v-v$                                 | Bellman 方程残差  | 否，期望量 | 衡量是否满足 Bellman 方程         |
| Projected Bellman error | $\mathcal B_\Pi(v_\theta)=\Pi_D(T_\pi v_\theta-v_\theta)$ | 函数空间内残差    | 否，期望量 | 函数近似下 TD fixed point / MSPBE |

---

# 19. 最终总结
**Bellman error**：
$$
\boxed{  
\mathcal B(v)=T_\pi v-v.  
}  
$$
它是 Bellman 方程的残差。若 $\mathcal B(v)=0$，则 $v=v_\pi$。
**TD-error**：
$$
\boxed{  
\delta_t=R_{t+1}+\gamma V(S_{t+1})-V(S_t).  
}  
$$
它是一个 transition 上的随机 Bellman 残差，其条件期望等于 Bellman error：
$$
\boxed{  
\mathbb E[\delta_t\mid S_t=s]
=
\mathcal B(V)(s).  
}  
$$
但：
$$
\boxed{  
\mathbb E[\delta_t^2]  
\neq  
\mathrm{MSBE}(V)  
}  
$$
一般成立，因为前者还包含条件方差。

**Projected Bellman error**：
$$
\boxed{  
\mathcal B_\Pi(v_\theta)
=
\Pi_D(T_\pi v_\theta-v_\theta).  
}  
$$
它是 Bellman error 在函数近似空间中的投影。对应目标：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
||\Pi_D(T_\pi v_\theta-v_\theta)||_D^2.  
}  
$$
线性函数近似下：
$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
\mathbb E[\delta\phi]^\top  
\left(  
\mathbb E[\phi\phi^\top]  
\right)^{-1}  
\mathbb E[\delta\phi].  
}  
$$
最核心的一句话是：
$$
\boxed{  
\text{TD-error 是 Bellman error 的采样版本；Bellman error 是 Bellman 方程的真实残差；projected Bellman error 是该残差在函数近似空间中能被表示出来的部分。}  
}
$$


---

**Bellman update** 可以理解为：把 Bellman 方程右侧当作新的估计目标，用它替换或部分修正当前价值估计。  
**在动态规划中，Bellman update 通常是一次完整的 “backup”；在 TD、Q-learning 中，它变成基于样本的增量更新。** Sutton & Barto 将 value iteration 描述为“把 Bellman optimality equation 转成更新规则”，Berkeley CS287 讲义也直接把这种 value update 称为 Bellman update / Bellman backup。([Stanford University](https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf?utm_source=chatgpt.com "Reinforcement Learning: An Introduction"))

---

# 1. Bellman 方程先说清楚

固定策略 $\pi$ 下，状态价值函数满足：
$$
v_\pi(s)
=
\mathbb E_\pi  
\left[  
R_{t+1}  
+  
\gamma v_\pi(S_{t+1})  
\mid S_t=s  
\right].  
$$
展开为：
$$
v_\pi(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)v_\pi(s').  
$$
向量形式：
$$
v_\pi
=
r_\pi+\gamma P_\pi v_\pi.  
$$
定义 Bellman operator：
$$
(T_\pi v)(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)v(s').  
$$
则 Bellman 方程写成：
$$
\boxed{  
v_\pi=T_\pi v_\pi.  
}  
$$
**==也就是说，真值函数 $v_\pi$ 是 Bellman operator $T_\pi$ 的不动点。==**

---

# 2. Bellman update 的基本形式

如果当前估计是 $v_k$，Bellman update 就是把它代入 Bellman operator，得到新的估计：
$$
\boxed{  
v_{k+1}=T_\pi v_k.  
}  
$$
逐状态写为：
$$
\boxed{  
v_{k+1}(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)v_k(s').  
}  
$$
==这就是 **policy evaluation** 中的 **Bellman update**。==

含义是：
$$
\text{新价值}
=
\text{即时奖励期望}  
+  
\gamma  
\times  
\text{下一状态旧价值的期望}.  
$$
注意这里右侧用的是旧估计 $v_k$，左侧得到新估计 $v_{k+1}$。

---
# 3. Bellman update 与 Bellman equation 的区别

==**Bellman equation 是固定点条件：**==
$$
v=T_\pi v.  
$$
==**Bellman update 是迭代规则：**==
$$
v_{k+1}=T_\pi v_k.  
$$
两者关系是：
$$
\boxed{  
\text{Bellman equation 描述目标；Bellman update 是逼近目标的迭代步骤。}  
}  
$$
==如果 $v_k$ 已经是真值函数 $v_\pi$，那么：==
$$
v_{k+1}=T_\pi v_k=T_\pi v_\pi=v_\pi.  
$$
此时更新不再改变值函数。

如果 $v_k\neq v_\pi$，Bellman update 会把当前估计向 Bellman fixed point 推近。

---

# 4. 为什么 Bellman update 会收敛？

在 $||\cdot||_\infty$ 范数下：
$$
||T_\pi u-T_\pi v||_\infty  
\le  
\gamma||u-v||_\infty.  
$$
证明：
$$
\begin{aligned}  
|(T_\pi u)(s)-(T_\pi v)(s)|  
&=  
\left|  
\gamma\sum_{s'}P_\pi(s'|s)(u(s')-v(s'))  
\right|  
\\  
&\le  
\gamma\sum_{s'}P_\pi(s'|s)|u(s')-v(s')|  
\\  
&\le  
\gamma||u-v||_\infty.  
\end{aligned}  
$$
对 $s$ 取最大：
$$
\boxed{  
||T_\pi u-T_\pi v||_\infty  
\le  
\gamma||u-v||_\infty.  
}  
$$
当：
$$
0\le \gamma<1  
$$
时，$T_\pi$ 是 **contraction mapping**。**因此根据 Banach fixed-point theorem，$T_\pi$ 有唯一 fixed point，反复应用 Bellman update 会收敛到该 fixed point。** Toronto CSC311 讲义也明确指出 value iteration update 是 contraction map，因此会收敛到唯一 fixed point([U of T Computer Science](https://www.cs.toronto.edu/~rgrosse/courses/csc311_f20/slides/lec11.pdf?utm_source=chatgpt.com "Lecture 11 - Reinforcement Learning"))。所以：
$$
\boxed{  
v_{k+1}=T_\pi v_k  
\quad\Longrightarrow\quad  
v_k\to v_\pi.  
}  
$$
---

# 5. 最优控制中的 Bellman update

如果不是固定策略评估，而是求最优价值函数，则使用 Bellman optimality operator。

状态价值形式：
$$
(T_*v)(s)
=
\max_a  
\sum_{s'}P(s'|s,a)  
\left[  
R(s,a,s')  
+  
\gamma v(s')  
\right].  
$$
Bellman optimality update 为：
$$
\boxed{  
v_{k+1}(s)
=
\max_a  
\sum_{s'}P(s'|s,a)  
\left[  
R(s,a,s')  
+  
\gamma v_k(s')  
\right].  
}  
$$
==**这就是 value iteration 的基本更新。**==

动作价值形式：
$$
(T_*Q)(s,a)
=
\sum_{s'}P(s'|s,a)  
\left[  
R(s,a,s')  
+  
\gamma\max_{a'}Q(s',a')  
\right].  
$$
对应 Bellman update：
$$
\boxed{  
Q_{k+1}(s,a)
=
\sum_{s'}P(s'|s,a)  
\left[  
R(s,a,s')  
+  
\gamma\max_{a'}Q_k(s',a')  
\right].  
}  
$$

Toronto CSC311 讲义把 value iteration 写为 $Q_{k+1}\leftarrow T^*Q_k$，并指出 fixed point 正是 optimal Bellman equation 的解。([U of T Computer Science](https://www.cs.toronto.edu/~rgrosse/courses/csc311_f20/slides/lec11.pdf?utm_source=chatgpt.com "Lecture 11 - Reinforcement Learning"))

---

# 6. Bellman update 与 backup 的关系

Bellman update 也常叫 **Bellman backup**。
**原因是：它从后继状态的值往当前状态“备份”信息。**
对固定策略：
$$
v_{k+1}(s)
=
r_\pi(s)  
+  
\gamma  
\mathbb E[v_k(S_{t+1})\mid S_t=s].  
$$
这表示：
$$
S_{t+1}\text{ 的价值}  
$$
被折扣后传回：
$$
S_t.  
$$
所以 Bellman backup 的直观含义是：
$$
\boxed{  
\text{用下一步状态的价值估计，反过来更新当前状态价值。}  
}  
$$
如果某个远处状态奖励很高，Bellman update 会让这个信息一层一层向前传播。

---

# 7. Model-based Bellman update 与 sample-based Bellman update

## 7.1 Model-based Bellman update

如果转移概率 $P$ 和奖励函数 $R$ 已知，可以直接计算期望：
$$
v_{k+1}(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)v_k(s').  
$$
这是动态规划中的 Bellman update。

---

## 7.2 Sample-based Bellman update

如果 $P$ 和 $R$ 未知，只能观察一个 transition：
$$
S_t=s,\quad R_{t+1}=r,\quad S_{t+1}=s',  
$$
则无法精确计算：
$$
r_\pi(s)+\gamma\sum_{s'}P_\pi(s'|s)v(s').  
$$
于是使用样本目标：
$$
\boxed{  
r+\gamma V(S_{t+1}).  
}  
$$
$TD(0)$ 更新为：
$$
\boxed{  
V(S_t)  
\leftarrow  
V(S_t)  
+  
\alpha  
\left[  
R_{t+1}  
+  
\gamma V(S_{t+1})
-
V(S_t)  
\right].  
}  
$$
其中：
$$
\delta_t
=
 R_{t+1}  
+  
\gamma V(S_{t+1})
-
V(S_t)  
$$
就是 TD-error。
所以 TD update 可以看作：
$$
\boxed{  
\text{用单样本 Bellman target 做增量 Bellman update。}  
}  
$$

---

# 8. Bellman target、Bellman error、TD error 的关系

当前状态 $s$ 的 Bellman target 是：
$$
(T_\pi V)(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)V(s').  
$$
Bellman error 是：
$$
\boxed{  
(T_\pi V)(s)-V(s).  
}  
$$
如果采样得到：
$$
S_t=s,\quad R_{t+1},\quad S_{t+1},  
$$
则样本 Bellman target 是：
$$
R_{t+1}+\gamma V(S_{t+1}).  
$$
TD-error 是：
$$
\boxed{  
\delta_t
=
 R_{t+1}  
+  
\gamma V(S_{t+1})
-
V(S_t).  
}  
$$
条件期望为：
$$
\begin{aligned}  
\mathbb E[\delta_t\mid S_t=s]  
&=  
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)V(s')
-
V(s)  
\\  
&=  
(T_\pi V)(s)-V(s).  
\end{aligned}  
$$
所以：
$$
\boxed{  
\text{TD-error 是 Bellman error 的单样本随机估计。}  
}  
$$
---

# 9. Bellman update 在函数近似中的形式

若使用线性函数近似：
$$
v_\theta(s)=\phi(s)^\top\theta,  
$$
Bellman target 为：
$$
r+\gamma \phi(s')^\top\theta.  
$$
TD-style Bellman update 为：
$$
\theta  
\leftarrow  
\theta  
+  
\alpha  
\left[  
r+\gamma\phi(s')^\top\theta-\phi(s)^\top\theta  
\right]\phi(s).  
$$
也就是：
$$
\boxed{  
\theta  
\leftarrow  
\theta+\alpha\delta_t\phi(S_t).  
}  
$$
这里不再显式更新某个表格项 $V(s)$，而是更新参数 $\theta$。参数变化后，许多状态的价值估计都会同时改变，因为它们共享同一个 $\theta$。

---

# 10. Bellman update 为什么不是简单监督学习？

普通监督学习可能有固定标签：
$$
y.  
$$
例如：
$$
\min_\theta (y-f_\theta(x))^2.  
$$
但 Bellman update 的目标含有当前价值函数自身：
$$
r+\gamma V(S_{t+1}).  
$$
==**也就是说，target 依赖当前估计 $V$。**这种结构叫 **bootstrapping**。==
$$
\boxed{  
\text{Bellman update 的目标不是外部固定标签，而是由当前估计递归构造出来的目标。}  
}  
$$
这也是 TD 学习与 Monte Carlo 学习的重要区别：TD 使用 bootstrap target，Monte Carlo 使用完整回报。

---

# 11. Bellman update 的几个版本对照

| 场景                 | Bellman update                                               |
| -------------------- | ------------------------------------------------------------ |
| 固定策略，已知模型   | $v_{k+1}=T_\pi v_k$                                          |
| 最优控制，已知模型   | $v_{k+1}=T_*v_k$                                             |
| TD(0)，未知模型      | $V(S_t)\leftarrow V(S_t)+\alpha[R_{t+1}+\gamma V(S_{t+1})-V(S_t)]$ |
| Q-learning，未知模型 | $Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\alpha[R_{t+1}+\gamma\max_{a'}Q(S_{t+1},a')-Q(S_t,A_t)]$ |
| SARSA，未知模型      | $Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\alpha[R_{t+1}+\gamma Q(S_{t+1},A_{t+1})-Q(S_t,A_t)]$ |

---

# 12. 总结

Bellman update 的本质是：
$$
\boxed{  
\text{用“一步奖励 + 折扣后的后继价值”重新估计当前价值。}  
}  
$$
固定策略下：
$$
\boxed{  
v_{k+1}(s)
=
r_\pi(s)  
+  
\gamma  
\sum_{s'}P_\pi(s'|s)v_k(s').  
}  
$$
最优控制下：
$$
\boxed{  
v_{k+1}(s)
=
\max_a  
\sum_{s'}P(s'|s,a)  
[  
R(s,a,s')+\gamma v_k(s')  
].  
}  
$$
采样形式下：
$$
\boxed{  
V(S_t)  
\leftarrow  
V(S_t)  
+  
\alpha  
[  
R_{t+1}+\gamma V(S_{t+1})-V(S_t)  
].  
}  
$$
一句话概括：
$$
\boxed{  
\text{Bellman update 是把 Bellman 方程右侧当作新的目标，对当前价值估计进行一次 backup；在已知模型时是期望更新，在未知模型时是样本 TD 更新。}  
}  
$$


---

下面给出 **Bellman error** 与 **Bellman residual** 的严格解释。二者在强化学习文献中经常被混用，但为了严谨，最好区分：


$$
\boxed{  
\text{Bellman residual 通常指 Bellman 方程两侧之差，即一个残差向量/函数。}  
}  
$$



$$
\boxed{  
\text{Bellman error 有时也指这个残差本身，有时指其范数或平方范数。}  
}  
$$


例如 Sutton、Szepesvári 和 Maei 在 GTD/TDC 论文中把

 
$$
\mathrm{MSBE}(\theta)=|V_\theta-TV_\theta|_D^2  
$$


称为 mean-square Bellman error，用来衡量近似值函数满足 Bellman 方程的程度。这里的 ($V_\theta-TV_\theta$) 就是 Bellman residual，只是符号方向可能与 ($TV_\theta-V_\theta$) 相反，平方后无差别。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

# 1. 从 Bellman 方程开始

考虑固定策略 ($\pi$) 下的 policy evaluation。有限状态空间为：


$$
\mathcal S={s_1,\dots,s_{|\mathcal S|}}.  
$$

策略 ($\pi$) 诱导出的状态转移矩阵为：


$$
P_\pi(s'|s)=\sum_a\pi(a|s)P(s'|s,a).  
$$


策略下的期望即时奖励为：

$$
r_\pi(s)=\mathbb E_\pi[R_{t+1}\mid S_t=s].  
$$


真实状态价值函数定义为：


$$
v_\pi(s)
=
\mathbb E_\pi  
\left[  
\sum_{k=0}^{\infty}\gamma^kR_{t+k+1}  
\mid S_t=s  
\right].  
$$


Bellman 方程为：


$$
\boxed{  
v_\pi(s)
=
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v_\pi(s').  
}  
$$


定义 Bellman operator：


$$
(T_\pi v)(s)
=
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s').  
$$


向量形式为：


$$
\boxed{  
T_\pi v=r_\pi+\gamma P_\pi v.  
}  
$$


因此 Bellman 方程可写成不动点方程：


$$
\boxed{  
v_\pi=T_\pi v_\pi.  
}  
$$


这句话的含义是：真实价值函数 ($v_\pi$) 是 Bellman operator ($T_\pi$) 的 fixed point。Sutton & Barto 的教材以 Bellman 方程作为动态规划、TD 学习和价值函数估计的基本结构。([Stanford University](https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf?utm_source=chatgpt.com "Reinforcement Learning: An Introduction"))

---

# 2. Bellman residual 的定义

给定任意近似价值函数 ($v$)，通常不会正好满足 Bellman 方程：


$$
v\neq T_\pi v.  
$$

于是定义 **Bellman residual**：


$$
\boxed{  
\mathcal R_\pi(v)=T_\pi v-v.  
}  
$$


逐状态展开：


$$
\boxed{  
\mathcal R_\pi(v)(s)
=
 r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s')

v(s).  
}  
$$


这个量就是 Bellman 方程右侧减左侧的残差。

也有文献采用相反符号：


$$
\boxed{  
v-T_\pi v.  
}  
$$


这只是符号约定不同。若讨论平方误差：


$$
||T_\pi v-v||^2
=
||v-T_\pi v||^2,  
$$


二者完全等价。

因此：


$$
\boxed{  
\text{Bellman residual = Bellman 方程两边未能相等的差。}  
}  
$$


若：


$$
\mathcal R_\pi(v)=0,  
$$


则：


$$
T_\pi v-v=0,  
$$

即：


$$
v=T_\pi v.  
$$


在折扣 MDP 中，($T_\pi$) 是 contraction，所以 fixed point 唯一，因此：


$$
\boxed{  
\mathcal R_\pi(v)=0  
\Longleftrightarrow  
v=v_\pi.  
}  
$$

---

# 3. Bellman error 的定义

“Bellman error” 有两种常见用法。

## 3.1 向量/函数意义上的 Bellman error

有时 Bellman error 直接指 Bellman residual：


$$
\boxed{  
\mathrm{BE}(v)(s)
=
(T_\pi v)(s)-v(s).  
}  
$$

也就是：

$$
\mathrm{BE}(v)=T_\pi v-v.  
$$


这种用法中，Bellman error 和 Bellman residual 基本同义。

---

## 3.2 标量目标意义上的 Bellman error

更多优化文献中，Bellman error 指 residual 的某种范数，尤其是均方形式：


$$
\boxed{  
\mathrm{MSBE}(v)
=
||T_\pi v-v||_D^2.  
}  
$$


其中 ($D=\mathrm{diag}(d(s))$)，($d(s)$) 是某个状态分布权重，定义：


$$
||x||_D^2
=
 x^\top D x
=
\sum_s d(s)x(s)^2.  
$$


所以：


$$
\boxed{  
\mathrm{MSBE}(v)
=
 \sum_s d(s)  
\left[  
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s')
-
v(s)  
\right]^2.  
}  
$$


这就是 **mean squared Bellman error**，也常称 **mean squared Bellman residual**。Sutton、Szepesvári 和 Maei 将 MSBE 解释为“近似值函数满足 Bellman 方程有多接近”的自然度量。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

---

# 4. Bellman residual 与 value error 的关系

Bellman residual 不是 value error。

真实 value error 是：


$$
v-v_\pi.  
$$


Bellman residual 是：

$$
T_\pi v-v.  
$$


二者有严格线性关系。令：


$$
\Delta=v-v_\pi.  
$$

则：


$$
v=v_\pi+\Delta.  
$$


因为：


$$
T_\pi v=r_\pi+\gamma P_\pi v,  
$$


所以：


$$
\begin{aligned}  
T_\pi v-v  
&=  
r_\pi+\gamma P_\pi(v_\pi+\Delta)-(v_\pi+\Delta)  
\\  
&=  
r_\pi+\gamma P_\pi v_\pi-v_\pi  
+  
\gamma P_\pi\Delta-\Delta.  
\end{aligned}  
$$


由于真实值函数满足 Bellman 方程：


$$
r_\pi+\gamma P_\pi v_\pi-v_\pi=0,  
$$


因此：


$$
\boxed{  
T_\pi v-v
=
\gamma P_\pi\Delta-\Delta.  
}  
$$


也就是：


$$
\boxed{  
\mathcal R_\pi(v)
=
-(I-\gamma P_\pi)(v-v_\pi).  
}  
$$


于是：


$$
\boxed{  
v-v_\pi
=
-(I-\gamma P_\pi)^{-1}\mathcal R_\pi(v).  
}  
$$


这个关系说明：

1. Bellman residual 为 0 一定意味着 value error 为 0；
    
2. Bellman residual 很小通常暗示 value error 受到一定控制；
    
3. 但 Bellman residual 的大小不总是 value error 的可靠代理，尤其在函数近似、有限数据、离策略和采样误差存在时更明显。
    

Fujimoto、Meger、Precup、Nachum 和 Gu 的论文专门指出，Bellman error 虽然由真实值函数唯一为零，但在实际有限数据和函数近似条件下，Bellman error 可以成为较差的 value prediction accuracy 代理。([Proceedings of Machine Learning Research](https://proceedings.mlr.press/v162/fujimoto22a.html?utm_source=chatgpt.com "Why Should I Trust You, Bellman? The Bellman Error is a Poor ..."))

---

# 5. Bellman residual 的几何意义

Bellman residual 是：


$$
T_\pi v-v.  
$$

可理解为：


$$
\boxed{  
\text{从当前估计 }v\text{ 出发，做一次 Bellman update 后，与原估计之间的差。}  
}  
$$


如果：


$$
T_\pi v  
$$

与


$$
v  
$$


相差很大，说明当前 ($v$) 与 Bellman 方程不一致。

若：


$$
T_\pi v=v,  
$$


则当前 ($v$) 是 Bellman operator 的 fixed point。

因此 Bellman residual 的几何意义是：


$$
\boxed{  
\text{当前函数离 Bellman fixed point condition 的偏离程度。}  
}  
$$


注意，这不是直接比较：


$$
v\quad \text{和}\quad v_\pi.  
$$


而是比较：


$$
v\quad \text{和}\quad T_\pi v.  
$$


也就是说，Bellman residual 衡量的是**方程自洽性**，不是直接衡量与真实值函数的点wise 差距。

---

# 6. Bellman residual 与 TD-error 的关系

单步 TD-error 为：


$$
\boxed{  
\delta_t
=
R_{t+1}  
+  
\gamma v(S_{t+1})
-
v(S_t).  
}  
$$


这是一个基于单个 transition 的随机变量。

对当前状态 ($S_t=s$) 条件取期望：


$$
\begin{aligned}  
\mathbb E[\delta_t\mid S_t=s]  
&=  
\mathbb E[  
R_{t+1}  
+  
\gamma v(S_{t+1})
-
 v(S_t)  
\mid S_t=s]  
\\  
&=  
r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s')
-
v(s)  
\\  
&=  
(T_\pi v)(s)-v(s)  
\\  
&=  
\mathcal R_\pi(v)(s).  
\end{aligned}  
$$


所以：


$$
\boxed{  
\mathbb E[\delta_t\mid S_t=s]
=
\text{Bellman residual at }s.  
}  
$$


这说明：

$$
\boxed{  
\text{TD-error 是 Bellman residual 的单样本随机估计。}  
}  
$$


但注意：


$$
\delta_t  
$$


不是 Bellman residual 本身。Bellman residual 是对奖励和下一状态随机性取期望后的量；TD-error 是一个具体样本上的瞬时误差。

Sutton & Barto 的 TD 学习公式正是使用


$$
\delta_t=R_{t+1}+\gamma V(S_{t+1})-V(S_t)  
$$


作为样本级更新信号。([Stanford University](https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf?utm_source=chatgpt.com "Reinforcement Learning: An Introduction"))

---

# 7. 为什么 ($\mathbb E[\delta_t^2]$) 不等于 MSBE？

这是非常重要的细节。

MSBE 是：


$$
\mathrm{MSBE}(v)
=
\mathbb E_{S\sim d}  
\left[  
\left(  
\mathbb E[\delta_t\mid S_t=S]  
\right)^2  
\right].  
$$


而 squared TD-error 的期望是：


$$
\mathbb E[\delta_t^2].  
$$


由条件方差分解：

 
$$
\mathbb E[\delta_t^2\mid S_t=s]
=
\left(\mathbb E[\delta_t\mid S_t=s]\right)^2  
+  
\operatorname{Var}(\delta_t\mid S_t=s).  
$$


再对 ($S_t\sim d$) 取期望：


$$
\boxed{  
\mathbb E[\delta_t^2]
=
\mathrm{MSBE}(v)  
+  
\mathbb E_{S\sim d}  
[  
\operatorname{Var}(\delta_t\mid S_t=S)  
].  
}  
$$


因此：


$$
\boxed{  
\mathbb E[\delta_t^2]\neq \mathrm{MSBE}(v)  
}  
$$


一般成立。

区别在于：

- MSBE 平方的是**条件期望误差**；
    
- squared TD-error 平方的是**单样本误差**，其中包含环境随机性和奖励噪声。
    

所以最小化样本平方 TD-error 并不等价于最小化 Bellman residual 的平方。

这也是 Bellman residual minimization 在 model-free 场景中出现 double sampling 问题的根源：若要无偏估计 MSBE 梯度，通常需要在同一状态下获得两个独立的下一状态样本。Zhu 和 Ying 的工作明确指出，model-free Bellman residual minimization 的主要困难就是 double sampling problem。([arXiv](https://arxiv.org/abs/1912.00304?utm_source=chatgpt.com "Borrowing From the Future: An Attempt to Address Double Sampling"))

---

# 8. 一个简单例子：Bellman residual 为 0，但 TD-error 平方不为 0

设某状态 ($s$) 有两个可能后继状态：


$$
P(s_1'|s)=\frac12,  
\qquad  
P(s_2'|s)=\frac12.  
$$


奖励恒为 0，折扣因子为：


$$
\gamma=1.  
$$


当前估计为：


$$
v(s)=0,  
$$

$$
v(s_1')=1,  
\qquad  
v(s_2')=-1.  
$$


Bellman residual 为：


$$
\begin{aligned}  
\mathcal R_\pi(v)(s)  
&=  
0  
+  
\frac12v(s_1')  
+  
\frac12v(s_2')

v(s)  
\\  
&=  
\frac12(1)+\frac12(-1)-0  
\\  
&=  
0.  
\end{aligned}  
$$


但是单样本 TD-error 为：

若采样到 ($s_1'$)：


$$
\delta=1.  
$$


若采样到 ($s_2'$)：


$$
\delta=-1.  
$$


所以：


$$
\mathbb E[\delta\mid s]=0,  
$$


但：


$$
\mathbb E[\delta^2\mid s]=1.  
$$


因此：


$$
\boxed{  
\text{Bellman residual 可以为 0，但 squared TD-error 仍然大于 0。}  
}  
$$


这说明 Bellman residual 是条件均值误差，TD-error 是带采样噪声的瞬时误差。

---

# 9. Bellman residual minimization

若以 Bellman residual 的平方作为目标，则得到 Bellman residual minimization：


$$
\boxed{  
\min_v ||T_\pi v-v||_D^2.  
}  
$$


在线性函数近似中：


$$
v_\theta=\Phi\theta.  
$$


目标为：


$$
\boxed{  
\min_\theta  
||T_\pi v_\theta-v_\theta||_D^2.  
}  
$$


这就是 MSBE minimization：


$$
\mathrm{MSBE}(\theta)
=
||T_\pi v_\theta-v_\theta||_D^2.  
$$


这类方法的优点是目标非常直接：让近似值函数尽量满足 Bellman 方程。Gottwald 等人把 MSBE 作为一个 smooth optimization objective 来分析，并研究了用神经网络近似时 Bellman residual error 的优化性质。([arXiv](https://arxiv.org/abs/2106.08774?utm_source=chatgpt.com "Analysis and Optimisation of Bellman Residual Errors with Neural Function Approximation"))

但缺点是：

1. model-free 条件下无偏梯度估计困难；
    
2. 会出现 double sampling problem；
    
3. Bellman error 小不一定代表 value error 小；
    
4. 在有限数据上可能过拟合 Bellman objective。
    

Fujimoto 等人特别强调，Bellman error 可以作为 Bellman equation 的 surrogate objective，但它不总是 value prediction accuracy 的可靠替代指标。([Proceedings of Machine Learning Research](https://proceedings.mlr.press/v162/fujimoto22a.html?utm_source=chatgpt.com "Why Should I Trust You, Bellman? The Bellman Error is a Poor ..."))

---

# 10. 与 projected Bellman error 的区别

在线性函数近似中：


$$
v_\theta=\Phi\theta.  
$$

Bellman 更新：
 
$$
T_\pi v_\theta  
$$


通常不在可表示空间：

  
$$
\mathcal V=\operatorname{Col}(\Phi)  
$$


中。

所以普通 Bellman residual 是完整空间中的残差：


$$
\boxed{  
T_\pi v_\theta-v_\theta.  
}  
$$


而 projected Bellman residual 是把这个残差投影回函数近似空间：


$$
\boxed{  
\Pi_D(T_\pi v_\theta-v_\theta).  
}  
$$

对应目标是：


$$
\boxed{  
\mathrm{MSPBE}(\theta)
=
||\Pi_D(T_\pi v_\theta-v_\theta)||_D^2.  
}  
$$


Sutton、Szepesvári 和 Maei 指出，很多 TD 方法的 fixed point 对应 projected Bellman equation，而 GTD/TDC 等梯度 TD 方法以 MSPBE 为目标。([ICML](https://icml.cc/Conferences/2009/papers/546.pdf?utm_source=chatgpt.com "Fast Gradient-Descent Methods for Temporal-Difference ..."))

因此：

 
$$
\boxed{  
\mathrm{MSBE}
=
\text{完整 Bellman residual 的平方范数}  
}  
$$

$$
\boxed{  
\mathrm{MSPBE}
=
\text{投影后的 Bellman residual 的平方范数}  
}  
$$


两者不同。

---

# 11. Bellman error / residual 在控制问题中的形式

上面讨论的是固定策略 ($\pi$)。在最优控制中，使用 Bellman optimality operator。

状态价值形式：


$$
(T_*v)(s)
=
\max_a  
\sum_{s'}P(s'|s,a)  
\left[  
R(s,a,s')  
+  
\gamma v(s')  
\right].  
$$

Bellman optimality residual 为：


$$
\boxed{  
\mathcal R_*(v)(s)
=
(T_*v)(s)-v(s).  
}  
$$


动作价值形式：


$$
(T_*Q)(s,a)
=
\sum_{s'}P(s'|s,a)  
\left[  
R(s,a,s')  
+  
\gamma\max_{a'}Q(s',a')  
\right].  
$$


Q-function 的 Bellman residual 为：


$$
\boxed{  
\mathcal R_*(Q)(s,a)
=
(T_*Q)(s,a)-Q(s,a).  
}  
$$


Q-learning 的 TD-error：


$$
\boxed{  
\delta_t
=
 R_{t+1}  
+  
\gamma\max_{a'}Q(S_{t+1},a')
-
Q(S_t,A_t)  
}  
$$


是最优 Bellman residual 的单样本估计。

---

# 12. 最终总结

**Bellman residual** 严格来说是 Bellman 方程残差：


$$
\boxed{  
\mathcal R_\pi(v)=T_\pi v-v.  
}  
$$


逐状态为：

 
$$
\boxed{  
\mathcal R_\pi(v)(s)
=
 r_\pi(s)  
+  
\gamma\sum_{s'}P_\pi(s'|s)v(s')
-
v(s).  
}  
$$


**Bellman error** 有时指同一个残差，有时指其范数或平方范数：

  
$$
\boxed{  
\mathrm{MSBE}(v)=||T_\pi v-v||_D^2.  
}  
$$


它衡量的是：

  
$$
\boxed{  
\text{当前价值函数是否满足 Bellman 方程。}  
}  
$$


但它不等于 value error：


$$
\boxed{  
v-v_\pi.  
}  
$$


二者关系为：


$$
\boxed{  
T_\pi v-v
=
-(I-\gamma P_\pi)(v-v_\pi).  
}  
$$


TD-error 是样本级残差：


$$
\boxed{  
\delta_t
=
 R_{t+1}  
+  
\gamma v(S_{t+1})
-
v(S_t).  
}  
$$


其条件期望等于 Bellman residual：

 
$$
\boxed{  
\mathbb E[\delta_t\mid S_t=s]
=
\mathcal R_\pi(v)(s).  
}  
$$


所以最简洁的关系是：


$$
\boxed{  
\text{Bellman residual 是期望层面的 Bellman 方程残差；TD-error 是它的单样本随机版本；Bellman error 常指该残差的大小或平方大小。}  
}  
$$


---


