Answers.Body: <blockquote>
    <p>So, here's is the question: <strong>Is it true that a non-stationary policy must satisfy this condition?</strong></p>
    
    <p><span class="math-container">$$ \forall i, j \in \mathbb{N}, s \in S, \pi (i, s) = \pi(j, s) $$</span></p>
  </blockquote>
  
  <p>With your custom notation (which certainly isn't common, but seems reasonable)... I assume you meant to say that a <strong>stationary</strong> policy must satisfy that condition, rather than that a <strong>non-stationary</strong> policy must satisfy that condition. In that case, yeah, that seems correct to me. A stationary policy would satisfy that condition, and a non-stationary one wouldn't.</p>
  
  <hr>
  
  <p>Wrapping back to the more usual notation, where <span class="math-container">$\pi(S, A)$</span> denotes a probability of selecting <span class="math-container">$A$</span> in <span class="math-container">$S$</span> (which also still covers the case of a deterministic policy, which would simply assign a probability of <span class="math-container">$1$</span> to a single action, and <span class="math-container">$0$</span> to all others)... I think it's still interesting to consider the case where we decide to "bake" a time-step counter into the state representation.</p>
  
  <p>With this notation, for two different time steps <span class="math-container">$t$</span> and <span class="math-container">$t'$</span>, such that <span class="math-container">$t \neq t'$</span>, I'd say that a policy <span class="math-container">$\pi$</span> is <strong>stationary</strong> if and only if:</p>
  
  <p><span class="math-container">$$\pi(S_t, A_t) = \pi(S_{t'}, A_{t'}) \text{ if } S_t = S_{t'} \wedge A_t = A_{t'}.$$</span></p>
  
  <p>Note that if we decide to include <span class="math-container">$t$</span> in the state-representation, the case that <span class="math-container">$S_t = S_{t'}$</span> with <span class="math-container">$t \neq t'$</span> will actually <strong>never hold within the same episode</strong>, states at different time steps will always automatically be different from each other if the time step is one of the "features" encoded in the state. So, within a single episode a policy with a "time-aware" state representation will always automatically be stationary because there cannot be any repeating states. Of course, if you start looking across multiple different episodes, this can change; this is what you're doing when you write:</p>
  
  <blockquote>
    <p>Once we reset the environment to evaluate the policy again, the turn, which we store in the state, will go back to 0, but the background number of evaluations won't reset and it will be 3.</p>
  </blockquote>
  
  <p>If you chose to <strong>also</strong> embed that "episode counter" into the state representation, you would also no longer have any state repetitions at all anymore across different episodes (I don't think doing this would ever be a good idea though).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-24T22:42:14.973Z
Answers.Text: you're right, that was a typo in the first quote, I meant "is it true that a *stationary* policy must satisfy this condition?" I have edited the question.
Answers.UserDisplayName: Paula Vega
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-23T11:43:48.630Z
Answers.LastActivityDate: 2019-02-23T11:43:48.630Z
Answers.UserDisplayName: Dennis Soemers
Answers.Body: <p>I think you're overthinking it. I've never seen a formalisation of the concept of "stationary policy" (apart from yours). However, in general, "stationary" means that something does not change (over time). In the context of reinforcement learning, you can interpret it in such a way that it is consistent with the context where you find this expression, unless you decide to formalise this expression (like you've tried in this question).</p>
  
  <p>I think it might be useful to differentiate between the learning phase and the "inference" (or "behaviour") phase, even though these two might interleave in the RL context, that is, you might be using a policy (to behave in the real-world) even though you're still attempting to find the best policy (and I am not just referring to on-policy algorithms, but, in general, you might be using a policy to behave in the real-world which is sub-optimal while your learning algorithm, like Q-learning, is attempting to find the best policy). </p>
  
  <p>During the learning phase, the policy will keep changing over time (anyway), because you still haven't found the optimal policy. So, you could call the policy derived from the <span class="math-container">$Q$</span> values, during the <span class="math-container">$Q$</span>-learning algorithm, a non-stationary policy, because it keeps changing (because the <span class="math-container">$Q$</span> values also keep changing). However, it is often the case that these are considered different policies associated with different approximations of the <span class="math-container">$Q$</span> function.</p>
  
  <p>You could also call a policy that changes in response to changes of the (dynamics of the) environment a non-stationary policy. In this case, you would call such an environment a non-stationary environment (because e.g. its transition model might keep changing over time). </p>
  
  <p>The problem that you describe when you compare the state <span class="math-container">$i$</span> with states that encode time only arises because of your definition of state <span class="math-container">$i$</span>. You can also reset <span class="math-container">$i$</span> when you reset the environment.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-23T12:12:09.787Z
Answers.LastActivityDate: 2019-02-24T13:27:28.380Z
Answers.LastEditDate: 2019-02-24T13:27:28.380Z
Answers.UserDisplayName: nbro
Body: <p>This question is related to <a href="https://ai.stackexchange.com/q/7640/2444">What does &quot;stationary&quot; mean in the context of reinforcement learning?</a>, but I have a more specific question to clarify the difference between a non-stationary policy and a state that includes time.</p>
  
  <p>My understanding is that, in general, a non-stationary policy is a policy that doesn't change. My first (probably incorrect) interpretation of that was that it meant that the state shouldn't contain time. For example, in the case of game, we could encode time as the current turn, which increases every time the agent takes an action. However, I think even if we include the turn in the state, the policy is still non-stationary so long as sending the same state (including turn) to the policy produces the same action (in case of a deterministic policy) or the same probability distribution (stochastic policy).</p>
  
  <p>I believe the notion of stationarity assumes an additional implicit background state that counts the number of times we have evaluated the policy, so a more precise way to think about a policy (I'll use a deterministic policy for simplicity) would be:</p>
  
  <p><span class="math-container">$$ \pi : \mathbb{N} \times S \rightarrow \mathbb{N} \times A $$</span>
  <span class="math-container">$$ \pi : (i, s_t) \rightarrow (i + 1, s_{t+1}) $$</span></p>
  
  <p>instead of <span class="math-container">$\pi : S \rightarrow A$</span>.</p>
  
  <p>So, here is the question: <strong>Is it true that a stationary policy must satisfy this condition?</strong></p>
  
  <p><span class="math-container">$$ \forall i, j \in \mathbb{N}, s \in S, \pi (i, s) = \pi(j, s) $$</span></p>
  
  <p>In other words, the policy must output the same result no matter when we evaluate it (either the ith or jth time). Even if the state <span class="math-container">$S$</span> contains a counter of the turn, the policy would still be non-stationary because for the same state (including turn), no matter how many times you evaluate it, it will return the same thing. Correct?</p>
  
  <p>As a final note, I want to contrast the difference between a state that includes time, with the background state I called <span class="math-container">$i$</span> in my definition of <span class="math-container">$\pi$</span>. For example, when we run an episode of 3 steps, the state <span class="math-container">$S$</span> will contain 0, 1, 2, and the background counter of number of the policy <span class="math-container">$i$</span> will also be set to 2. Once we reset the environment to evaluate the policy again, the turn, which we store in the state, will go back to 0, but the background number of evaluations won't reset and it will be 3. My understanding is that in this reset is when we could see the non-stationarity of the policy in action. If we get a different result here it's a non-stationary policy, and if we get the same result it's a stationary policy, and such property is independent of whether or not we include the turn in the state. Correct?</p>
  
Tags: <reinforcement-learning><policies>
Title: What is the difference between a non-stationary policy and a state that stores time?
UserDisplayName: Paula Vega
ThreadText: # What is the difference between a non-stationary policy and a state that stores time?
  
  (Asked by: username_0 on 2019-02-20)
  
  This question is related to [What does "stationary" mean in the context of reinforcement learning?](https://ai.stackexchange.com/q/7640/2444), but I have a more specific question to clarify the difference between a non-stationary policy and a state that includes time.
  
  My understanding is that, in general, a non-stationary policy is a policy that doesn't change. My first (probably incorrect) interpretation of that was that it meant that the state shouldn't contain time. For example, in the case of game, we could encode time as the current turn, which increases every time the agent takes an action. However, I think even if we include the turn in the state, the policy is still non-stationary so long as sending the same state (including turn) to the policy produces the same action (in case of a deterministic policy) or the same probability distribution (stochastic policy).
  
  I believe the notion of stationarity assumes an additional implicit background state that counts the number of times we have evaluated the policy, so a more precise way to think about a policy (I'll use a deterministic policy for simplicity) would be:
  
  $$ \pi : \mathbb{N} \times S \rightarrow \mathbb{N} \times A $$
  $$ \pi : (i, s\_t) \rightarrow (i + 1, s\_{t+1}) $$
  
  instead of $\pi : S \rightarrow A$.
  
  So, here is the question: **Is it true that a stationary policy must satisfy this condition?**
  
  $$ \forall i, j \in \mathbb{N}, s \in S, \pi (i, s) = \pi(j, s) $$
  
  In other words, the policy must output the same result no matter when we evaluate it (either the ith or jth time). Even if the state $S$ contains a counter of the turn, the policy would still be non-stationary because for the same state (including turn), no matter how many times you evaluate it, it will return the same thing. Correct?
  
  As a final note, I want to contrast the difference between a state that includes time, with the background state I called $i$ in my definition of $\pi$. For example, when we run an episode of 3 steps, the state $S$ will contain 0, 1, 2, and the background counter of number of the policy $i$ will also be set to 2. Once we reset the environment to evaluate the policy again, the turn, which we store in the state, will go back to 0, but the background number of evaluations won't reset and it will be 3. My understanding is that in this reset is when we could see the non-stationarity of the policy in action. If we get a different result here it's a non-stationary policy, and if we get the same result it's a stationary policy, and such property is independent of whether or not we include the turn in the state. Correct?
  
  **Tags:** reinforcement-learning, policies
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-02-23. Score: 2
  
  > So, here's is the question: **Is it true that a non-stationary policy must satisfy this condition?**
  >
  > $$ \forall i, j \in \mathbb{N}, s \in S, \pi (i, s) = \pi(j, s) $$
  
  With your custom notation (which certainly isn't common, but seems reasonable)... I assume you meant to say that a **stationary** policy must satisfy that condition, rather than that a **non-stationary** policy must satisfy that condition. In that case, yeah, that seems correct to me. A stationary policy would satisfy that condition, and a non-stationary one wouldn't.
  
  ---
  
  Wrapping back to the more usual notation, where $\pi(S, A)$ denotes a probability of selecting $A$ in $S$ (which also still covers the case of a deterministic policy, which would simply assign a probability of $1$ to a single action, and $0$ to all others)... I think it's still interesting to consider the case where we decide to "bake" a time-step counter into the state representation.
  
  With this notation, for two different time steps $t$ and $t'$, such that $t \neq t'$, I'd say that a policy $\pi$ is **stationary** if and only if:
  
  $$\pi(S\_t, A\_t) = \pi(S\_{t'}, A\_{t'}) \text{ if } S\_t = S\_{t'} \wedge A\_t = A\_{t'}.$$
  
  Note that if we decide to include $t$ in the state-representation, the case that $S\_t = S\_{t'}$ with $t \neq t'$ will actually **never hold within the same episode**, states at different time steps will always automatically be different from each other if the time step is one of the "features" encoded in the state. So, within a single episode a policy with a "time-aware" state representation will always automatically be stationary because there cannot be any repeating states. Of course, if you start looking across multiple different episodes, this can change; this is what you're doing when you write:
  
  > Once we reset the environment to evaluate the policy again, the turn, which we store in the state, will go back to 0, but the background number of evaluations won't reset and it will be 3.
  
  If you chose to **also** embed that "episode counter" into the state representation, you would also no longer have any state repetitions at all anymore across different episodes (I don't think doing this would ever be a good idea though).
  
  > **Comments:**
  > **username_0**: you're right, that was a typo in the first quote, I meant "is it true that a *stationary* policy must satisfy this condition?" I have edited the question.  
  
  ---
  
  ### Answer by username_2 on 2019-02-23. Score: 1
  
  I think you're overthinking it. I've never seen a formalisation of the concept of "stationary policy" (apart from yours). However, in general, "stationary" means that something does not change (over time). In the context of reinforcement learning, you can interpret it in such a way that it is consistent with the context where you find this expression, unless you decide to formalise this expression (like you've tried in this question).
  
  I think it might be useful to differentiate between the learning phase and the "inference" (or "behaviour") phase, even though these two might interleave in the RL context, that is, you might be using a policy (to behave in the real-world) even though you're still attempting to find the best policy (and I am not just referring to on-policy algorithms, but, in general, you might be using a policy to behave in the real-world which is sub-optimal while your learning algorithm, like Q-learning, is attempting to find the best policy).
  
  During the learning phase, the policy will keep changing over time (anyway), because you still haven't found the optimal policy. So, you could call the policy derived from the $Q$ values, during the $Q$-learning algorithm, a non-stationary policy, because it keeps changing (because the $Q$ values also keep changing). However, it is often the case that these are considered different policies associated with different approximations of the $Q$ function.
  
  You could also call a policy that changes in response to changes of the (dynamics of the) environment a non-stationary policy. In this case, you would call such an environment a non-stationary environment (because e.g. its transition model might keep changing over time).
  
  The problem that you describe when you compare the state $i$ with states that encode time only arises because of your definition of state $i$. You can also reset $i$ when you reset the environment.
  
  
  ---
  
  