# Importance Sampling Ratio Probability

When reading Reinforcement Learning by Sutton and Barto, I came across the importance sampling ratio.

The first equation, I believe, describes the probability a particular sequence is obtained given the current state, and the policy.

The next part takes takes the ratio between the probabilities of the two trajectories:

I don't understand how this ratio could lead to this:

The $$G_t$$ rewards are obtained through the $$b$$ policy, not the $$\pi$$ policy.

I think there is something to do with Bayes Rule, but I could not derive it. Could someone guide me through the derivation?

It has nothing to do with Bayes rule, like you said, $$G_t$$ is the return we get by following the policy $$b$$ , so the value of the state we get that return in is equal to the expected value of that return. On page 59 of the book, equation 3.14 derives the value of the state as expected value of the return but in this case we are following the behaviour policy $$b$$ so you would replace $$\pi (a \mid s)$$ with $$b (a \mid s)$$ and $$v_\pi (s')$$ with $$v_b (s')$$ and you would get the value of the state following the policy $$b$$, that is $$v_b (s)$$.
We are actually interested in the value of the state when we follow target policy $$\pi$$ , but we got the value by following behaviour policy, so we will multiply that expression with importance sampling ratio. If we do that $$b (a \mid s)$$ terms will cancel out and you are only left with term $$\pi (a \mid s)$$ from importance sampling ratio so we will get the value by following the target policy $$\pi$$ that is $$v_\pi (s)$$
• importance sampling ratio for state $s$ is $\pi (a \mid s) / b (a \mid s)$ and $b (a \mid s)$ term in that ratio will cancel out with term $b (a \mid s)$ from first sum in expression 3.14 (the modified one as I described above). Notice that expression 3.14 is recursive so same would apply for value $v_b (s')$ which you would write out the same way as $v_b (s)$ is written out in 3.14, but in that state (state $s'$ ) importance sampling ratio would be $\pi (a \mid s') / b (a \mid s')$ and now terms $b (a \mid s')$ would cancel out and so on, you would keep writing out next states until the end – Brale_ Dec 19 '18 at 20:22