2

In per-decison importance sampling given in Sutton & Barto's book:

Eq 5.12 $\rho_{t:T-1}R_{t+k} = \frac{\pi(A_{t}|S_{t})}{b(A_{t}|S_{t})}\frac{\pi(A_{t+1}|S_{t+1})}{b(A_{t+1}|S_{t+1})}\frac{\pi(A_{t+2}|S_{t+2})}{b(A_{t+2}|S_{t+2})}......\frac{\pi(A_{T-1}|S_{T-1})}{b(A_{T-1}|S_{T-1})}R_{t+k}$

Eq 5.13 $\mathbb{E}\left[\frac{\pi(A_{k}|S_{k})}{b(A_{k}|S_{k})}\right] = \displaystyle\sum_ab(a|S_k)\frac{\pi(A_{k}|S_{k})}{b(A_{k}|S_{k})} = \displaystyle\sum_a\pi(a|S_k) = 1$

Eq.5.14 $\mathbb{E}[\rho_{t:T-1}R_{t+k}] = \mathbb{E}[\rho_{t:t+k-1}R_{t+k}]$

As full derivation is not given, how do we arrive at Eq 5.14 from 5.12?

From what i understand :

1) $R_{t+k}$ is only dependent on action taken at $t+k-1$ given state at that time i.e. only dependent on $\frac{\pi(A_{t+k-1}|S_{t+k-1})}{b(A_{t+k-1}|S_{t+k-1})}$

2) $\frac{\pi(A_{k}|S_{k})}{b(A_{k}|S_{k})}$ is independent of $\frac{\pi(A_{k+1}|S_{k+1})}{b(A_{k+1}|S_{k+1})}$ , so $\mathbb{E}\left[\frac{\pi(A_{k}|S_{k})}{b(A_{k}|S_{k})}\frac{\pi(A_{k+1}|S_{k+1})}{b(A_{k+1}|S_{k+1})}\right] = \mathbb{E}\left[\frac{\pi(A_{k}|S_{k})}{b(A_{k}|S_{k})}\right]\mathbb{E}\left[\frac{\pi(A_{k+1}|S_{k+1})}{b(A_{k+1}|S_{k+1})}\right], \forall \, k\in [t,T-2]$

Hence, $\mathbb{E}[\rho_{t:T-1}R_{t+k}]= \mathbb{E}\left[\frac{\pi(A_{t}|S_{t})}{b(A_{t}|S_{t})}\frac{\pi(A_{t+1}|S_{t+1})}{b(A_{t+1}|S_{t+1})}\frac{\pi(A_{t+2}|S_{t+2})}{b(A_{t+2}|S_{t+2})}......\frac{\pi(A_{T-1}|S_{T-1})}{b(A_{T-1}|S_{T-1})}R_{t+k}\right] \\= \mathbb{E}\left[\frac{\pi(A_{t}|S_{t})}{b(A_{t}|S_{t})}\frac{\pi(A_{t+1}|S_{t+1})}{b(A_{t+1}|S_{t+1})}\frac{\pi(A_{t+2}|S_{t+2})}{b(A_{t+2}|S_{t+2})}....\frac{\pi(A_{t+k-2}|S_{t+k-2})}{b(A_{t+k-2}|S_{t+k-2})}\frac{\pi(A_{t+k}|S_{t+k})}{b(A_{t+k}|S_{t+k})}......\frac{\pi(A_{T-1}|S_{T-1})}{b(A_{T-1}|S_{T-1})}\right]\mathbb{E}\left[\frac{\pi(A_{t+k-1}|S_{t+k-1})}{b(A_{t+k-1}|S_{t+k-1})}R_{t+k}\right] \\= \mathbb{E}\left[\frac{\pi(A_{t}|S_{t})}{b(A_{t}|S_{t})}\right]\mathbb{E}\left[\frac{\pi(A_{t+1}|S_{t+1})}{b(A_{t+1}|S_{t+1})}\right]\mathbb{E}\left[\frac{\pi(A_{t+2}|S_{t+2})}{b(A_{t+2}|S_{t+2})}\right]....\mathbb{E}\left[\frac{\pi(A_{t+k-2}|S_{t+k-2})}{b(A_{t+k-2}|S_{t+k-2})}\right]\mathbb{E}\left[\frac{\pi(A_{t+k}|S_{t+k})}{b(A_{t+k}|S_{t+k})}\right]......\mathbb{E}\left[\frac{\pi(A_{T-1}|S_{T-1})}{b(A_{T-1}|S_{T-1})}\right]\mathbb{E}\left[\frac{\pi(A_{t+k-1}|S_{t+k-1})}{b(A_{t+k-1}|S_{t+k-1})}R_{t+k}\right] \\= \mathbb{E}[\frac{\pi_{t+k-1}}{b_{t+k-1}}R_{t+k}]\\=\mathbb{E}[\rho_{t+k-1}R_{t+k}]$

which is not equal to eq 5.14. What's the mistake in the above calculations? Are 1 and 2 correct?

ZERO NULLS
  • 147
  • 8
  • To answer your last question, in general, the expectation of the product of two random variables is not equal to the product of the expectations of each random variable, unless the random variables are independent. That doesn't seem to be true in your case (given that the policies at successive time steps could be correlated), but I could be wrong (because I know little or almost nothing about importance sampling and related topics). – nbro Jun 13 '20 at 16:50
  • I don't think policies at successive time steps are correlated, otherwise there would have been no point of giving eq 5.13. Also in theory given in the book, $\pi$ is sometimes taken as epsilon-greedy which is not correlated – ZERO NULLS Jun 13 '20 at 22:17
  • You made a mistake in step 2. State $S_{k+1}$ depends on $S_k$ and $A_k$ through conditional probability $p(s'|s,a)$ so you cant do what you did. – Brale Jun 14 '20 at 08:06
  • $S_{k+1}$ is indeed dependent on $S_k$ but $A_k|S_k $ is independent of $A_{k+1}|S_{k+1}$ because $P(A_k|S_k)$ means, given $S_k = s$, what's the probability of choosing $A_k = a$ , similarly for $P(A_{k+1}|S_{k+1})$ . Hence since we are given $S_{k+1} = s'$, there is no need to calculate $p(s'|s,a)$. Is something wrong in this way of thinking?? – ZERO NULLS Jun 14 '20 at 22:07

2 Answers2

1

As mentioned in the comments your assumption about independence is wrong. Here's why. To prove independence we need to show the following holds:

P(X=x,Y=y)=P(X=x)P(Y=y)

in the case of RL this becomes:

P(X=a,X=a)=P(X=a)P(Y=a)

The left hand side has the value:

P(X=a,Y=a)=b(At=a|St=s)p(s|a,s)b(At+1=a|,St+1=s)

while the right hand side has the value:

P(X=a)P(Y=a)=b(At=a|St=s)b(At+1=a|St+1=s)

And hence not independent.

Now let use look at why the following expression holds:

Eq.5.14: $\mathbb{E}[\rho_{t:T-1}R_{t+k}] = \mathbb{E}[\rho_{t:t+k-1}R_{t+k}]$

I will not derive the exact expressions, but I hope you can form the reasoning I provide. By the rules of probability we know that sum of joint probability is equal to 1 i.e.:

X1..XnP(X1=a1,X2=a2,...Xn=an)=1

I have alredy showed above, the trajectory is not independent. So $R_{t+k}$ will depend on the trajectory $S_{t:t+k-1}$ where $S_{t:t+k-1}$ is a particular trajectory. At the end of this trajectory we get a reward $R_{t+k}$ and thus $R_{t+k}$ is exclusively a function of $S_{t:t+k-1}$ i.e. $R_{t+k} = f(S_{t:t+k-1})$. The trajectory after this $S_{t+k:T-1}$ irrelevant since it will always sum up of to 1. i.e once you have reached a particular state at time step $t+k-1$ you are now conditioning based on that $P(S_{t+k:T-1}|S_{t:t+k-1})$ and taking the expected value over all trajectories possible from thereon i.e. $\sum_{S_{t+k:T-1}} P(S_{t+k:T-1}|S_{t:t+k-1})$ which is 1 by probability rules. Thus, what you are really doing is:

P(St:t+k1)Rt+k(St+k:T1P(St+k:T1|St:t+k1))

and hence the remaining trajectory has no contribution.

Another way of thinking this is you are taking weighted trajectories till time step $t+k-1$ weighted by rewards $R_{t+k}$ and hence you cannot sum up to 1. The rest of the trajectory after $t+k-1$ will sum up to 1.

I hope this qualitative description suffices. You can do the maths, but you must be careful with the notations and the assumptions you make.

Also all the equations are correct, I hope you can indirectly see it from my reasoning.

  • unable to understand this step: P(X=a,Y=a)=b(At=a|St=s)p(s|a,s)b(At+1=a|,St+1=s)
    , after solving it, the right hand side of this equation gives $p(s',a',a|s)$ which is not equal to p(a,a').
    – ZERO NULLS Sep 15 '20 at 06:55
  • @SAHAJGUPTA wait did you get it. You marked the answer as accepted, or should I explain? –  Sep 15 '20 at 11:53
  • Yep I think you are correct...I made a notaional mistake....what I meant to write was $X=a|s, Y=a'|s'$. I think this makes sense now. –  Sep 15 '20 at 12:26
0

First Part

We can reduce variance in off-policy importance sapling, even in the absence of discounting ($\gamma = 1$). Notice that the off-policy estimators are made up of terms like ρt:T1Gt=ρt:T1(Rt+1+γRt+2++γTt1RT)

and consider the second term, imagine $\gamma$=$1$: ρt:T1Rt+2=π(At|St)π(At+1|St+1)......π(AT1|ST1)b(At|St)b(At+1|St+1)......b(AT1|ST1)Rt+2

In above equation, the term $\pi(A_t|S_t)$, $\pi(A_{t+1}|S_{t+1})$, $R_{t+2}$ are correleated, all the other terms are independent of each other.

Notice the very import property of expectation: $E[ab] = E[a] E[b]$ if and only if $a$, $b$ are independent random variables.

Now: E[π(At|St)π(At+1|St+1).....π(AT1|ST1)b(At|St)b(At+1|St+1).....b(AT1|ST1)Rt+2]

=E[π(At|St)π(At+1|St+1)b(At|St)b(At+1|St+1)Rt+2]E[π(At+2|St+2)b(At+2|St+2)].....E[π(AT1|ST1)b(AT1|ST1)]
=E[π(At|St)π(At+1|St+1)b(At|St)b(At+1|St+1)Rt+2]ab(a|st+2)π(a|st+2b(a|st+2.....ab(a|sT1)π(a|sT1b(a|sT1
=E[π(At|St)π(At+1|St+1)b(At|St)b(At+1|St+1)Rt+2]aπ(a|st+2).....aπ(a|sT1)

=E[π(At|St)π(At+1|St+1)b(At|St)b(At+1|St+1)Rt+2]11
=E[π(At|St)π(At+1|St+1)b(At|St)b(At+1|St+1)Rt+2]
therefore E[ρt:T1Rt+2]=E[ρt:t+1Rt+2]
If we repeat this analysis for the $k$th term, we will get: E[ρt:T1Rt+k]=E[ρt:t+k1Rt+k]
It follows that the expectation of our original term can be written: E[ρt:T1Gt]=E[~Gt]
where ˜Gtρt:tRt+1+γρt:t+1Rt+2+γ2ρt:t+2Rt+3+......+γTt1ρt:T1RT
We call this idea per reward importance sampling. It follows immediately that there is an alternative importance sampling estimate, with the same unbiased expectation as the ordinary importance sampling estimate: V(s)tT(s)˜Gt|T(s)|
which we might expect to sometimes be of lower variance.

Second Part

The reward $R_{k+1}$ depends on the previous $\pi(a_1|s_1)$ up to $\pi(a_{k-1}|s_{k-1})$. So, you can't seperate them and treat them as independent variable just you did on the aforementioned example.

Swakshar Deb
  • 673
  • 4
  • 12