3
$\begingroup$

On page 270 of this draft of Intro to Reinforcement Learning by Sutton and Burton, the authors simplify the policy gradient as follows:

enter image description here

Since the action-value function equals the conditional expectation of the cumulative reward, the intermediate step in moving from line 2 to 3 is presumably:

enter image description here

Why can you just drop the inner expectation to arrive at line 3?

$\endgroup$

2 Answers 2

2
$\begingroup$

In my proof I use related random variables as the subscript of expectations rather than the policy $\pi$. It may make the expressions look more complicated but it makes the notion more clear.


The proof is based on two facts:

Fact 1.

$$ y\mathbb{E}_{X|Y=y}[X|Y=y]=\mathbb{E}_{X|Y=y}[Xy|Y=y] $$

The left part is actually a function of $y$ so in $\mathbb{E}_{X|Y=y}[\cdot]$'s view $y$ is a constant. Thus it can be put into the expectation by linearity. You can also prove it easily as below: $$ \begin{align} y\mathbb{E}[X|Y=y]&=y\sum_xp_{X|Y=y}(x|y)x\\ &=\sum_xp_{X|Y=y}(x|y)xy\\ &=\mathbb{E}[Xy|Y=y]\\ \end{align} $$

Fact 2.

$$ \mathbb{E}_X[\mathbb{E}_{Y|X}[g(X,Y)|X]]=\mathbb{E}_{X,Y}[g(X,Y)] $$

It is a generalization of the Law of Total Expectation. You can also easily prove it as below: $$ \begin{align} \mathbb{E}_X[\mathbb{E}_{Y|X}[g(X,Y)|X]]&=\sum_xp_X(x)\mathbb{E}_{Y|X=x}[g(x,Y)|X=x]\\ &=\sum_xp_X(x)\sum_yp_{Y|X=x}(y|x)g(x,y)\\ &=\sum_x\sum_yp_X(x)p_{Y|X=x}(y|x)g(x,y)\\ &=\sum_x\sum_yp_{X,Y}(x,y)g(x,y)\\ &=\mathbb{E}_{X,Y}[g(X,Y)] \end{align} $$

The final proof.

$$ \begin{align} \nabla J(\theta)&=\mathbb{E}_{S_t,A_t}\left[q_\pi(S_t,A_t)\nabla\ln\pi_\theta(A_t|S_t)\right]\\ &=\mathbb{E}_{S_t,A_t}\Big[\mathbb{E}_{G_t|S_t,A_t}[G_t|S_t,A_t]\nabla\ln\pi_\theta(A_t|S_t)\Big]\tag{Definition of $q$}\\ &=\mathbb{E}_{S_t,A_t}\Big[\mathbb{E}_{G_t|S_t,A_t}\big[G_t\nabla\ln\pi_\theta(A_t|S_t)|S_t,A_t\big]\Big]\tag{Fact 1.}\\ &=\mathbb{E}_{G_t,S_t,A_t}\big[G_t\nabla\ln\pi_\theta(A_t|S_t)\big]\tag{Fact 2.} \end{align} $$

(Note: for applying fact 2, here $(S_t,A_t)$ is the $X$, and $G_t$ is the $Y$.)

$\endgroup$
2
  • $\begingroup$ This was great, thanks. $\endgroup$
    – jcaliz
    Commented Aug 25, 2021 at 22:18
  • $\begingroup$ Thanks for the answer. In fact 1, your proof is for a conditional expected value giving a particular value $Y=y$, but in PG formula the it's conditioned on RV $Y$. I am too struggling with this derivation on the book. RL course on YT based on the book usually skip this derivation which is kind of sad... $\endgroup$ Commented Aug 31, 2021 at 2:11
0
$\begingroup$

The expectation of an expectation of a random variable (using the same assumptions, such as following the policy as here) is the same as the expectation of the random variable.

$$\mathbb{E}[\mathbb{E}[X|Y]] = \mathbb{E}[X]$$

(provided $X$ and $Y$ are drawn from same probability space)

This rule appears with various names, but Wikipedia has it as the law of total expectation.

$\endgroup$
5
  • $\begingroup$ I'm familiar with the law of total expectation. It is not applicable here unfortunately. $\endgroup$
    – Miguel
    Commented Oct 2, 2018 at 9:56
  • $\begingroup$ @Miguel: Can you explain why it is not applicable here? $G_t$, $S_t$ and $A_t$ all seem to be drawn from same space, which is the only constraint. $\endgroup$ Commented Oct 2, 2018 at 10:01
  • $\begingroup$ Because the expression is of the form $\mathbb{E}[\mathbb{E}[X|Y]\cdot Z]$ and not $\mathbb{E}[\mathbb{E}[X|Y]]$ $\endgroup$
    – Miguel
    Commented Oct 2, 2018 at 13:50
  • $\begingroup$ I think there is something more subtle going on here with the notation. In particular, the expectation in the first line is w.r.t $S_t$ and $A_t$, and the action value function is an expectation w.r.t $G_t$ conditional on $S_t$ and $A_t$. Putting this all together, the expectation in the third line should be w.r.t. $S_t$, $A_t$ and $G_t$. What is confusing is that the notation $\mathbb{E}_{\pi}[\cdot]$ is used for all of these different expectations. $\endgroup$
    – Miguel
    Commented Oct 2, 2018 at 14:17
  • $\begingroup$ @Miguel You can take the intermediate step you wrote and move what you're calling "Z" into the inner expectation, because your Z is a deterministic function of what you're calling "Y". It's "taking out what is known" in reverse. Guo Shuai's answer explains it in detail. $\endgroup$
    – DavidR
    Commented Apr 7, 2021 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.