Answers.Body: <p>I think your net should have the various actions as outputs, but I am not an expert in Deep Nets. I just think that that light form of multi-task learning might be better. The idea of multi-task learning is that a predictor predicting multiple variables (in this case the various Q(s,a1), Q(s,a2), ...) using mostly the same structure (varying only the output weights) will learn more sensible things. Though I admit applying this here might be a bit of a stretch.</p>
  
  <p>As for the real question, a popular technique in Reinforcement Learning is <a href="https://webdocs.cs.ualberta.ca/~sutton/book/ebook/node88.html" rel="nofollow">Tile Coding</a>.</p>
  
  <p>The basic idea is to discretize the (2-dimensional, in your case) state-space - imagine a grid laid over the 2D space - and assigning an input feature to each cell; all of these variables are set to zero except for the one your continuous variables fall into. For example, if your grid is 20x20, you will have 400 variables, 399 of which are set to zero, and 1 set to one.</p>
  
  <p>Tile Coding takes this one step further and repeats this using slight offsets for the grid. Imagine you create an identical grid but you move it slightly to the right by 1/10 of the width of a cell: you will have another set of 400 variables like before, but it is possible that the cell set to one is not the same. Then you repeat this moving the grid by 2/10 and you have another set of 400 variables, again, only 1 of which is set to one. In total you have 10 sets of 400 variables (if you repeat more than that, you get the same grids as before); of your 4000 variables, only 10 are set to one.
  Now you repeat this by adding a 1/10 of a cell offset in the Y axis and obtain another 4000 variables. Repeat with 2/10 and you get another 4000. By the end of it, you have 40000 variables, 100 of which are set to one.</p>
  
  <p>Now your net can more easily learn different weights for different positions. I recommend you to follow the link above for a better explanation than mine (and figures!)</p>
  
  <p>My suggestion is to feed all of these variables to your net and have it predict the Q-value for all of the actions. But, again, I am no expert in deep nets so I may be wrong.</p>
  
  <p>Also, according to Andrej Karpathy, "most people prefer to use Policy Gradients, including the authors of the original DQN paper who have shown Policy Gradients to work better than Q Learning when tuned well.". This means that you may be better off not using Q-learning (as they did in the original DQN formulation) to train your net. Have a look at <a href="http://karpathy.github.io/2016/05/31/rl/" rel="nofollow">Andrej's blog</a> and <a href="http://arxiv.org/abs/1602.01783" rel="nofollow">the paper he points to</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-09T17:38:52.033Z
Answers.Text: So basically you are suggesting to divide continuous space into tiles so effectively making it discrete and therefore simplify the problem. Yeah that would work. I just wanted to try doing continuous space to see if I understand the point. But still, the answer is great so thanks. I may try it if the continuous thing suggested by BlindKungFuMaster will fail. About Policy Iterations, I am just beginning so first I want to try classic Q-Learning and then move on Policy methods, still thanks for the suggestion.
Answers.UserDisplayName: Dominik
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-09T17:09:35.313Z
Answers.LastActivityDate: 2016-09-09T17:18:20.390Z
Answers.LastEditDate: 2016-09-09T17:18:20.390Z
Answers.UserDisplayName: marcotama
Body: <p>I recently finished Course on RL by David Silver (on YT) and thought about trying it out on simple application in Unity Game Engine, where I've built simple labyrint with ball and want to teach the ball to get from point A to point B in there while avoiding obstacles and fire (the place where you'll get burnt so big negative reward)</p>
  
  <p>The problem I encountered while designing the whole thing (programming-wise) is: What is the correct (or at least good) way of representing the position in 2D space? It is continuous so I thought about representing it as feature vector consisting of [up, down, left, right, posX, posY] where direction is whether I am pressing button of moving in that direction in binary (or actions if you want) and pos are floats (0-1) representing normalized position from one corner on the plane where the whole map is. That would be accompanied by vector W that would represent the weights adjusted using Gradient Descent.</p>
  
  <p>Question is: will this work?? I am asking for 2 reasons. One is that I am not so sure about that posX and posY since it can be 0 and if I multiply it by the weights vector then how could be resulting reward anything but 0? Second reason is that I am not sure if the actions should be part of the features. I mean, it makes sense to me but I could easily be very wrong since I am a beginner.</p>
  
  <p>Thanks a lot guys in advance. If you have any more questions or think the problem is not described deeply enough just ask in the comments and I'll edit the question. :)</p>
  
  <p>PS: I could just code it the way I think is right, but I also want to get gasp of designing applications on paper before coding them (project management).</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-09T12:42:56.280Z
Comments.Text: Shouldn't the action be the output not the input? If you also learn a bias vector you mitigate the pos==(0,0) problem.
Comments.UserDisplayName: BlindKungFuMaster
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-09T13:06:52.963Z
Comments.Text: @BlindKungFuMaster That's the second reason there. To explain my thought process - The vector there is intended to be used as input to Q(s, a) which will be a function with parameters W (vector) that will be learned. The exact action then will be extracted from there finding max a in that Q(s, a) where S will be extracted from actual position of the ball and A will be found in some sort of loop.  
  What do you mean by the bias vector? Is it that W vector I mentioned or something else? Thanks.
Comments.UserDisplayName: Dominik
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-09T15:17:43.453Z
Comments.Text: Ah, ok, so Q predicts the expected reward. A bias vector would be added to the product of input and W. So it would B would contain additional parameters for Q.
Comments.UserDisplayName: BlindKungFuMaster
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-09T16:56:48.520Z
Comments.Text: So in the end it would be something like: Q(Sa, B) = W*Sa + B where B would be just some value so the Q of state (0, 0) won't be always 0 and therefore everything will be shifted by B which will not matter because in the end as W gets learnt the Q will converge to the actual values anyway, just W will be different then as if I did it without B. Do I understand correctly?
Comments.UserDisplayName: Dominik
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-09T17:09:38.590Z
Comments.Text: Yes, though I would suspect that you'll need more layers anyway, which would look like Q(Sa, B) = W2*f(W1*Sa + B1)+B2, except if your labyrinth is extremely simple.
Comments.UserDisplayName: BlindKungFuMaster
Tags: <reinforcement-learning><models><implementation><q-learning>
Title: State representation of position in 2D plane for Reinforcement Learning (Q Learning)
UserDisplayName: Dominik
ThreadText: # State representation of position in 2D plane for Reinforcement Learning (Q Learning)
  
  (Asked by: username_0 on 2016-09-09)
  
  I recently finished Course on RL by David Silver (on YT) and thought about trying it out on simple application in Unity Game Engine, where I've built simple labyrint with ball and want to teach the ball to get from point A to point B in there while avoiding obstacles and fire (the place where you'll get burnt so big negative reward)
  
  The problem I encountered while designing the whole thing (programming-wise) is: What is the correct (or at least good) way of representing the position in 2D space? It is continuous so I thought about representing it as feature vector consisting of [up, down, left, right, posX, posY] where direction is whether I am pressing button of moving in that direction in binary (or actions if you want) and pos are floats (0-1) representing normalized position from one corner on the plane where the whole map is. That would be accompanied by vector W that would represent the weights adjusted using Gradient Descent.
  
  Question is: will this work?? I am asking for 2 reasons. One is that I am not so sure about that posX and posY since it can be 0 and if I multiply it by the weights vector then how could be resulting reward anything but 0? Second reason is that I am not sure if the actions should be part of the features. I mean, it makes sense to me but I could easily be very wrong since I am a beginner.
  
  Thanks a lot guys in advance. If you have any more questions or think the problem is not described deeply enough just ask in the comments and I'll edit the question. :)
  
  PS: I could just code it the way I think is right, but I also want to get gasp of designing applications on paper before coding them (project management).
  
  **Tags:** reinforcement-learning, models, implementation, q-learning
  
  > **Comments:**
  > **username_1**: Shouldn't the action be the output not the input? If you also learn a bias vector you mitigate the pos==(0,0) problem.  
  > **username_0**: @username_1 That's the second reason there. To explain my thought process - The vector there is intended to be used as input to Q(s, a) which will be a function with parameters W (vector) that will be learned. The exact action then will be extracted from there finding max a in that Q(s, a) where S will be extracted from actual position of the ball and A will be found in some sort of loop.   What do you mean by the bias vector? Is it that W vector I mentioned or something else? Thanks.  
  > **username_1**: Ah, ok, so Q predicts the expected reward. A bias vector would be added to the product of input and W. So it would B would contain additional parameters for Q.  
  > **username_0**: So in the end it would be something like: Q(Sa, B) = W*Sa + B where B would be just some value so the Q of state (0, 0) won't be always 0 and therefore everything will be shifted by B which will not matter because in the end as W gets learnt the Q will converge to the actual values anyway, just W will be different then as if I did it without B. Do I understand correctly?  
  > **username_1**: Yes, though I would suspect that you'll need more layers anyway, which would look like Q(Sa, B) = W2*f(W1*Sa + B1)+B2, except if your labyrinth is extremely simple.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-09-09. Score: 3
  
  I think your net should have the various actions as outputs, but I am not an expert in Deep Nets. I just think that that light form of multi-task learning might be better. The idea of multi-task learning is that a predictor predicting multiple variables (in this case the various Q(s,a1), Q(s,a2), ...) using mostly the same structure (varying only the output weights) will learn more sensible things. Though I admit applying this here might be a bit of a stretch.
  
  As for the real question, a popular technique in Reinforcement Learning is [Tile Coding](https://webdocs.cs.ualberta.ca/~sutton/book/ebook/node88.html).
  
  The basic idea is to discretize the (2-dimensional, in your case) state-space - imagine a grid laid over the 2D space - and assigning an input feature to each cell; all of these variables are set to zero except for the one your continuous variables fall into. For example, if your grid is 20x20, you will have 400 variables, 399 of which are set to zero, and 1 set to one.
  
  Tile Coding takes this one step further and repeats this using slight offsets for the grid. Imagine you create an identical grid but you move it slightly to the right by 1/10 of the width of a cell: you will have another set of 400 variables like before, but it is possible that the cell set to one is not the same. Then you repeat this moving the grid by 2/10 and you have another set of 400 variables, again, only 1 of which is set to one. In total you have 10 sets of 400 variables (if you repeat more than that, you get the same grids as before); of your 4000 variables, only 10 are set to one.
  Now you repeat this by adding a 1/10 of a cell offset in the Y axis and obtain another 4000 variables. Repeat with 2/10 and you get another 4000. By the end of it, you have 40000 variables, 100 of which are set to one.
  
  Now your net can more easily learn different weights for different positions. I recommend you to follow the link above for a better explanation than mine (and figures!)
  
  My suggestion is to feed all of these variables to your net and have it predict the Q-value for all of the actions. But, again, I am no expert in deep nets so I may be wrong.
  
  Also, according to Andrej Karpathy, "most people prefer to use Policy Gradients, including the authors of the original DQN paper who have shown Policy Gradients to work better than Q Learning when tuned well.". This means that you may be better off not using Q-learning (as they did in the original DQN formulation) to train your net. Have a look at [Andrej's blog](http://karpathy.github.io/2016/05/31/rl/) and [the paper he points to](http://arxiv.org/abs/1602.01783).
  
  > **Comments:**
  > **username_0**: So basically you are suggesting to divide continuous space into tiles so effectively making it discrete and therefore simplify the problem. Yeah that would work. I just wanted to try doing continuous space to see if I understand the point. But still, the answer is great so thanks. I may try it if the continuous thing suggested by username_1 will fail. About Policy Iterations, I am just beginning so first I want to try classic Q-Learning and then move on Policy methods, still thanks for the suggestion.  
  
  ---
  
  