您当前的位置: 首页 > 

静静的喝酒

暂无认证

  • 3浏览

    0关注

    99博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

策略梯度方法介绍——确定性策略梯度定理

静静的喝酒 发布时间:2022-07-28 18:29:11 ,浏览量:3

策略梯度方法介绍——确定性策略梯度定理
  • 引言
    • 回顾:策略梯度定理
    • 确定性策略梯度
      • 确定性策略梯度的表示形式
      • 确定性策略梯度算法推导过程

引言

上一节我们介绍了 行动者-评论家(AC)方法,其核心思想是将policy_based与value_based方法相结合,仅需要执行一次状态转移过程,就可立即进行策略改进。本节将继续沿用AC方法框架,介绍 确定性策略梯度定理。

回顾:策略梯度定理

在策略梯度方法介绍——蒙特卡洛策略梯度方法(REINFORCE)介绍了策略梯度定理的期望表达形式: ∇ J ( θ ) = E S t ∼ ρ π θ ; A t ∼ π θ [ ∇ log ⁡ π ( A t ∣ S t ; θ ) q π θ ( S t , A t ) ] \nabla \mathcal J(\theta) = \mathbb E_{S_t \sim \rho^{\pi_{\theta}};A_t \sim \pi_{\theta}}[\nabla \log \pi(A_t \mid S_t;\theta)q_{\pi_{\theta}}(S_t,A_t)] ∇J(θ)=ESt​∼ρπθ​;At​∼πθ​​[∇logπ(At​∣St​;θ)qπθ​​(St​,At​)] 其中, t t t时刻状态 S t S_t St​服从状态分布 ρ π θ \rho^{\pi_{\theta}} ρπθ​, t t t时刻动作 A t A_t At​服从 S t S_t St​时刻的策略函数 π ( A t ∣ S t ; θ ) \pi(A_t \mid S_t;\theta) π(At​∣St​;θ)。

确定性策略梯度 确定性策略梯度的表示形式

既然有确定型策略梯度,自然也会有随机性策略梯度。在策略梯度定理推导过程中介绍的就是随机性策略梯度的推导过程。两者之间主要的差别是 t t t时刻动作 A t A_t At​服从的策略是确定性策略还是随机性策略。

在最早的马尔可夫奖励过程(MRP)中介绍到确定性策略—智能体在某一状态下只能执行唯一一个确定的动作。因此,在策略梯度方法中,策略 π ( A t ∣ S t ; θ ) \pi(A_t \mid S_t;\theta) π(At​∣St​;θ)是一个 常数,而常数自身是不存在梯度的,因此 ∇ π ( A t ∣ S t ; θ ) = 0 \nabla \pi(A_t \mid S_t;\theta) = 0 ∇π(At​∣St​;θ)=0;

为了在算法过程中,继续对参数 θ \theta θ求解梯度,对确定性策略设定一个符号: μ ( S t ; θ ) \mu(S_t;\theta) μ(St​;θ),记为 μ θ \mu_{\theta} μθ​。

  • μ ( S t ; θ ) \mu(S_t;\theta) μ(St​;θ)可看成是关于 S t S_t St​和参数 θ \theta θ的函数,而不是条件概率;
  • μ ( S t ; θ ) \mu(S_t;\theta) μ(St​;θ)本身就可以表示动作 A t A_t At​;

J ( θ ) \mathcal J(\theta) J(θ)仍然表示 μ θ \mu_{\theta} μθ​条件下,初始状态的回报 G 0 G_0 G0​的期望 E μ θ [ G 0 ] \mathbb E_{\mu_{\theta}}[G_0] Eμθ​​[G0​]。因此,对确定性策略梯度 ∇ J ( θ ) \nabla \mathcal J(\theta) ∇J(θ)表示如下: ∇ J ( θ ) = ∇ E μ θ [ G 0 ] = E [ ∑ k = 0 + ∞ γ k ∇ μ ( S t ; θ ) [ ∇ a q μ θ ( S t , a ) ] ∣ a = μ ( S t ; θ ) ] \nabla \mathcal J(\theta) = \nabla \mathbb E_{\mu_{\theta}}[G_0] = \mathbb E \left[\sum_{k=0}^{+\infty}\gamma^k \nabla \mu(S_t;\theta)[\nabla_{a}q_{\mu_{\theta}}(S_t,a)]|_{a=\mu(S_t;\theta)} \right] ∇J(θ)=∇Eμθ​​[G0​]=E[k=0∑+∞​γk∇μ(St​;θ)[∇a​qμθ​​(St​,a)]∣a=μ(St​;θ)​] 更一般的形式表示如下: ∇ J ( θ ) = E S t ∼ ρ μ θ [ ∇ μ ( S t ; θ ) ∇ a q μ θ ( S t , a ) ∣ a = μ ( S t ; θ ) ] \nabla \mathcal J(\theta) = \mathbb E_{S_t \sim \rho^{\mu_{\theta}}} \left[\nabla \mu(S_t;\theta) \nabla_{a}q_{\mu_{\theta}}(S_t,a) |_{a=\mu(S_t;\theta)}\right] ∇J(θ)=ESt​∼ρμθ​​[∇μ(St​;θ)∇a​qμθ​​(St​,a)∣a=μ(St​;θ)​]

和回顾中策略梯度定理中期望的表达形式对比,主要有如下几个区别:

  • 期望结果中,分布只包含状态分布 S t ∼ ρ μ θ S_t \sim \rho^{\mu_{\theta}} St​∼ρμθ​;
  • 期望内部,不仅要对 μ ( S t ; θ ) \mu(S_t;\theta) μ(St​;θ)中的 θ \theta θ求解梯度,还要对状态-动作价值函数 q μ θ ( S t , a ) q_{\mu_{\theta}}(S_t,a) qμθ​​(St​,a)中的 a a a求解梯度;
  • 不存在 log ⁡ \log log项;

带着上述的几个区别,执行确定性策略梯度的算法推导过程。

确定性策略梯度算法推导过程

整个推导过程和‘策略梯度定理’推导过程非常相似,大家可以对比查看。 当策略函数 π ( a ∣ s ; θ ) \pi(a \mid s;\theta) π(a∣s;θ)成为确定性策略 μ ( s ; θ ) \mu(s;\theta) μ(s;θ)后,最主要的变化 是状态价值函数 V μ θ ( s ) V_{\mu_{\theta}}(s) Vμθ​​(s)与状态-动作价值函数 q μ θ ( s , μ ( s ; θ ) ) q_{\mu_{\theta}}(s,\mu(s;\theta)) qμθ​​(s,μ(s;θ))相等: 动作被唯一确定了; V μ θ ( s ) = q μ θ ( s , μ ( s ; θ ) ) , s ∈ S V_{\mu_{\theta}}(s) = q_{\mu_{\theta}}(s,\mu(s;\theta)), s \in \mathcal S Vμθ​​(s)=qμθ​​(s,μ(s;θ)),s∈S

根据贝尔曼期望方程,将 q μ θ ( s , a ) q_{\mu_{\theta}}(s,a) qμθ​​(s,a)展开为如下形式: r ( s , μ ( s , θ ) ) r(s,\mu(s,\theta)) r(s,μ(s,θ))被称为奖赏函数。 q μ θ ( s , μ ( s ; θ ) ) = r ( s , μ ( s ; θ ) ) + γ ∑ s ′ , r P ( s ′ , r ∣ s , μ ( s ; θ ) ) V μ θ ( s ′ ) , s ∈ S q_{\mu_{\theta}}(s,\mu(s;\theta)) = r(s,\mu(s;\theta)) + \gamma \sum_{s',r}P(s',r \mid s,\mu(s;\theta))V_{\mu_{\theta}}(s'), s \in \mathcal S qμθ​​(s,μ(s;θ))=r(s,μ(s;θ))+γs′,r∑​P(s′,r∣s,μ(s;θ))Vμθ​​(s′),s∈S 继续化简,后一项的 r r r可以使用概率密度积分的方式消掉。整理得: q μ θ ( s , μ ( s ; θ ) ) = r ( s , μ ( s , θ ) ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) V μ θ ( s ′ ) , s ∈ S q_{\mu_{\theta}}(s,\mu(s;\theta)) = r(s,\mu(s,\theta)) + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta))V_{\mu_{\theta}}(s'), s \in \mathcal S qμθ​​(s,μ(s;θ))=r(s,μ(s,θ))+γs′∑​P(s′∣s,μ(s;θ))Vμθ​​(s′),s∈S

分别对 V μ θ ( s ) , q μ θ ( s , μ ( s ; θ ) ) V_{\mu_{\theta}}(s),q_{\mu_{\theta}}(s,\mu(s;\theta)) Vμθ​​(s),qμθ​​(s,μ(s;θ))求解梯度: ∇ V μ θ ( s ) = ∇ q μ θ ( s , μ ( s ; θ ) ) \nabla V_{\mu_{\theta}}(s) = \nabla q_{\mu_{\theta}}(s,\mu(s;\theta)) ∇Vμθ​​(s)=∇qμθ​​(s,μ(s;θ)) 对 q μ θ ( s , μ ( s ; θ ) ) q_{\mu_{\theta}}(s,\mu(s;\theta)) qμθ​​(s,μ(s;θ))求解梯度过程中,由于对 θ \theta θ求解梯度,因此注意 链式求导法则 和 乘法求导: ∇ q μ θ ( s , μ ( s ; θ ) ) = ∇ a r ( s , a ) ∣ a = μ ( s ; θ ) ⋅ ∇ μ ( s ; θ ) + γ ∑ s ′ { ∇ a P ( s ′ ∣ s , a ) ∣ a = μ ( s ; θ ) ⋅ ∇ μ ( s ; θ ) ⋅ V μ θ ( s ′ ) + P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ V μ θ ( s ′ ) } \nabla q_{\mu_{\theta}}(s,\mu(s;\theta)) = \nabla_{a} r(s,a)|_{a=\mu(s;\theta)}\cdot\nabla\mu(s;\theta) + \gamma \sum_{s'}\left\{\nabla_{a} P(s' \mid s,a)|_{a = \mu(s;\theta)} \cdot \nabla \mu(s;\theta) \cdot V_{\mu_{\theta}}(s') + P(s' \mid s,\mu(s;\theta)) \cdot \nabla V_{\mu_{\theta}}(s') \right\} ∇qμθ​​(s,μ(s;θ))=∇a​r(s,a)∣a=μ(s;θ)​⋅∇μ(s;θ)+γs′∑​{∇a​P(s′∣s,a)∣a=μ(s;θ)​⋅∇μ(s;θ)⋅Vμθ​​(s′)+P(s′∣s,μ(s;θ))⋅∇Vμθ​​(s′)} 将含有 ∇ μ ( s ; θ ) \nabla \mu(s;\theta) ∇μ(s;θ)的项提出来: ∇ μ ( s ; θ ) ⋅ [ ∇ a r ( s , a ) + γ ∑ s ′ ∇ a P ( s ′ ∣ s , a ) ⋅ V μ θ ( s ′ ) ] a = μ ( s ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ V μ θ ( s ′ ) \nabla\mu(s;\theta) \cdot \left[\nabla_{a}r(s,a) + \gamma\sum_{s'}\nabla_{a}P(s' \mid s,a) \cdot V_{\mu_{\theta}}(s')\right]_{a=\mu(s;\theta)} + \gamma \sum_{s'}P(s'\mid s,\mu(s;\theta)) \cdot \nabla V_{\mu_{\theta}}(s') ∇μ(s;θ)⋅[∇a​r(s,a)+γs′∑​∇a​P(s′∣s,a)⋅Vμθ​​(s′)]a=μ(s;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅∇Vμθ​​(s′) 又因为: ∇ a r ( s , a ) + γ ∑ s ′ ∇ a P ( s ′ ∣ s , a ) ⋅ V μ θ ( s ′ ) = ∇ a r ( s , a ) + ∇ a γ ∑ s ′ P ( s ′ ∣ s , a ) ⋅ V μ θ ( s ′ ) = ∇ a [ r ( s , a ) + γ ∑ s ′ P ( s ′ ∣ s , a ) ⋅ V μ θ ( s ′ ) ] = ∇ a q μ θ ( s , a ) \begin{split} & \nabla_{a}r(s,a) + \gamma\sum_{s'}\nabla_{a}P(s' \mid s,a) \cdot V_{\mu_{\theta}}(s') \\ & = \nabla_{a} r(s,a) + \nabla_{a}\gamma\sum_{s'}P(s' \mid s,a) \cdot V_{\mu_{\theta}}(s') \\ & = \nabla_{a} \left[r(s,a) + \gamma\sum_{s'}P(s' \mid s,a) \cdot V_{\mu_{\theta}}(s')\right] \\ & = \nabla_{a}q_{\mu_{\theta}}(s,a) \\ \end{split} ​∇a​r(s,a)+γs′∑​∇a​P(s′∣s,a)⋅Vμθ​​(s′)=∇a​r(s,a)+∇a​γs′∑​P(s′∣s,a)⋅Vμθ​​(s′)=∇a​[r(s,a)+γs′∑​P(s′∣s,a)⋅Vμθ​​(s′)]=∇a​qμθ​​(s,a)​

则有: ∇ q μ θ ( s , μ ( s ; θ ) ) = ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ V μ θ ( s ′ ) \nabla q_{\mu_{\theta}}(s,\mu(s;\theta)) = \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \nabla V_{\mu_{\theta}}(s') ∇qμθ​​(s,μ(s;θ))=∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅∇Vμθ​​(s′)

最终有: ∇ V μ θ ( s ) = ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ V μ θ ( s ′ ) \nabla V_{\mu_{\theta}}(s) = \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \nabla V_{\mu_{\theta}}(s') ∇Vμθ​​(s)=∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅∇Vμθ​​(s′) 至此,我们得到了 ∇ V μ θ ( s ) → ∇ V μ θ ( s ′ ) \nabla V_{\mu_{\theta}}(s) \to \nabla V_{\mu_{\theta}}(s') ∇Vμθ​​(s)→∇Vμθ​​(s′)的 递推关系。我们同样可以得到 ∇ V μ θ ( s ′ ) → ∇ V μ θ ( s ′ ′ ) \nabla V_{\mu_{\theta}}(s') \to \nabla V_{\mu_{\theta}}(s'') ∇Vμθ​​(s′)→∇Vμθ​​(s′′)的递推关系: ∇ V μ θ ( s ′ ) = ∇ μ ( s ′ ; θ ) ⋅ ∇ a ′ q μ θ ( s ′ , a ′ ) ∣ a ′ = μ ( s ′ ; θ ) + γ ∑ s ′ ′ P ( s ′ ′ ∣ s ′ , μ ( s ′ ; θ ) ) ⋅ ∇ V μ θ ( s ′ ′ ) \nabla V_{\mu_{\theta}}(s') = \nabla \mu(s';\theta) \cdot \nabla_{a'}q_{\mu_{\theta}}(s',a')|_{a' = \mu(s';\theta)} + \gamma \sum_{s''}P(s'' \mid s',\mu(s';\theta)) \cdot \nabla V_{\mu_{\theta}}(s'') ∇Vμθ​​(s′)=∇μ(s′;θ)⋅∇a′​qμθ​​(s′,a′)∣a′=μ(s′;θ)​+γs′′∑​P(s′′∣s′,μ(s′;θ))⋅∇Vμθ​​(s′′)

将 ∇ V μ θ ( s ′ ) \nabla V_{\mu_{\theta}}(s') ∇Vμθ​​(s′)带回 ∇ V μ θ ( s ) \nabla V_{\mu_{\theta}}(s) ∇Vμθ​​(s): ∇ V μ θ ( s ) = ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ { ∇ μ ( s ′ ; θ ) ⋅ ∇ a ′ q μ θ ( s ′ , a ′ ) ∣ a ′ = μ ( s ′ ; θ ) + γ ∑ s ′ ′ P ( s ′ ′ ∣ s ′ , μ ( s ′ ; θ ) ) ⋅ ∇ V μ θ ( s ′ ′ ) } \nabla V_{\mu_{\theta}}(s) = \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \left\{\nabla \mu(s';\theta) \cdot \nabla_{a'}q_{\mu_{\theta}}(s',a')|_{a' = \mu(s';\theta)} + \gamma \sum_{s''}P(s'' \mid s',\mu(s';\theta)) \cdot \nabla V_{\mu_{\theta}}(s'') \right\} ∇Vμθ​​(s)=∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅{∇μ(s′;θ)⋅∇a′​qμθ​​(s′,a′)∣a′=μ(s′;θ)​+γs′′∑​P(s′′∣s′,μ(s′;θ))⋅∇Vμθ​​(s′′)}

展开后依然是三项加和的形式: ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ′ ; θ ) ⋅ ∇ a ′ q μ θ ( s ′ , a ′ ) ∣ a ′ = μ ( s ′ ; θ ) γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ γ ∑ s ′ ′ P ( s ′ ′ ∣ s ′ , μ ( s ′ ; θ ) ) ⋅ ∇ V μ θ ( s ′ ′ ) \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} \\ \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \nabla \mu(s';\theta) \cdot \nabla_{a'}q_{\mu_{\theta}}(s',a')|_{a' = \mu(s';\theta)} \\ \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \gamma \sum_{s''}P(s'' \mid s',\mu(s';\theta)) \cdot \nabla V_{\mu_{\theta}}(s'') ∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​γs′∑​P(s′∣s,μ(s;θ))⋅∇μ(s′;θ)⋅∇a′​qμθ​​(s′,a′)∣a′=μ(s′;θ)​γs′∑​P(s′∣s,μ(s;θ))⋅γs′′∑​P(s′′∣s′,μ(s′;θ))⋅∇Vμθ​​(s′′) 由于最后一项依然可以继续展开,因此我们先关注前面两项是否存在某种表达规律; 第一个式子,我们可以理解成 使用确定性策略 μ ( s ; θ ) \mu(s;\theta) μ(s;θ) 从状态 s s s经过动作 a = μ ( s ; θ ) a=\mu(s;\theta) a=μ(s;θ)执行0次状态转移至 状态 s s s的价值函数的 梯度。 状态 s s s转移至状态 s → s \to s→相当于没有进行状态转移——静止不动 ,因此动态特性函数 P ( s ′ ∣ s , μ ( s ; θ ) ) = 1 P(s' \mid s,\mu(s;\theta))=1 P(s′∣s,μ(s;θ))=1恒成立。并且 转移后的状态结果只有 s s s自身。因此,可以将第一项式子扩展如下: ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) = 1 × ∑ s 1 × ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) = γ 0 ∑ s P ( s ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) \begin{split} & \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} \\ & = 1 \times \sum_{s} 1 \times \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} \\ & = \gamma^0 \sum_{s} P(s \mid s,\mu(s;\theta)) \cdot \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} \end{split} ​∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​=1×s∑​1×∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​=γ0s∑​P(s∣s,μ(s;θ))⋅∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​​ 再次将第一项与第二项进行对比: γ 0 ∑ s P ( s ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ′ ; θ ) ⋅ ∇ a ′ q μ θ ( s ′ , a ′ ) ∣ a ′ = μ ( s ′ ; θ ) \gamma^0 \sum_{s} P(s \mid s,\mu(s;\theta)) \cdot \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)}\\ \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \nabla \mu(s';\theta) \cdot \nabla_{a'}q_{\mu_{\theta}}(s',a')|_{a' = \mu(s';\theta)} γ0s∑​P(s∣s,μ(s;θ))⋅∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​γs′∑​P(s′∣s,μ(s;θ))⋅∇μ(s′;θ)⋅∇a′​qμθ​​(s′,a′)∣a′=μ(s′;θ)​ 至此,找到规律: 如果状态 s s s执行了 N N N次状态转移后达到状态 s ( N ) s^{(N)} s(N): γ N ∑ s ( N ) P ( s ( N ) ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ( N ) ; θ ) ⋅ ∇ a ( N ) q μ θ ( s ( N ) , a ( N ) ) ∣ a ( N ) = μ ( s ( N ) ; θ ) \gamma^N \sum_{s^{(N)}} P(s^{(N)} \mid s,\mu(s;\theta)) \cdot \nabla \mu(s^{(N)};\theta) \cdot \nabla_{a^{(N)}}q_{\mu_{\theta}}(s^{(N)},a^{(N)})|_{a^{(N)} = \mu(s^{(N)};\theta)} γNs(N)∑​P(s(N)∣s,μ(s;θ))⋅∇μ(s(N);θ)⋅∇a(N)​qμθ​​(s(N),a(N))∣a(N)=μ(s(N);θ)​ 因此, ∇ J ( θ ) = ∇ V μ θ ( s 0 ) \nabla \mathcal J(\theta) = \nabla V_{\mu_{\theta}}(s_0) ∇J(θ)=∇Vμθ​​(s0​)表示如下: ∇ J ( θ ) = ∇ V μ θ ( s 0 ) = ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ V μ θ ( s ′ ) = ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ′ ; θ ) ⋅ ∇ a ′ q μ θ ( s ′ , a ′ ) ∣ a ′ = μ ( s ′ ; θ ) + γ ∑ s ′ P ( s ′ ∣ s , μ ( s ; θ ) ) ⋅ γ ∑ s ′ ′ P ( s ′ ′ ∣ s ′ , μ ( s ′ ; θ ) ) ⋅ ∇ V μ θ ( s ′ ′ ) = ⋯ = ∑ N = 0 + ∞ γ N ∑ s ( N ) P ( s ( N ) ∣ s , μ ( s ; θ ) ) ⋅ ∇ μ ( s ( N ) ; θ ) ⋅ ∇ a ( N ) q μ θ ( s ( N ) , a ( N ) ) ∣ a ( N ) = μ ( s ( N ) ; θ ) \begin{aligned} \nabla \mathcal J(\theta) & = \nabla V_{\mu_{\theta}}(s_0) \\ & = \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \nabla V_{\mu_{\theta}}(s') \\ & = \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \nabla \mu(s';\theta) \cdot \nabla_{a'}q_{\mu_{\theta}}(s',a')|_{a' = \mu(s';\theta)} + \gamma \sum_{s'}P(s' \mid s,\mu(s;\theta)) \cdot \gamma \sum_{s''}P(s'' \mid s',\mu(s';\theta)) \cdot \nabla V_{\mu_{\theta}}(s'')\\ & = \cdots \\ & = \sum_{N=0}^{+\infty}\gamma^N \sum_{s^{(N)}} P(s^{(N)} \mid s,\mu(s;\theta)) \cdot \nabla \mu(s^{(N)};\theta) \cdot \nabla_{a^{(N)}}q_{\mu_{\theta}}(s^{(N)},a^{(N)})|_{a^{(N)} = \mu(s^{(N)};\theta)} \end{aligned} ∇J(θ)​=∇Vμθ​​(s0​)=∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅∇Vμθ​​(s′)=∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅∇μ(s′;θ)⋅∇a′​qμθ​​(s′,a′)∣a′=μ(s′;θ)​+γs′∑​P(s′∣s,μ(s;θ))⋅γs′′∑​P(s′′∣s′,μ(s′;θ))⋅∇Vμθ​​(s′′)=⋯=N=0∑+∞​γNs(N)∑​P(s(N)∣s,μ(s;θ))⋅∇μ(s(N);θ)⋅∇a(N)​qμθ​​(s(N),a(N))∣a(N)=μ(s(N);θ)​​ 同样可以引入状态分布,构建一个符号: P r { s 0 → s , k , μ } P_r\{s_0 \to s,k,\mu\} Pr​{s0​→s,k,μ}表示 从初始状态 s 0 s_0 s0​开始,在确定性策略 μ θ \mu_{\theta} μθ​条件下,执行 k k k次状态转移后达到状态 s s s的概率: P r { s 0 → s , k , μ } P_r\{s_0 \to s,k,\mu\} Pr​{s0​→s,k,μ}符号产生过程 -> 传送门 V μ θ ( s ) = ∑ s ∈ S ∑ N = 0 + ∞ γ N × P r { s 0 → s , N , μ } ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) = ∑ s ∈ S γ N × η ( s ) × ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) \begin{aligned} V_{\mu_{\theta}}(s) & = \sum_{s \in \mathcal S}\sum_{N=0}^{+\infty} \gamma^N \times P_r\{s_0 \to s,N,\mu\} \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} \\ & = \sum_{s \in \mathcal S} \gamma^N \times \eta(s) \times \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} \end{aligned} Vμθ​​(s)​=s∈S∑​N=0∑+∞​γN×Pr​{s0​→s,N,μ}∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​=s∈S∑​γN×η(s)×∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​​

最终同样可以得到和策略梯度定理相似的如下表达: ∇ J ( θ ) ∝ ∑ s ∈ S μ ( s ) × ∇ μ ( s ; θ ) ⋅ ∇ a q μ θ ( s , a ) ∣ a = μ ( s ; θ ) \nabla \mathcal J(\theta) \propto \sum_{s \in \mathcal S}\mu(s) \times \nabla \mu(s;\theta) \cdot \nabla_{a}q_{\mu_{\theta}}(s,a)|_{a = \mu(s;\theta)} ∇J(θ)∝s∈S∑​μ(s)×∇μ(s;θ)⋅∇a​qμθ​​(s,a)∣a=μ(s;θ)​

最终引入状态分布符号 S t ∼ ρ π θ S_t \sim \rho^{\pi_{\theta}} St​∼ρπθ​,将上述公式化简为期望形式: ∇ J ( θ ) = E S t ∼ ρ μ θ [ ∇ μ ( S t ; θ ) ∇ a q μ θ ( S t , a ) ∣ a = μ ( S t ; θ ) ] \nabla \mathcal J(\theta) = \mathbb E_{S_t \sim \rho^{\mu_{\theta}}} \left[\nabla \mu(S_t;\theta) \nabla_{a}q_{\mu_{\theta}}(S_t,a) |_{a=\mu(S_t;\theta)}\right] ∇J(θ)=ESt​∼ρμθ​​[∇μ(St​;θ)∇a​qμθ​​(St​,a)∣a=μ(St​;θ)​]

本质上,确定性策略梯度定理与策略梯度定理推导非常相似,只是推导初始存在差异。 由于 μ ( S t ; θ ) \mu(S_t;\theta) μ(St​;θ)是确定性策略,因此不会对动作求解期望,从而不会像策略梯度定理一样通过除以 μ ( S t ; θ ) \mu(S_t;\theta) μ(St​;θ)以获取 log ⁡ \log log项。

相关参考: 深度强化学习原理、算法pytorch实战 —— 刘全,黄志刚编著 深度强化学习-确定性策略梯度算法推导

关注
打赏
1664446683
查看更多评论
立即登录/注册

微信扫码登录

0.0659s