RL学习笔记-状态价值,行动价值,贝尔曼方程
学习笔记来自西湖大学的RL课程:https://github.com/MathFoundationRL/Book-Mathematical-Foundation-of-Reinforcement-Learning
为了解决随机系统中回报的不稳定性问题,状态价值的概念被引入:它定义为从某一状态出发,遵循给定策略时所能获得的期望回报(平均回报)。这种期望形式能够平滑掉随机性带来的波动,更稳定地衡量策略在该状态下的长期表现,从而成为评估策略的可靠指标。
随机变量的引入
随机变量就是一个取值不确定、结果受到某种概率分布支配的变量。在强化学习中,环境状态、动作选择、奖励获得等都不是完全确定的,因此用随机变量建模并用概率和期望等方法去分析,是强化学习理论的基础。
- 首先,明确了多个符号所代表的都是随机变量,这是因为在强化学习的环境中,很多元素都存在不确定性。例如,智能体所处的状态、选择的动作、获得的奖励等,都可能受到随机因素的影响,并非完全确定。
- 其次,说明了这些随机变量的取值范围:
表示下一个状态属于状态空间
,即下一个状态是所有可能状态中的某一个;
意味着在当前状态
下,智能体选择的动作属于该状态下可执行的动作集合
;
表明在当前状态
下执行动作
所获得的即时奖励,属于该状态-动作对对应的奖励集合
。
这些说明为后续讨论状态价值、贝尔曼方程等概念奠定了基础,因为正是由于这些元素的随机性,才需要引入期望等概念来进行分析和计算。
状态价值函数的时间无关性
这句话阐述了状态价值函数 的一个重要特性:**它不依赖于时间步 **
。
具体来说,当智能体在状态空间中移动时, 仅表示当前的时间步(比如第 1 步、第 5 步等),**但对于给定的策略
和状态 **
,状态价值
是固定的。这是因为状态价值的定义是“在策略
下,从状态
出发所能获得的期望回报”,其核心取决于策略的规则以及环境对状态转移和奖励的设定,而与智能体“何时到达该状态”无关。
例如,假设在一个迷宫中,策略 是“始终向右移动”,那么无论智能体是在第 3 步还是第 10 步到达“迷宫入口”这个状态
,在策略
下,从
出发的期望回报(即状态价值
)都是相同的。一旦策略确定,每个状态的价值就被唯一确定,不会随时间步的变化而改变。
与回报的关系
- 确定性环境:状态价值 = 回报(因为每次结果都一样)
- 随机性环境:状态价值 = 所有可能回报的平均值
贝尔曼方程(Bellman Equation)
贝尔曼方程(Bellman Equation)是强化学习和动态规划中的核心方程,用来描述在给定策略 ππ 下,某一状态的价值(价值函数)与其后续状态价值之间的递归关系。
逐元素形式
首先将回报分解:
(当前回报 = 立即奖励 + 未来回报的折扣)
两边取期望(条件是 ):
展开期望项:
- 第一项(立即奖励期望):
(按策略选动作,再按环境模型得奖励)
- 第二项(未来价值期望):
(按策略选动作,按环境模型转移状态,再乘以未来状态的价值)
合并得到贝尔曼方程:
逐元素形式
这里, 和
分别表示可能的动作集合和奖励集合。需要注意的是,$A$ 可能因不同状态而异,在这种情况下,应该写作
。同样地,
也可能依赖于
。为了简化本书的表述,我们忽略了对
或
的依赖关系。但即便存在这种依赖,结论仍然成立。
全概率形式
In addition to the expression in (2.7), readers may also encounter other expressions of the Bellman equation in the literature. We next introduce two equivalent expressions.
First, it follows from the law of total probability that
Then, equation (2.7) can be rewritten as
This is the expression used in [3].
Second, the reward may depend solely on the next state
in some problems. As a result, we can write the reward as
and hence
, substituting which into (2.7) gives
全概率形式
矩阵形式
给出一个贝尔曼方程组的矩阵形式:
一般形式为:
解贝尔曼方程
证明可以通过随机初始化一个vk然后通过迭代收敛
Define the error:
We want to show that .
Step 1: Substitute expressions
Substitute and
into
which yields
Step 2: Rearrange terms
Rearranging, we have
Step 3: Iterative form
Repeatedly applying this,
Step 4: Convergence argument
Since every entry of is nonnegative and no greater than one,
for any . Also, since
, then
. Therefore,
动作价值(状态-动作价值)
◇ First, it follows from the properties of conditional expectation that
It then follows that
As a result, a state value is the expectation of the action values associated with that state.
◇ Second, since the state value is given by
comparing it with (2.13) leads to
2.14就是动作价值函数
贝尔曼公式的动作价值形式
In particular, substituting (2.13) into (2.14) yields, which is an equation of action values.
The above equation is valid for every state-action pair. If we put all these equations together, their matrix-vector form is
where is the action value vector indexed by the state-action pairs: its
th element is
.
is the immediate reward vector indexed by the state-action pairs:
.
The matrix is the probability transition matrix, whose row is indexed by the state-action pairs and whose column is indexed by the states:
_Moreover, is a block diagonal matrix in which each block is a
vector:
_and the other entries of
are zero.
Compared to the Bellman equation defined in terms of state values, the equation defined in terms of action values has some unique features.
For example, and
are independent of the policy and are merely determined by the system model. The policy is embedded in
. It can be verified that (2.15) is also a contraction mapping and has a unique solution that can be iteratively solved. More details can be found in [5].
RL学习笔记-状态价值,行动价值,贝尔曼方程