Answers.Body: <p>A common early approach to modeling complex problems was <em>discretization</em>. At a basic level, this is splitting a complex and continuous space into a grid. Then you can use any of the classic RL techniques that are designed for discrete, linear, spaces. However, as you might imagine, if you aren't careful, this can cause a lot of trouble!</p>
  
  <p>Sutton &amp; Barto's classic book <em>Reinforcement Learning</em> has some suggestions for other ways to go about this. One is <em>tile coding</em>, covered in section 9.5.4 of the <a href="https://drive.google.com/file/d/1opPSz5AZ_kVa1uWOdOiveNiBFiEOHjkG/view" rel="noreferrer">new, second edition</a>. In tile coding, we generate a large number of grids, each with different grid spacing. We then overlay the grids on top of each other. This creates discrete regions non-uniform shapes, and can work well for a variety of problems.</p>
  
  <p>Section 9.5 also covers a variety of other ways to encode a continuous space into a discrete MDP, including radial-basis functions, and coarse codings. Check it out!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-31T02:41:58.353Z
Answers.LastActivityDate: 2019-07-18T19:40:37.783Z
Answers.LastEditDate: 2019-07-18T19:40:37.783Z
Answers.UserDisplayName: John Doucette
Answers.Body: <p>The problem of state representation in Reinforcement Learning (RL) is similar to problems of feature representation, feature selection and feature engineering in supervised or unsupervised learning.</p>
  
  <p>Literature that teaches the basics of RL tends to use very simple environments so that all states can be enumerated. This simplifies value estimates into basic rolling averages in a table, which are easier to understand and implement. Tabular learning algorithms also have reasonable theoretical guarantees of convergence, which means if you <em>can</em> simplify your problem so that it has, say, less than a few million states, then this is worth trying.</p>
  
  <p>Most interesting control problems will not fit into that number of states, even if you discretise them. This is due to the "<a href="https://en.wikipedia.org/wiki/Curse_of_dimensionality" rel="noreferrer">curse of dimensionality</a>". For those problems, you will typically represent your state as a vector of different features - e.g. for a robot, various positions, angles, velocities of mechanical parts. As with supervised learning, you may want to treat these for use with a specific learning process. For instance, typically you will want them all to be numeric, and if you want to use a neural network you should also normalise them to a standard range (e.g. -1 to 1).</p>
  
  <p>In addition to the above concerns which apply for other machine learning, for RL, you also need to be concerned with the <a href="https://en.wikipedia.org/wiki/Markov_property" rel="noreferrer">Markov Property</a> - that the state provides enough information, so that you can accurately predict expected next rewards and next states given an action, without the need for any additional information. This does not need to be perfect, small differences due to e.g. variations in air density or temperature for a wheeled robot will not usually have a large impact on its navigation, and can be ignored. Any factor which is essentially random can also be ignored whilst sticking to RL theory - it may make the agent less optimal overall, but the theory will still work. </p>
  
  <p>If there are consistent unknown factors that influence result, and could logically be deduced - maybe from history of state or actions - but you have excluded them from the state representation, then you may have a more serious problem, and the agent may fail to learn.</p>
  
  <p>It is worth noting the difference here between <em>observation</em> and <em>state</em>. An observation is some data that you can collect. E.g. you may have sensors on your robot that feed back the positions of its joints. Because the state should possess the Markov Property, a single raw observation might not be enough data to make a suitable state. If that is the case, you can either apply your domain knowledge in order to construct a better state from available data, or you can try to use techniques designed for <a href="https://en.wikipedia.org/wiki/Partially_observable_Markov_decision_process" rel="noreferrer">partially observable MDPs (POMDPs)</a> - these effectively try to build missing parts of state data statistically. You could use a RNN or hidden markov model (also called a "belief state") for this, and in some way this is using a "<em>learning or classification algorithms to "learn" those states</em>" as you asked.</p>
  
  <p>Finally, you need to consider the type of approximation model you want to use. A similar approach applies here as for supervised learning: </p>
  
  <ul>
  <li><p>A simple linear regression with features engineered based on domain knowledge can do very well. You may need to work hard on trying different state representations so that the linear approximation works. The advantage is that this simpler approach is more robust against stability issues than non-linear approximation</p></li>
  <li><p>A more complex non-linear function approximator, such as a multi-layer neural network. You can feed in a more "raw" state vector and hope that the hidden layers will find some structure or representation that leads to good estimates. In some ways, this too is "<em>learning or classification algorithms to "learn" those states</em>" , but in a different way to a RNN or HMM. This might be a sensible approach if your state was expressed naturally as a screen image - figuring out the feature engineering for image data by hand is very hard.</p></li>
  </ul>
  
  <p>The <a href="https://deepmind.com/research/dqn/" rel="noreferrer">Atari DQN work by DeepMind</a> team used a combination of feature engineering and relying on deep neural network to achieve its results. The feature engineering included downsampling the image, reducing it to grey-scale and - importantly for the Markov Property - using four consecutive frames to represent a single state, so that information about velocity of objects was present in the state representation. The DNN then processed the images into higher-level features that could be used to make predictions about state values.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-31T16:02:59.630Z
Answers.LastActivityDate: 2018-08-31T16:02:59.630Z
Answers.UserDisplayName: Neil Slater
Body: <p>I am studying reinforcement learning and the variants of it. I am starting to get an understanding of how the algorithms work and how they apply to an MDP.</p>
  <p>What I don't understand is the process of defining the states of the MDP. In most examples and tutorials, they represent something simple like a square in a grid or similar.</p>
  <p>For more complex problems, like a robot learning to walk, etc.,</p>
  <ul>
  <li>How do you go about defining those states?</li>
  <li>Can you use learning or classification algorithms to &quot;learn&quot; those states?</li>
  </ul>
  
Tags: <reinforcement-learning><ai-design><markov-decision-process><state-spaces><state-representations>
Title: How to define states in reinforcement learning?
UserDisplayName: Andy
ThreadText: # How to define states in reinforcement learning?
  
  (Asked by: username_0 on 2018-08-30)
  
  I am studying reinforcement learning and the variants of it. I am starting to get an understanding of how the algorithms work and how they apply to an MDP.
  
  What I don't understand is the process of defining the states of the MDP. In most examples and tutorials, they represent something simple like a square in a grid or similar.
  
  For more complex problems, like a robot learning to walk, etc.,
  
  * How do you go about defining those states?
  * Can you use learning or classification algorithms to "learn" those states?
  
  **Tags:** reinforcement-learning, ai-design, markov-decision-process, state-spaces, state-representations
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-08-31. Score: 24 | Accepted answer
  
  The problem of state representation in Reinforcement Learning (RL) is similar to problems of feature representation, feature selection and feature engineering in supervised or unsupervised learning.
  
  Literature that teaches the basics of RL tends to use very simple environments so that all states can be enumerated. This simplifies value estimates into basic rolling averages in a table, which are easier to understand and implement. Tabular learning algorithms also have reasonable theoretical guarantees of convergence, which means if you *can* simplify your problem so that it has, say, less than a few million states, then this is worth trying.
  
  Most interesting control problems will not fit into that number of states, even if you discretise them. This is due to the "[curse of dimensionality](https://en.wikipedia.org/wiki/Curse_of_dimensionality)". For those problems, you will typically represent your state as a vector of different features - e.g. for a robot, various positions, angles, velocities of mechanical parts. As with supervised learning, you may want to treat these for use with a specific learning process. For instance, typically you will want them all to be numeric, and if you want to use a neural network you should also normalise them to a standard range (e.g. -1 to 1).
  
  In addition to the above concerns which apply for other machine learning, for RL, you also need to be concerned with the [Markov Property](https://en.wikipedia.org/wiki/Markov_property) - that the state provides enough information, so that you can accurately predict expected next rewards and next states given an action, without the need for any additional information. This does not need to be perfect, small differences due to e.g. variations in air density or temperature for a wheeled robot will not usually have a large impact on its navigation, and can be ignored. Any factor which is essentially random can also be ignored whilst sticking to RL theory - it may make the agent less optimal overall, but the theory will still work.
  
  If there are consistent unknown factors that influence result, and could logically be deduced - maybe from history of state or actions - but you have excluded them from the state representation, then you may have a more serious problem, and the agent may fail to learn.
  
  It is worth noting the difference here between *observation* and *state*. An observation is some data that you can collect. E.g. you may have sensors on your robot that feed back the positions of its joints. Because the state should possess the Markov Property, a single raw observation might not be enough data to make a suitable state. If that is the case, you can either apply your domain knowledge in order to construct a better state from available data, or you can try to use techniques designed for [partially observable MDPs (POMDPs)](https://en.wikipedia.org/wiki/Partially_observable_Markov_decision_process) - these effectively try to build missing parts of state data statistically. You could use a RNN or hidden markov model (also called a "belief state") for this, and in some way this is using a "*learning or classification algorithms to "learn" those states*" as you asked.
  
  Finally, you need to consider the type of approximation model you want to use. A similar approach applies here as for supervised learning:
  
  * A simple linear regression with features engineered based on domain knowledge can do very well. You may need to work hard on trying different state representations so that the linear approximation works. The advantage is that this simpler approach is more robust against stability issues than non-linear approximation
  * A more complex non-linear function approximator, such as a multi-layer neural network. You can feed in a more "raw" state vector and hope that the hidden layers will find some structure or representation that leads to good estimates. In some ways, this too is "*learning or classification algorithms to "learn" those states*" , but in a different way to a RNN or HMM. This might be a sensible approach if your state was expressed naturally as a screen image - figuring out the feature engineering for image data by hand is very hard.
  
  The [Atari DQN work by DeepMind](https://deepmind.com/research/dqn/) team used a combination of feature engineering and relying on deep neural network to achieve its results. The feature engineering included downsampling the image, reducing it to grey-scale and - importantly for the Markov Property - using four consecutive frames to represent a single state, so that information about velocity of objects was present in the state representation. The DNN then processed the images into higher-level features that could be used to make predictions about state values.
  
  
  ---
  
  ### Answer by username_1 on 2018-08-31. Score: 12
  
  A common early approach to modeling complex problems was *discretization*. At a basic level, this is splitting a complex and continuous space into a grid. Then you can use any of the classic RL techniques that are designed for discrete, linear, spaces. However, as you might imagine, if you aren't careful, this can cause a lot of trouble!
  
  Sutton & Barto's classic book *Reinforcement Learning* has some suggestions for other ways to go about this. One is *tile coding*, covered in section 9.5.4 of the [new, second edition](https://drive.google.com/file/d/1opPSz5AZ_kVa1uWOdOiveNiBFiEOHjkG/view). In tile coding, we generate a large number of grids, each with different grid spacing. We then overlay the grids on top of each other. This creates discrete regions non-uniform shapes, and can work well for a variety of problems.
  
  Section 9.5 also covers a variety of other ways to encode a continuous space into a discrete MDP, including radial-basis functions, and coarse codings. Check it out!
  
  
  ---
  
  