前言
由于公式太长,写在一个文章里面看得云里雾里,所以分开写,本文中将直接使用推导好的动作价值函数与状态价值函数,关于如何推出来的表达式,请参考:深度强化学习总结
动作、状态、奖励序列
s t , a t , r t ( s t , a t ) , s t + 1 , a t + 1 , r t + 1 ( s t + 1 , a t + 1 ) , ⋯ , s t + n , a t + n , t t + n ( s t + n , a t + n ) s_t,a_t,r_{t}(s_t,a_t),s_{t+1},a_{t+1},r_{t+1}(s_{t+1},a_{t+1}),\cdots,s_{t+n},a_{t+n},t_{t+n}(s_{t+n},a_{t+n}) st,at,rt(st,at),st+1,at+1,rt+1(st+1,at+1),⋯,st+n,at+n,tt+n(st+n,at+n)
动作价值函数
当我们采取某个动作以后,可能的轨迹序列有多条,如何评价这个动作的价值,不能只选取某一条轨迹的价值作为评价,而应该是选择所有轨迹的均值作为评价。所以我们
首先计算在初始动作和状态已知的情况下一种可能轨迹序列所带来的回报及对应的概率。我把这种单次特定序列下的回报函数记为:
U
(
a
t
∣
s
t
,
f
a
,
f
r
,
f
t
)
=
[
r
t
(
s
t
,
a
t
)
+
γ
r
t
+
1
(
s
t
+
1
,
a
t
+
1
)
+
⋯
+
γ
n
r
t
+
n
(
s
t
+
n
,
a
t
+
n
)
]
U(a_t|s_t,f_a,f_r,f_t)=[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^nr_{t+n}(s_{t+n},a_{t+n})]
U(at∣st,fa,fr,ft)=[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]
对应的概率为:
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})
P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)
而某个动作的价值就是所有的可能轨迹序列所对应的回报的均值,所以需要求出所有可能的轨迹序列所对应的回报的期望:
∑
s
t
+
1
⋯
∑
s
t
+
n
∑
a
t
+
1
⋯
∑
a
t
+
n
[
r
t
(
s
t
,
a
t
)
+
γ
r
t
+
1
(
s
t
+
1
,
a
t
+
1
)
+
⋯
+
γ
n
r
t
+
n
(
s
t
+
n
,
a
t
+
n
)
]
∗
[
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
]
\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^nr_{t+n}(s_{t+n},a_{t+n})]*[P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})]
st+1∑⋯st+n∑at+1∑⋯at+n∑[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]∗[P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)]
因为是在一定状态下对于某个动作的期望回报,涉及的变量一共包括策略函数
f
a
f_a
fa,奖励函数
f
r
f_r
fr,转移函数
f
t
f_t
ft,以及动作和状态。所以我们选择
V
(
a
t
∣
f
a
,
f
r
,
f
t
,
s
t
)
V(a_t|f_a,f_r,f_t,s_t)
V(at∣fa,fr,ft,st)来表示这个动作所对应的价值。
我用
V
(
a
t
∣
f
a
,
f
r
,
f
t
,
s
t
)
V(a_t|f_a,f_r,f_t,s_t)
V(at∣fa,fr,ft,st)表示对所有特定的序列求均值所得到的均值回报函数,也就是==
U
U
U表示单次,
V
V
V表示均值==:
V
(
a
t
∣
f
a
,
f
r
,
f
t
,
s
t
)
=
∑
s
t
+
1
⋯
∑
s
t
+
n
∑
a
t
+
1
⋯
∑
a
t
+
n
[
r
t
(
s
t
,
a
t
)
+
γ
r
t
+
1
(
s
t
+
1
,
a
t
+
1
)
+
⋯
+
γ
n
r
t
+
n
(
s
t
+
n
,
a
t
+
n
)
]
∗
[
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
]
=
∑
s
t
+
1
⋯
∑
s
t
+
n
∑
a
t
+
1
⋯
∑
a
t
+
n
U
(
a
t
∣
s
t
,
f
a
,
f
r
,
f
t
)
∗
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
\begin{split} V(a_t|f_a,f_r,f_t,s_t)&=\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^nr_{t+n}(s_{t+n},a_{t+n})]*[P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})] \\&=\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}U(a_t|s_t,f_a,f_r,f_t)*P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n}) \end{split}
V(at∣fa,fr,ft,st)=st+1∑⋯st+n∑at+1∑⋯at+n∑[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]∗[P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)]=st+1∑⋯st+n∑at+1∑⋯at+n∑U(at∣st,fa,fr,ft)∗P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)
最优策略函数下的最大动作价值函数
V ( a t ∣ f a ∗ , f r , f t , s t ) = ∑ s t + 1 ⋯ ∑ s t + n ∑ a t + 1 ⋯ ∑ a t + n [ r t ( s t , a t ) + γ r t + 1 ( s t + 1 , a t + 1 ) + ⋯ + γ n r t + n ( s t + n , a t + n ) ] ∗ [ P ( s t + 1 ∣ s t , a t ) ∗ P ∗ ( a t + 1 ∣ s t + 1 ) ∗ ⋯ ∗ P ∗ ( a t + n ∣ s t + n ) ] = ∑ s t + 1 ⋯ ∑ s t + n ∑ a t + 1 ⋯ ∑ a t + n U ( a t ∣ s t , f a , f r , f t ) ∗ [ P ( s t + 1 ∣ s t , a t ) ∗ P ∗ ( a t + 1 ∣ s t + 1 ) ∗ ⋯ ∗ P ∗ ( a t + n ∣ s t + n ) ] \begin{split} V(a_t|f_a^*,f_r,f_t,s_t)&=\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^nr_{t+n}(s_{t+n},a_{t+n})]*[P(s_{t+1}|s_t,a_t)*P^*(a_{t+1}|s_{t+1})*\cdots*P^*(a_{t+n}|s_{t+n})] \\&=\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}U(a_t|s_t,f_a,f_r,f_t)*[P(s_{t+1}|s_t,a_t)*P^*(a_{t+1}|s_{t+1})*\cdots*P^*(a_{t+n}|s_{t+n})] \end{split} V(at∣fa∗,fr,ft,st)=st+1∑⋯st+n∑at+1∑⋯at+n∑[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]∗[P(st+1∣st,at)∗P∗(at+1∣st+1)∗⋯∗P∗(at+n∣st+n)]=st+1∑⋯st+n∑at+1∑⋯at+n∑U(at∣st,fa,fr,ft)∗[P(st+1∣st,at)∗P∗(at+1∣st+1)∗⋯∗P∗(at+n∣st+n)]
状态价值函数
状态价值函数也是同样,同一个状态可能有多条轨迹,我们评价状态的价值不能只选择一条路径上的价值而应该考虑所有路径上的价值,所以就是所有路径上价值的期望价值。
首先求出在初始状态给定的情况下一条可能的轨迹序列所对应的回报与概率:
U
(
s
t
∣
f
a
,
f
r
,
f
t
)
=
[
r
t
(
s
t
,
a
t
)
+
γ
r
t
+
1
(
s
t
+
1
,
a
t
+
1
)
+
⋯
+
γ
n
r
t
+
n
(
s
t
+
n
,
a
t
+
n
)
]
U(s_t|f_a,f_r,f_t)=[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^n{r_{t+n}(s_{t+n},a_{t+n})}]
U(st∣fa,fr,ft)=[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]
以上就是在给定策略函数,奖励函数,状态转移函数的情况下一条特定序列的回报函数。
对应的概率为:
[
P
(
a
t
∣
s
t
)
∗
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
]
[P(a_t|s_t)*P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})]
[P(at∣st)∗P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)]
然后求出所有可能的轨迹序列所对应的回报与概率的加权和:
∑
a
t
∑
a
t
+
1
⋯
∑
a
t
+
n
∑
s
t
+
1
⋯
∑
s
t
+
n
[
r
t
(
s
t
,
a
t
)
+
γ
r
t
+
1
(
s
t
+
1
,
a
t
+
1
)
+
⋯
+
γ
n
r
t
+
n
(
s
t
+
n
,
a
t
+
n
)
]
∗
[
P
(
a
t
∣
s
t
)
∗
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
]
\sum_{a_t}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^n{r_{t+n}(s_{t+n},a_{t+n})}]*[P(a_t|s_t)*P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})]
at∑at+1∑⋯at+n∑st+1∑⋯st+n∑[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]∗[P(at∣st)∗P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)]
同样,我们也分析一下这个值与什么有关,与策略函数
f
a
f_a
fa,奖励函数
f
r
f_r
fr,转移函数
f
t
f_t
ft,初始状态有关。用
V
(
s
t
∣
f
a
,
f
r
,
f
t
)
V(s_t|f_a,f_r,f_t)
V(st∣fa,fr,ft)来表示它。也就是:
V
(
s
t
∣
f
a
,
f
r
,
f
t
)
=
∑
a
t
∑
a
t
+
1
⋯
∑
a
t
+
n
∑
s
t
+
1
⋯
∑
s
t
+
n
[
r
t
(
s
t
,
a
t
)
+
γ
r
t
+
1
(
s
t
+
1
,
a
t
+
1
)
+
⋯
+
γ
n
r
t
+
n
(
s
t
+
n
,
a
t
+
n
)
]
∗
[
P
(
a
t
∣
s
t
)
∗
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
]
=
∑
a
t
∑
a
t
+
1
⋯
∑
a
t
+
n
∑
s
t
+
1
⋯
∑
s
t
+
n
U
(
s
t
∣
f
a
,
f
r
,
f
t
)
∗
[
P
(
a
t
∣
s
t
)
∗
P
(
s
t
+
1
∣
s
t
,
a
t
)
∗
P
(
a
t
+
1
∣
s
t
+
1
)
∗
⋯
∗
P
(
a
t
+
n
∣
s
t
+
n
)
]
\begin{split} V(s_t|f_a,f_r,f_t)&=\sum_{a_t}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^n{r_{t+n}(s_{t+n},a_{t+n})}]*[P(a_t|s_t)*P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})] \\&=\sum_{a_t}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}U(s_t|f_a,f_r,f_t)*[P(a_t|s_t)*P(s_{t+1}|s_t,a_t)*P(a_{t+1}|s_{t+1})*\cdots*P(a_{t+n}|s_{t+n})] \end{split}
V(st∣fa,fr,ft)=at∑at+1∑⋯at+n∑st+1∑⋯st+n∑[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]∗[P(at∣st)∗P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)]=at∑at+1∑⋯at+n∑st+1∑⋯st+n∑U(st∣fa,fr,ft)∗[P(at∣st)∗P(st+1∣st,at)∗P(at+1∣st+1)∗⋯∗P(at+n∣st+n)]
也就是状态的价值函数也是所有轨迹价值函数的均值,最优策略影响的只不过是各条轨迹出现的概率也就是各种回报出现的概率。
最优策略函数下的最大状态价值函数
V ( s t ∣ f a ∗ , f r , f t ) = ∑ a t ∑ a t + 1 ⋯ ∑ a t + n ∑ s t + 1 ⋯ ∑ s t + n [ r t ( s t , a t ) + γ r t + 1 ( s t + 1 , a t + 1 ) + ⋯ + γ n r t + n ( s t + n , a t + n ) ] ∗ [ P ∗ ( a t ∣ s t ) ∗ P ( s t + 1 ∣ s t , a t ) ∗ P ∗ ( a t + 1 ∣ s t + 1 ) ∗ ⋯ ∗ P ∗ ( a t + n ∣ s t + n ) ] = ∑ a t ∑ a t + 1 ⋯ ∑ a t + n ∑ s t + 1 ⋯ ∑ s t + n U ( s t ∣ f a , f r , f t ) ∗ [ P ∗ ( a t ∣ s t ) ∗ P ( s t + 1 ∣ s t , a t ) ∗ P ∗ ( a t + 1 ∣ s t + 1 ) ∗ ⋯ ∗ P ∗ ( a t + n ∣ s t + n ) ] \begin{split} V(s_t|f_a^*,f_r,f_t)&=\sum_{a_t}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}[r_t(s_t,a_t)+\gamma{r_{t+1}(s_{t+1},a_{t+1})}+\cdots+\gamma^n{r_{t+n}(s_{t+n},a_{t+n})}]*[P^*(a_t|s_t)*P(s_{t+1}|s_t,a_t)*P^*(a_{t+1}|s_{t+1})*\cdots*P^*(a_{t+n}|s_{t+n})] \\&=\sum_{a_t}\sum_{a_{t+1}}\cdots\sum_{a_{t+n}}\sum_{s_{t+1}}\cdots\sum_{s_{t+n}}U(s_t|f_a,f_r,f_t)*[P^*(a_t|s_t)*P(s_{t+1}|s_t,a_t)*P^*(a_{t+1}|s_{t+1})*\cdots*P^*(a_{t+n}|s_{t+n})] \end{split} V(st∣fa∗,fr,ft)=at∑at+1∑⋯at+n∑st+1∑⋯st+n∑[rt(st,at)+γrt+1(st+1,at+1)+⋯+γnrt+n(st+n,at+n)]∗[P∗(at∣st)∗P(st+1∣st,at)∗P∗(at+1∣st+1)∗⋯∗P∗(at+n∣st+n)]=at∑at+1∑⋯at+n∑st+1∑⋯st+n∑U(st∣fa,fr,ft)∗[P∗(at∣st)∗P(st+1∣st,at)∗P∗(at+1∣st+1)∗⋯∗P∗(at+n∣st+n)]