# Four Identities for RL used in TRPO

In this blog post, I will present four useful identities that give some theoretical insight on advantage and value functions in reinforcement learning. These identities are useful in proving the theoretical correctness of the non-decreasing expected return policy iteration algorithm in the paper "Trust Region Policy Optimization" (TRPO) - Schulman et al, 2015, https://arxiv.org/abs/1502.05477. I would like to note that readers should be familiar with the reinforcement learning terminology and notation from the TRPO paper before reading this post. Finally, I encourage the reader to try proving the identities themselves if they feel, like me, the need to keep their math skills sharp when you no longer have problem sets and exams to do.

### Identity 1

First, the expected value of the advantage function using an action sampled from it’s own policy is zero. Intuitively this makes sense, because the advantage function for a state $s$$s$ss and an action $a$$a$aa measures how much better that action is relative to the “average” action taken at the state $s$$s$ss. The “average” action is not better or worse than itself, hence the identity:
$\begin{array}{}\text{(1)}& {\mathbb{E}}_{a\sim \pi \mid s}\left[{A}_{\pi }\left(s,a\right)\right]=0\end{array}$$\begin{array}{}\text{(1)}& {\mathbb{E}}_{a\sim \pi \mid s}\left[{A}_{\pi }\left(s,a\right)\right]=0\end{array}${:(1)E_(a∼pi∣s)[A_(pi)(s,a)]=0:}$$\mathbb{E}_{a \sim \pi \mid s}\left[A_{\pi}(s, a)\right]=0$$
Proof of Identity [1]:
$\begin{array}{rl}{\mathbb{E}}_{a\sim \pi \mid s}\left[{A}_{\pi }\left(s,a\right)\right]& ={\mathbb{E}}_{a\sim \pi \mid s}\left[{Q}_{\pi }\left(s,a\right)-{V}_{\pi }\left(s\right)\right]\\ & ={\mathbb{E}}_{a\sim \pi \mid s}\left[{Q}_{\pi }\left(s,a\right)-{\mathbb{E}}_{a\sim \pi \mid s}\left[{Q}_{\pi }\left(s,a\right)\right]\right]\\ & =0\end{array}$$\begin{array}{r}{\mathbb{E}}_{a\sim \pi \mid s}\left[{A}_{\pi }\left(s,a\right)\right]={\mathbb{E}}_{a\sim \pi \mid s}\left[{Q}_{\pi }\left(s,a\right)-{V}_{\pi }\left(s\right)\right]\\ ={\mathbb{E}}_{a\sim \pi \mid s}\left[{Q}_{\pi }\left(s,a\right)-{\mathbb{E}}_{a\sim \pi \mid s}\left[{Q}_{\pi }\left(s,a\right)\right]\right]\\ =0\end{array}${:[E_(a∼pi∣s)[A_(pi)(s,a)]=E_(a∼pi∣s)[Q_(pi)(s,a)-V_(pi)(s)]],[=E_(a∼pi∣s)[Q_(pi)(s,a)-E_(a∼pi∣s)[Q_(pi)(s,a)]]],[=0]:}\begin{aligned} \mathbb{E}_{a \sim \pi \mid s}\left[A_{\pi}(s, a)\right] &=\mathbb{E}_{a \sim \pi \mid s}\left[Q_{\pi}(s, a)-V_{\pi}(s)\right] \\ & =\mathbb{E}_{a \sim \pi \mid s}\left[Q_{\pi}(s, a)-\mathbb{E}_{a \sim \pi \mid s}\left[Q_{\pi}(s, a)\right]\right] \\ & = 0 \end{aligned}
Here we used an identity from probability: $\mathbb{E}\left[X-\mathbb{E}\left[X\right]\right]=0$$\mathbb{E}\left[X-\mathbb{E}\left[X\right]\right]=0$E[X-E[X]]=0\mathbb{E}[X-\mathbb{E}[X]]=0. You can reason that this makes sense intuitively, or you can prove it mathematically (hint: E[E[X]] = E[X] from the Appendix of this post).

### Identity 2

The second identity I will present shows another way to describe the state-action value function Q:
$\begin{array}{}\text{(2)}& {Q}_{\pi }\left(s,a\right)=r\left(s\right)+\gamma {\mathbb{E}}_{{s}^{\mathrm{\prime }}\sim P\left({s}^{\mathrm{\prime }}\mid s,a\right)}\left[{V}_{\pi }\left({s}^{\mathrm{\prime }}\right)\right]\end{array}$$\begin{array}{}\text{(2)}& {Q}_{\pi }\left(s,a\right)=r\left(s\right)+\gamma {\mathbb{E}}_{{s}^{\mathrm{\prime }}\sim P\left({s}^{\mathrm{\prime }}\mid s,a\right)}\left[{V}_{\pi }\left({s}^{\mathrm{\prime }}\right)\right]\end{array}${:(2)Q_(pi)(s","a)=r(s)+gammaE_(s^(')∼P(s^(')∣s,a))[V_(pi)(s^('))]:}$$Q_{\pi}(s, a)= r(s) + \gamma \mathbb{E}_{s^{\prime} \sim P\left(s^{\prime} \mid s, a\right)}\left[V_{\pi}\left(s^{\prime}\right)\right]$$
Proof of Identity [2] (omitting the $\sim \pi$$\sim \pi$∼pi\sim \pi and $\sim P$$\sim P$∼P\sim P symbols for brevity):
From the definition of Q:
$\begin{array}{rl}{Q}_{\pi }\left({s}_{t},{a}_{t}\right)& ={\mathbb{E}}_{{s}_{t+1},{a}_{t+1}}\dots \left[\sum _{l=0}^{\mathrm{\infty }}{\gamma }^{l}r\left({s}_{t+l}\right)\right]\\ & =r\left({s}_{t}\right)+{\mathbb{E}}_{{s}_{t+1},{a}_{t+1}}\dots \left[\sum _{l=1}^{\mathrm{\infty }}{\gamma }^{l}r\left({s}_{t+l}\right)\right]\\ & =r\left({s}_{t}\right)+{\mathbb{E}}_{{s}_{t+1},{a}_{t+1}}\dots \left[\sum _{l=0}^{\mathrm{\infty }}{\gamma }^{l+1}r\left({s}_{t+1+l}\right)\right]\\ & =r\left({s}_{t}\right)+\gamma {\mathbb{E}}_{{s}_{t+1},{a}_{t+1}}\dots \left[\sum _{l=0}^{\mathrm{\infty }}{\gamma }^{l}r\left({s}_{t+1+l}\right)\right]\\ & =r\left({s}_{t}\right)+\gamma {\mathbb{E}}_{{s}_{t+1}}\left[{\mathbb{E}}_{{a}_{t+1}}\dots \left[\sum _{l=0}^{\mathrm{\infty }}{\gamma }^{l}r\left({s}_{t+1+l}\right)\right]\right]\\ & =r\left({s}_{t}\right)+\gamma {\mathbb{E}}_{{s}_{t+1}}\left[{V}_{\pi }\left({s}_{t+1}\right)\right]\\ & \text{by definition of}{V}_{\pi }\text{}◻\end{array}${:[Q_(pi)(s_(t),a_(t))=E_(s_(t+1),a_(t+1))dots[sum_(l=0)^(oo)gamma^(l)r(s_(t+l))]],[=r(s_(t))+E_(s_(t+1),a_(t+1))dots[sum_(l=1)^(oo)gamma^(l)r(s_(t+l))]],[=r(s_(t))+E_(s_(t+1),a_(t+1))dots[sum_(l=0)^(oo)gamma^(l+1)r(s_(t+1+l))]],[=r(s_(t))+gammaE_(s_(t+1),a_(t+1))dots[sum_(l=0)^(oo)gamma^(l)r(s_(t+1+l))]],[=r(s_(t))+gammaE_(s_(t+1))[E_(a_(t+1))dots[sum_(l=0)^(oo)gamma^(l)r(s_(t+1+l))]]],[=r(s_(t))+gammaE_(s_(t+1))[V_(pi)(s_(t+1))]],["by definition of "(V_(pi))◻]:}\begin{aligned} Q_{\pi}\left(s_{t}, a_{t}\right) &= \mathbb{E}_{s_{t+1}, a_{t+1}} \ldots\left[\sum_{l=0}^{\infty} \gamma^{l} r\left(s_{t+l}\right)\right] \\ &= r(s_t) + \mathbb{E}_{s_{t+1}, a_{t+1}} \ldots\left[\sum_{l=1}^{\infty} \gamma^{l} r\left(s_{t+l}\right)\right] \\ &= r(s_t) + \mathbb{E}_{s_{t+1}, a_{t+1}} \ldots\left[\sum_{l=0}^{\infty} \gamma^{l+1} r\left(s_{t+1+l}\right)\right] \\ &= r(s_t) + \gamma \mathbb{E}_{s_{t+1}, a_{t+1}} \ldots\left[\sum_{l=0}^{\infty} \gamma^{l} r\left(s_{t+1+l}\right)\right] \\ &= r(s_t) + \gamma \mathbb{E}_{s_{t+1}}\left[\mathbb{E}_{a_{t+1}} \ldots\left[\sum_{l=0}^{\infty} \gamma^{l} r\left(s_{t+1+l}\right)\right]\right]\\ &= r(s_t) + \gamma \mathbb{E}_{s_{t+1}}\left[V_{\pi}(s_{t+1})\right]\\ & \text{by definition of $V_{\pi}$} \space \square \end{aligned}
In plain English, we can reason that this makes sense. The Q function is giving you the expected discounted return sampled from all possible future states when taking action $a$$a$aa in the current state $s$$s$ss in addition to the reward of the current state $s$$s$ss.

### Identity 3

The advantage function can be expressed without the state-action value function:
$\begin{array}{}\text{(3)}& {A}_{\pi }\left(s,a\right)={\mathbb{E}}_{{s}^{\mathrm{\prime }}\sim P\left({s}^{\mathrm{\prime }}\mid s,a\right)}\left[r\left(s\right)+\gamma {V}_{\pi }\left({s}^{\mathrm{\prime }}\right)-V\left(s\right)\right]\end{array}$$\begin{array}{}\text{(3)}& {A}_{\pi }\left(s,a\right)={\mathbb{E}}_{{s}^{\mathrm{\prime }}\sim P\left({s}^{\mathrm{\prime }}\mid s,a\right)}\left[r\left(s\right)+\gamma {V}_{\pi }\left({s}^{\mathrm{\prime }}\right)-V\left(s\right)\right]\end{array}${:(3)A_(pi)(s","a)=E_(s^(')∼P(s^(')∣s,a))[r(s)+gammaV_(pi)(s^('))-V(s)]:}$$A_{\pi}(s, a)=\mathbb{E}_{s^{\prime} \sim P\left(s^{\prime} \mid s, a\right)}\left[r(s)+\gamma V_{\pi}\left(s^{\prime}\right)-V(s)\right]$$
Proof of equation [3]: Use Identity [2] and the definition of the advantage function ${A}_{\pi }\left(s,a\right)={Q}_{\pi }\left(s,a\right)-{V}_{\pi }\left(s\right)$${A}_{\pi }\left(s,a\right)={Q}_{\pi }\left(s,a\right)-{V}_{\pi }\left(s\right)$A_(pi)(s,a)=Q_(pi)(s,a)-V_(pi)(s)A_{\pi}(s,a) = Q_{\pi}(s, a) - V_{\pi}(s):
${A}_{\pi }\left(s,a\right)=r\left(s\right)+\gamma {\mathbb{E}}_{{s}^{\mathrm{\prime }}\sim P\left({s}^{\mathrm{\prime }}\mid s,a\right)}\left[{V}_{\pi }\left({s}^{\mathrm{\prime }}\right)\right]-{V}_{\pi }\left(s\right)$${A}_{\pi }\left(s,a\right)=r\left(s\right)+\gamma {\mathbb{E}}_{{s}^{\mathrm{\prime }}\sim P\left({s}^{\mathrm{\prime }}\mid s,a\right)}\left[{V}_{\pi }\left({s}^{\mathrm{\prime }}\right)\right]-{V}_{\pi }\left(s\right)$A_(pi)(s,a)=r(s)+gammaE_(s^(')∼P(s^(')∣s,a))[V_(pi)(s^('))]-V_(pi)(s)A_{\pi}(s, a)=r(s)+\gamma \mathbb{E}_{s^{\prime} \sim P\left(s^{\prime} \mid s, a\right)}\left[V_{\pi}\left(s^{\prime}\right)\right]-V_{\pi}(s)
Then move all terms that are constant w.r.t. the sampling distribution into the expectation braces. $◻$$◻$\square

### Identity 4

The final identity that I will present is an identity for the difference between the expected discounted returns of two policies $\stackrel{~}{\pi }$$\stackrel{~}{\pi }$tilde(pi)\tilde{\pi} and $\pi$$\pi$pi\pi. This difference is equal to the expected accumulated discounted advantages that would be obtained by following policy $\pi$$\pi$pi\pi but on a trajectory actually followed by policy $\stackrel{~}{\pi }$$\stackrel{~}{\pi }$tilde(pi)\tilde{\pi}.
$\begin{array}{}\text{(4)}& \eta \left(\stackrel{~}{\pi }\right)-\eta \left(\pi \right)={\mathbb{E}}_{\tau \sim \stackrel{~}{\pi }}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}{A}_{\pi }\left({s}_{t},{a}_{t}\right)\right]\end{array}$$\begin{array}{}\text{(4)}& \eta \left(\stackrel{~}{\pi }\right)-\eta \left(\pi \right)={\mathbb{E}}_{\tau \sim \stackrel{~}{\pi }}\left[\sum _{t=0}^{\mathrm{\infty }} {\gamma }^{t}{A}_{\pi }\left({s}_{t},{a}_{t}\right)\right]\end{array}${:(4)eta( tilde(pi))-eta(pi)=E_(tau∼ tilde(pi))[sum_(t=0)^(oo)gamma^(t)A_(pi)(s_(t),a_(t))]:}$$\eta(\tilde{\pi}) - \eta(\pi) = \mathbb{E}_{\tau \sim \tilde{\pi}}\left[\sum_{t=0}^{\infty} \gamma^{t} A_{\pi}\left(s_{t}, a_{t}\right)\right]$$
The intuitive way of understanding this equation is that if $\stackrel{~}{\pi }$$\stackrel{~}{\pi }$tilde(pi)\tilde{\pi} is better than $\pi$$\pi$pi\pi, then on average (but favoring earlier states and actions through the discount $\gamma$$\gamma$gamma\gamma), the value-functions that follow the imperfect policy $\pi$$\pi$pi\pi at given states like the actions that policy $\stackrel{~}{\pi }$$\stackrel{~}{\pi }$tilde(pi)\tilde{\pi} chooses more.
The proof of Identity [4] is in the TRPO paper, and assumes that you accept Identity 3 and understand some probability algebra. I will rewrite it here with more detail. I will also explicity show that the trajectory $\tau$$\tau$tau\tau not only depends on the policy $\stackrel{~}{\pi }$$\stackrel{~}{\pi }$tilde(pi)\tilde{\pi}, but also the start state distribution $\rho \left(\cdot \right)$$\rho \left(\cdot \right)$rho(*)\rho(\cdot) and the transition function $P\left({s}^{\prime }|s,a\right)$$P\left({s}^{\prime }|s,a\right)$P(s^(')|s,a)P(s’ | s, a). This would be a bit excessive to notate in the paper, but I’ll notate it here to minimize any chance of confusion.
$\begin{array}{rl}& {\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}{A}_{\pi }\left({s}_{t},{a}_{t}\right)\right]\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[{\mathbb{E}}_{{s}_{t+1}\sim P\left({s}_{t+1}\mid {s}_{t},{a}_{t}\right)}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}\left(r\left({s}_{t}\right)+\gamma {V}_{\pi }\left({s}_{t+1}\right)-{V}_{\pi }\left({s}_{t}\right)\right)\right]\right]\\ & \text{see Appendix}\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}\left(r\left({s}_{t}\right)+\gamma {V}_{\pi }\left({s}_{t+1}\right)-{V}_{\pi }\left({s}_{t}\right)\right)\right]\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)+\sum _{t=0}^{\mathrm{\infty }}\left({\gamma }^{t+1}{V}_{\pi }\left({s}_{t+1}\right)-{\gamma }^{t}{V}_{\pi }\left({s}_{t}\right)\right)\right]\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)\right]+{\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}\left({\gamma }^{t+1}{V}_{\pi }\left({s}_{t+1}\right)-{\gamma }^{t}{V}_{\pi }\left({s}_{t}\right)\right)\right]\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)\right]+{\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\underset{t\to \mathrm{\infty }}{lim}{\gamma }^{t}{V}_{\pi }\left({s}_{t}\right)-{V}_{\pi }\left({s}_{0}\right)+\sum _{t=1}^{\mathrm{\infty }-1}\left({\gamma }^{t}{V}_{\pi }\left({s}_{t}\right)-{\gamma }^{t}{V}_{\pi }\left({s}_{t}\right)\right)\right]\\ & \text{assuming our discount factor}\gamma \in \left(0,1\right)\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)\right]-{\mathbb{E}}_{{s}_{0},{a}_{0},{s}_{1},\cdots \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[{V}_{\pi }\left({s}_{0}\right)\right]\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)\right]-{\mathbb{E}}_{{s}_{0}\sim \rho \left(\cdot \right)}\left[{V}_{\pi }\left({s}_{0}\right)\right]\\ & ={\mathbb{E}}_{\tau \sim \rho \left(\cdot \right),\stackrel{~}{\pi },P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)\right]-{\mathbb{E}}_{{s}_{0}\sim \rho \left(\cdot \right)}\left[{\mathbb{E}}_{{a}_{0},{s}_{1},{a}_{1},\cdots \sim \pi ,P}\left[\sum _{t=0}^{\mathrm{\infty }}{\gamma }^{t}r\left({s}_{t}\right)\right]\right]\\ & =\eta \left(\stackrel{~}{\pi }\right)-\eta \left(\pi \right)& ◻\end{array}${:[E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)A_(pi)(s_(t),a_(t))]],[=E_(tau∼rho(*), tilde(pi),P)[E_(s_(t+1)∼P(s_(t+1)∣s_(t),a_(t)))[sum_(t=0)^(oo)gamma^(t)(r(s_(t))+gammaV_(pi)(s_(t+1))-V_(pi)(s_(t)))]]],["see Appendix"],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)(r(s_(t))+gammaV_(pi)(s_(t+1))-V_(pi)(s_(t)))]],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))+sum_(t=0)^(oo)(gamma^(t+1)V_(pi)(s_(t+1))-gamma ^(t)V_(pi)(s_(t)))]],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))]+E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)(gamma^(t+1)V_(pi)(s_(t+1))-gamma ^(t)V_(pi)(s_(t)))]],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))]+E_(tau∼rho(*), tilde(pi),P)[lim_(t rarr oo)gamma ^(t)V_( pi)(s_(t))-V_( pi)(s_(0))+sum_(t=1)^(oo-1)(gamma^(t)V_(pi)(s_(t))-gamma ^(t)V_(pi)(s_(t)))]],["assuming our discount factor "(gamma in(0,1))],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))]-E_(s_(0),a_(0),s_(1),cdots∼rho(*), tilde(pi),P)[V_( pi)(s_(0))]],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))]-E_(s_(0)∼rho(*))[V_( pi)(s_(0))]],[=E_(tau∼rho(*), tilde(pi),P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))]-E_(s_(0)∼rho(*))[E_(a_(0),s_(1),a_(1),cdots∼pi,P)[sum_(t=0)^(oo)gamma^(t)r(s_(t))]]],[=eta( tilde(pi))-eta(pi)◻]:}\begin{aligned} &\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[\sum_{t=0}^{\infty} \gamma^{t} A_{\pi}\left(s_{t}, a_{t}\right)\right] \\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \mathbb{E}_{s_{t+1} \sim P(s_{t+1} \mid s_t, a_t)} \left[\sum_{t=0}^{\infty} \gamma^{t}\left(r\left(s_{t}\right)+\gamma V_{\pi}\left(s_{t+1}\right)-V_{\pi}\left(s_{t}\right)\right)\right]\right]\\ & \text{see Appendix}\\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}\left(r\left(s_{t}\right)+\gamma V_{\pi}\left(s_{t+1}\right)-V_{\pi}\left(s_{t}\right)\right)\right]\\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right)+\sum_{t=0}^{\infty}\left(\gamma^{t+1} V_{\pi}\left(s_{t+1}\right)-\gamma^t V_{\pi}\left(s_{t}\right)\right)\right]\\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right)\right] + \mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[\sum_{t=0}^{\infty}\left(\gamma^{t+1} V_{\pi}\left(s_{t+1}\right)-\gamma^t V_{\pi}\left(s_{t}\right)\right)\right] \\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right)\right] + \mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \lim_{t \rightarrow \infty} \gamma^t V_\pi (s_t) - V_\pi (s_0) + \sum_{t=1}^{\infty-1}\left(\gamma^{t} V_{\pi}\left(s_{t}\right)-\gamma^t V_{\pi}\left(s_{t}\right)\right)\right] \\ & \text{assuming our discount factor $\gamma \in (0, 1)$}\\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right)\right] - \mathbb{E}_{s_0, a_0, s_1, \cdots \sim \rho(\cdot), \tilde{\pi}, P}\left[V_\pi(s_0) \right] \\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right)\right]- \mathbb{E}_{s_0 \sim \rho(\cdot)}\left[V_\pi(s_0) \right] \\ &=\mathbb{E}_{\tau \sim \rho(\cdot), \tilde{\pi}, P}\left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right)\right] - \mathbb{E}_{s_0 \sim \rho(\cdot)}\left[\mathbb{E}_{a_0, s_1, a_1, \cdots \sim \pi, P} \left[ \sum_{t=0}^{\infty} \gamma^{t}r\left(s_{t}\right) \right] \right]\\ &= \eta(\tilde{\pi}) - \eta(\pi) & \square \end{aligned}
The way in which Identity [4] is used is to theoretically guarantee an improving policy. If you can somehow update your policy from $\pi$$\pi$pi\pi to $\stackrel{~}{\pi }$$\stackrel{~}{\pi }$tilde(pi)\tilde{\pi} while guaranteeing the RHS of Identity [4] is non-negative, then the new policy is in the worst case just as good as the old policy.

## Appendix: Some probability algebra

Below is a very important result of probability algebra that the TRPO paper assumes you know. Assume ${\rho }_{1}$${\rho }_{1}$rho_(1)\rho_1 and ${\rho }_{2}$${\rho }_{2}$rho_(2)\rho_2 are continuous probability distributions. Then,
$\begin{array}{}\text{(5)}& {\mathbb{E}}_{x\sim {\rho }_{1},y\sim {\rho }_{2}}\left[{\mathbb{E}}_{x\sim {\rho }_{1}}\left[f\left(x,y\right)\right]\right]={\mathbb{E}}_{x\sim {\rho }_{1},y\sim {\rho }_{2}}\left[f\left(x,y\right)\right]\end{array}$$\begin{array}{}\text{(5)}& {\mathbb{E}}_{x\sim {\rho }_{1},y\sim {\rho }_{2}}\left[{\mathbb{E}}_{x\sim {\rho }_{1}}\left[f\left(x,y\right)\right]\right]={\mathbb{E}}_{x\sim {\rho }_{1},y\sim {\rho }_{2}}\left[f\left(x,y\right)\right]\end{array}${:(5)E_(x∼rho_(1),y∼rho_(2))[E_(x∼rho_(1))[f(x,y)]]=E_(x∼rho_(1),y∼rho_(2))[f(x,y)]:}$$\mathbb{E}_{x \sim \rho_1, y \sim \rho_2} \left[ \mathbb{E}_{x \sim \rho_1} \left[ f(x, y) \right] \right] = \mathbb{E}_{x \sim \rho_1, y \sim \rho_2} \left[ f(x, y) \right]$$
Proof by rewriting the expectation on the LHS as integrals:
$\begin{array}{rl}{\int }_{y}{\rho }_{2}\left(y\right){\int }_{x}{\rho }_{1}\left(x\right)\left[{\int }_{z}{\rho }_{1}\left(z\right)f\left(z,y\right)dz\right]dxdy& ={\int }_{y}{\rho }_{2}\left(y\right){\int }_{x}{\rho }_{1}\left(x\right)dx\left[{\int }_{z}{\rho }_{1}\left(z\right)f\left(z,y\right)dz\right]dy\\ & ={\int }_{y}{\rho }_{2}\left(y\right)\left[{\int }_{z}{\rho }_{1}\left(z\right)f\left(z,y\right)dz\right]dy\end{array}$$\begin{array}{r}{\int }_{y} {\rho }_{2}\left(y\right){\int }_{x} {\rho }_{1}\left(x\right)\left[{\int }_{z} {\rho }_{1}\left(z\right)f\left(z,y\right)dz\right]dxdy={\int }_{y} {\rho }_{2}\left(y\right){\int }_{x} {\rho }_{1}\left(x\right)dx\left[{\int }_{z} {\rho }_{1}\left(z\right)f\left(z,y\right)dz\right]dy\\ ={\int }_{y} {\rho }_{2}\left(y\right)\left[{\int }_{z} {\rho }_{1}\left(z\right)f\left(z,y\right)dz\right]dy\end{array}${:[int_(y)rho_(2)(y)int_(x)rho_(1)(x)[int_(z)rho_(1)(z)f(z,y)dz]dxdy=int_(y)rho_(2)(y)int_(x)rho_(1)(x)dx[int_(z)rho_(1)(z)f(z,y)dz]dy],[=int_(y)rho_(2)(y)[int_(z)rho_(1)(z)f(z,y)dz]dy]:}\begin{aligned} \int_{y} \rho_{2}(y) \int_{x} \rho_{1}(x)\left[\int_{z} \rho_{1}(z) f(z, y) d z\right] d x d y &= \int_{y} \rho_{2}(y) \int_{x} \rho_{1}(x) d x \left[\int_{z} \rho_{1}(z) f(z, y) d z\right] d y \\ &= \int_{y} \rho_{2}(y) \left[\int_{z} \rho_{1}(z) f(z, y) d z\right] d y \end{aligned}
because the integral of a probability distribution is 1: ${\int }_{x}{\rho }_{1}\left(x\right)dx=1$${\int }_{x} {\rho }_{1}\left(x\right)dx=1$int_(x)rho_(1)(x)dx=1\int_{x} \rho_{1}(x) d x = 1. This is the continuous analogue of the discrete case, where the sum of chances of all possibilities must be equal to 100%.

# Recommended for you

Srishti Saha
High Dimension Data Analysis - A tutorial and review for Dimensionality Reduction Techniques
High Dimension Data Analysis - A tutorial and review for Dimensionality Reduction Techniques
This article explains and provides a comparative study of a few techniques for dimensionality reduction. It dives into the mathematical explanation of several feature selection and feature transformation techniques, while also providing the algorithmic representation and implementation of some other techniques. Lastly, it also provides a very brief review of various other works done in this space.
29 points
0 issues