Answers.Body: <p>The initial state can vary during in both training and use, and how you decide to do this makes very little difference to Q-learning. The important factor is whether all state/action pairs relevant to optimal behaviour can be reached. As there is already randomness in any exploring policy, and in many environments as part of state transitions and reward functions, adding some more at the start is not an issue.</p>
  
  <p>More formally, you can take any existing environment with states <span class="math-container">$S_1, S_2, S_3 ... S_n$</span> plus defined actions and rewards. Add a special fixed start state <span class="math-container">$S_{0}$</span> with one special action <span class="math-container">$A_{0}$</span> allowed. Make the state transition matrix following that action any distribution you like over the other states, and reward <span class="math-container">$0$</span>. It is clearly a valid MDP, and is identical to your original MDP in terms of value and policy functions for states <span class="math-container">$S_1, S_2, S_3 ... S_n$</span>. For all intents and purposes to the agent (which gets no meaningful policy choice in <span class="math-container">$S_0$</span>), it starts in the original MDP in some randomly chosen state.</p>
  
  <p>That is as long as the variations are not made to deliberately exclude some of the state space during training that it would need later, or otherwise used to "attack" the agent and prevent it learning. Q-learning proofs of convergence assume that all state/action pairs are reachable an infinite number of times in the limit of infinite training time. Of course in practice this is never achieved, but clearly if you excluded some important state from ever being seen at the start by choosing to start in a way that it is never reachable, then the agent would never learn about it.</p>
  
  <p>You can use a highly variable start state for training to your advantage. It is a form of exploration, and truly exploring starts (that could start from any state/action pair, so you would want to randomise the first action choice) allow you to skip any further exploration and still guarantee convergence to an optimal policy - i.e. you could learn Q values on-policy using a deterministic policy. This will not necessarily make things converge faster, but does go to demonstrate that random start states are not a barrier to RL.</p>
  
  <p>There are a couple of minor/partial exceptions to "do what you like":</p>
  
  <ul>
  <li><p>If the environment is otherwise highly deterministic, adding a random start may increase the difficulty in optimising it, as more states will be reachable, even with an optimal policy, therefore the state space over which optimal behaviour needs to be discovered may be larger and take longer to learn.</p></li>
  <li><p>Policy Gradient methods, like REINFORCE, optimise the policy towards maximising return from a known distribution of start states. So you can vary start state, but you should really stick to a standard start procedure, including a fixed <em>distribution</em> of allowed start states. </p></li>
  <li><p>Similarly, if you want to report a standard score for your agent, it is common to quote the expected return from the start states. Again that doesn't mean you have a fixed start state, but you should use a fixed <em>distribution</em> of start states to assess your agent.</p></li>
  </ul>
  
  <p>Many standard environments, like Open AI's Gym environments CartPole and LunarLander, include some amount of randomness in the start state, so that the agent has to solve a more general problem than just generating a fixed sequence of actions that always works from the beginning.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-11T16:26:10.960Z
Answers.Text: @DuttA: I don't know. I expect that will depend on other things. Oddly, if you also randomly stop then it might be better at such a task, as the algorithm starts to look a bit like Dyna-Q planning.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-11T16:12:29.877Z
Answers.LastActivityDate: 2019-09-11T16:34:29.597Z
Answers.LastEditDate: 2019-09-11T16:34:29.597Z
Answers.UserDisplayName: Neil Slater
Body: <p>Is it crucial to always have the same initial (starting) state for Reinforcement Learning, for example, for Q-learning or DQN?
  Or it can vary?</p>
  
Tags: <reinforcement-learning><dqn>
Title: How important is the choice of the initial state?
UserDisplayName: fenixkz
ThreadText: # How important is the choice of the initial state?
  
  (Asked by: username_0 on 2019-09-11)
  
  Is it crucial to always have the same initial (starting) state for Reinforcement Learning, for example, for Q-learning or DQN?
  Or it can vary?
  
  **Tags:** reinforcement-learning, dqn
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-11. Score: 2 | Accepted answer
  
  The initial state can vary during in both training and use, and how you decide to do this makes very little difference to Q-learning. The important factor is whether all state/action pairs relevant to optimal behaviour can be reached. As there is already randomness in any exploring policy, and in many environments as part of state transitions and reward functions, adding some more at the start is not an issue.
  
  More formally, you can take any existing environment with states $S\_1, S\_2, S\_3 ... S\_n$ plus defined actions and rewards. Add a special fixed start state $S\_{0}$ with one special action $A\_{0}$ allowed. Make the state transition matrix following that action any distribution you like over the other states, and reward $0$. It is clearly a valid MDP, and is identical to your original MDP in terms of value and policy functions for states $S\_1, S\_2, S\_3 ... S\_n$. For all intents and purposes to the agent (which gets no meaningful policy choice in $S\_0$), it starts in the original MDP in some randomly chosen state.
  
  That is as long as the variations are not made to deliberately exclude some of the state space during training that it would need later, or otherwise used to "attack" the agent and prevent it learning. Q-learning proofs of convergence assume that all state/action pairs are reachable an infinite number of times in the limit of infinite training time. Of course in practice this is never achieved, but clearly if you excluded some important state from ever being seen at the start by choosing to start in a way that it is never reachable, then the agent would never learn about it.
  
  You can use a highly variable start state for training to your advantage. It is a form of exploration, and truly exploring starts (that could start from any state/action pair, so you would want to randomise the first action choice) allow you to skip any further exploration and still guarantee convergence to an optimal policy - i.e. you could learn Q values on-policy using a deterministic policy. This will not necessarily make things converge faster, but does go to demonstrate that random start states are not a barrier to RL.
  
  There are a couple of minor/partial exceptions to "do what you like":
  
  * If the environment is otherwise highly deterministic, adding a random start may increase the difficulty in optimising it, as more states will be reachable, even with an optimal policy, therefore the state space over which optimal behaviour needs to be discovered may be larger and take longer to learn.
  * Policy Gradient methods, like REINFORCE, optimise the policy towards maximising return from a known distribution of start states. So you can vary start state, but you should really stick to a standard start procedure, including a fixed *distribution* of allowed start states.
  * Similarly, if you want to report a standard score for your agent, it is common to quote the expected return from the start states. Again that doesn't mean you have a fixed start state, but you should use a fixed *distribution* of start states to assess your agent.
  
  Many standard environments, like Open AI's Gym environments CartPole and LunarLander, include some amount of randomness in the start state, so that the agent has to solve a more general problem than just generating a fixed sequence of actions that always works from the beginning.
  
  > **Comments:**
  > **username_1**: @DuttA: I don't know. I expect that will depend on other things. Oddly, if you also randomly stop then it might be better at such a task, as the algorithm starts to look a bit like Dyna-Q planning.  
  
  ---
  
  