boyu-ai / Hands-on-RL

https://hrl.boyuai.com/
Apache License 2.0
2.56k stars 550 forks source link

策略梯度证明笔误? #82

Open lanceyliao opened 3 months ago

lanceyliao commented 3 months ago

9.6. 策略梯度证明

$$ \begin{aligned} \nabla\theta V^{\pi\theta}(s) &= \phi(s) + \gamma \suma \pi\theta(a|s) \sum{s'} p(s'|s, a) \nabla\theta V^{\pi\theta}(s')\ &= \phi(s) + \gamma \sum{s'} \suma \pi\theta(a|s) p(s'|s, a) \nabla\theta V^{\pi\theta}(s')\ &= \phi(s) + \gamma \sum{s'} d^{\pi\theta}(s \to s', 1) \nabla\theta V^{\pi\theta}(s')\ &= \phi(s) + \gamma \sum{s'} d^{\pi\theta}(s \to s', 1)[\phi(s') + \gamma \sum{s''} d^{\pi\theta}(s' \to s'', 1)\nabla\theta V^{\pi\theta}(s'')]\ &= \phi(s) + \gamma \sum{s'} d^{\pi\theta}(s \to s', 1)\phi(s') + \gamma^2 \sum{s''} d^{\pi\theta}(s \to s'', 2)\nabla\theta V^{\pi\theta}(s'')\ &= \phi(s) + \gamma \sum{s'} d^{\pi\theta}(s \to s', 1)\phi(s') + \gamma^2 \sum{s''} d^{\pi\theta}(s \to s'', 2)\phi(s'') + \gamma^3 \sum{s'''} d^{\pi\theta}(s \to s''', 3)\nabla\theta V^{\pi\theta}(s''')\ &= \cdots\ &= \sum{x \in \mathcal{S}} \sum{k=0}^{\infty} \gamma^k d^{\pi_\theta}(s \to x, k)\phi(x) \end{aligned} $$

左侧为网站,右侧为应更正为的 image

lanceyliao commented 3 months ago

13.5. 确定性策略梯度证明也是,为什么不用$s_0 \to s$,而用$s \to s'$?

$$ \begin{aligned} \nabla{\theta} J(\mu{\theta}) &= \nabla{\theta} \int{S} \nu{0}(s) V^{\mu\theta}(s) ds \ &= \int{S} \nu{0}(s) \nabla{\theta} V^{\mu\theta}(s) ds \ (\text{代入} V^{\mu\theta}(s)) &= \int{S} \nu{0}(s) \left( \int{S} \sum{t=0}^{\infty} \gamma^{t} p(s \to s', t, \mu{\theta}) \nabla{\theta} \mu{\theta}(s') \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} ds' \right) ds \ (\text{交换积分顺序}) &= \int{S} \left( \int{S} \sum{t=0}^{\infty} \gamma^{t} \nu{0}(s) p(s \to s', t, \mu{\theta}) ds \right) \nabla{\theta} \mu{\theta}(s') \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} ds' \ (\text{代回} \nu^{\mu\theta}(s)) &= \int{S} \nu^{\mu\theta}(s') \nabla{\theta} \mu{\theta}(s') \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} ds' \ &= \mathbb{E}{s \sim \nu^{\mu\theta}} \left[ \nabla{\theta} \mu{\theta}(s) \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} \right] \end{aligned} $$

image

NeoPek commented 2 months ago

13.5. 确定性策略梯度证明也是,为什么不用$s_0 \to s$,而用$s \to s'$?

$$ \begin{aligned} \nabla{\theta} J(\mu{\theta}) &= \nabla{\theta} \int{S} \nu{0}(s) V^{\mu\theta}(s) ds \ &= \int{S} \nu{0}(s) \nabla{\theta} V^{\mu\theta}(s) ds \ (\text{代入} V^{\mu\theta}(s)) &= \int{S} \nu{0}(s) \left( \int{S} \sum{t=0}^{\infty} \gamma^{t} p(s \to s', t, \mu{\theta}) \nabla{\theta} \mu{\theta}(s') \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} ds' \right) ds \ (\text{交换积分顺序}) &= \int{S} \left( \int{S} \sum{t=0}^{\infty} \gamma^{t} \nu{0}(s) p(s \to s', t, \mu{\theta}) ds \right) \nabla{\theta} \mu{\theta}(s') \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} ds' \ (\text{代回} \nu^{\mu\theta}(s)) &= \int{S} \nu^{\mu\theta}(s') \nabla{\theta} \mu{\theta}(s') \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} ds' \ &= \mathbb{E}{s \sim \nu^{\mu\theta}} \left[ \nabla{\theta} \mu{\theta}(s) \nabla{a} Q^{\mu\theta}(s', a) \big|{a=\mu{\theta}(s')} \right] \end{aligned} $$

image

这里用 s' 应该是为了对应原论文推导的习惯,但是我感觉这里应该确实是写错了,交换积分顺序那一步里面那个括号的结果有问题,根据原始论文的符号定义应该是 ν^(μ_θ)(s') image 然后代回的那一步里面所有的 s' 就可以换成 s,这里感觉是笔者发现圆不回来偷了一步 :anguished: