# Why does the state-action value function, defined as an expected value of the reward and state value function, not need to follow a policy?

I often see that the state-action value function is expressed as:

$$q_{\pi}(s,a)=\color{red}{\mathbb{E}_{\pi}}[R_{t+1}+\gamma G_{t+1} | S_t=s, A_t = a] = \color{blue}{\mathbb{E}}[R_{t+1}+\gamma v_{\pi}(s') |S_t = s, A_t =a]$$

Why does expressing the future return in the time $$t+1$$ as a state value function $$v_{\pi}$$ make the expected value under policy change to expected value in general?

• Here is a related question.
– nbro
Jan 24, 2022 at 12:58

Let's first write the state-value function as

$$q_{\pi}(s,a) = \mathbb{E}_{p, \pi}[R_{t+1} + \gamma G_{t+1} | S_t = s, A_t = a]\;,$$

where $$R_{t+1}$$ is the random variable that represents the reward gained at time $$t+1$$, i.e. after we have taken action $$A_t = a$$ in state $$S_t = s$$, while $$G_{t+1}$$ is the random variable that represents the return, the sum of future rewards. This allows us to show that the expectation is taken under the conditional joint distribution $$p(s', r \mid s, a)$$, which is the environment dynamics, and future actions are taken from our policy distribution $$\pi$$.

As $$R_{t+1}$$ depends on $$S_t = s, A_t = a$$ and $$p(s', r \mid s, a)$$, the only random variable in the expectation that is dependent on our policy $$\pi$$ is $$G_{t+1}$$, because this is the sum of future reward signals and so will depend on future state-action values. Thus, we can rewrite again as $$q_{\pi}(s,a) = \mathbb{E}_{p}[R_{t+1} + \gamma \mathbb{E}_{\pi}[ G_{t+1} |S_{t+1} = s'] | S_t = s, A_t = a]\;,$$ where the inner expectation (coupled with the fact its inside an expectation over the state and reward distributions) should look familiar to you as the state value function, i.e. $$\mathbb{E}_{\pi}[ G_{t+1} |S_{t+1} = s'] = v_{\pi}(s')\;.$$ This leads us to get what you have $$q_{\pi}(s,a) = \mathbb{E}_{p}[R_{t+1} + \gamma v_{\pi}(s') | S_t = s, A_t = a]\;,$$ where the only difference is that we have made clear what our expectation is taken with respect to.

The expectation is taken with respect to the conditional joint distribution $$p(s', r \mid s, a)$$, and we usually include the $$\pi$$ subscript to denote that they are also taking the expectation with respect to the policy, but here this does not affect the first term as we have conditioned on knowing $$A_t = a$$ and only applies to the future reward signals.

David Ireland gives a fantastic answer, and I will provide an intuitive and gentle (but less rigorous) answer for those who are unfamiliar with the relevant statistical concepts.

Next reward $$R_{t+1}$$: The next reward $$R_{t+1}$$ is solely dependent on the current state $$S_t$$ and action $$A_t$$. It is only dependent on the policy because the policy details the probability distribution of actions given a state. Since we assume that the current state and action are given when calculating the expectation $$\left(S_t = s, A_t = a\right)$$, then the policy does not give us any new information, and therefore the next reward is independent of the policy.

Return $$G_{t+1}$$: By definition, $$v_{\pi}(s') = \mathbb{E}_{\pi}[G_{t+1}|S_{t+1} = s']$$. The value function is unaffected by sampling actions from the policy in the outer expectation $$\left(\mathbb{E}_{\pi}[v_{\pi}(s')] = \mathbb{E}[v_{\pi}(s')]\right)$$ since the value function is an expectation under the policy, and hence samples actions from the policy already.

Dropping $$\pi$$ from $$\mathbb{E}_{\pi}$$: The expectation under the current policy samples next states and rewards from the environment and also samples actions from our policy $$\pi$$. Because the next reward is independent of the policy given the current state and action, and because the value function is unaffected by sampling actions from the policy in the outer expectation, we can simply drop the policy from the outer expectation (the outer expectation will still sample next states and rewards from the environment).