Answers.Body: <p>Your issue is related to how you are representing your rewards, and not anything to worry about for the MDP.</p>
  
  <p>You have chosen to use a matrix to represent your reward function, which maps <span class="math-container">$(s,s')$</span> to <span class="math-container">$r$</span>. If some transition <span class="math-container">$s \rightarrow s'$</span> doesn't happen, then it doesn't matter at all what you put there for the reward value for <span class="math-container">$(s,s')$</span>. It is only because you have decided to use a matrix for this that you even need to think about it. </p>
  
  <p>A <em>complete</em> reward function would map <span class="math-container">$s, a, s'$</span> to a scalar value, and can also include a random factor. You don't need to use all the factors - a MDP can use any or all of them, and all the MDP theory is still correct. In your case, it looks like arriving in a "goal state" <span class="math-container">$s' = C$</span> is what triggers a +1 reward. So instead of a matrix you could define a function:</p>
  
  <p><span class="math-container">$$r(s,a,s') = \begin{cases}
      -1,&amp; \text{if } s' = A\\
      1,&amp; \text{if } s' = C\\
      0,              &amp; \text{otherwise}
  \end{cases} $$</span></p>
  
  <p>This is equally valid in the MDP as your matrix, and avoids the issue of storing data about impossible transitions.</p>
  
  <blockquote>
    <p>I thought the transition function would handle this issue since I will define there what is possible and what is not.</p>
  </blockquote>
  
  <p>Yes that should be the case. If your transition function does not allow for certain state changes, then there is no need to handle them in any particular way in the reward function.</p>
  
  <blockquote>
    <p>But anyway it is said that for a horizon of one the imm[e]diate reward is given and the transition function isn't even considered</p>
  </blockquote>
  
  <p>I am not sure where you have read this, but it does not relate to your representation issue or resolving "impossible" state transitions.</p>
  
  <p>If you are using a model-based method, such as Policy Iteration or Value Iteration, then you do use the transition function and reward function - more or less directly in the form of the <a href="https://en.wikipedia.org/wiki/Bellman_equation#Example" rel="nofollow noreferrer">Bellman equations</a>. In this case, the transition function will assign a weight of 0 to the impossible transitions, so the reward value doe not matter (and efficient code would likely skip even looking up or calculating the reward in that case).</p>
  
  <p>If you are using a model-free method, such as Q learning, then the <em>agent</em> does not use the transition function or the reward function directly. They are part of the environment that it is learning. However, any code for the simulated environment has to implement the physics of your world, and that includes using the transition function to resolve what happens when the agent takes an action. In that case, the simulated model of the environment would prevent the agent ever experiencing impossible transitions, so there is never any need to calculate the reward for them or allow for them as edge cases in a reward function (you might still choose to check validity and/or return something as defensive programming of the reward function, but it is not required for the MDP and reinforcement learning to work).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-23T09:35:49.353Z
Answers.LastActivityDate: 2019-03-23T11:40:11.823Z
Answers.LastEditDate: 2019-03-23T11:40:11.823Z
Answers.UserDisplayName: Neil Slater
Body: <p>Do we have to consider if (s is given) an action a can lead to s' when defining a reward function?</p>
  
  <p>To be more specific:
  Let's say I have a 1D Map like: <code>|A|B|C|D|</code>
  To define a reward function, I simply defined a matrix for every action, where the columns and rows represent the states (A-D) and the entries represent the reward. But I made it even simpler. As reaching a specific state gives a reward of 1 I just assigned the reward to a column (C). </p>
  
  <p><span class="math-container">$$
  \begin{matrix} -1&amp;0&amp;1&amp;0\\ -1&amp;0&amp;1&amp;0\\-1&amp;0&amp;1&amp;0\\-1&amp;0&amp;1&amp;0 \end{matrix}
  $$</span>
  However, lets say the matrix is specified for the action "going right". Now there are entries reading: <code>D ==&gt; going right ==&gt; C getting reward of 1</code>. This is actually not possible. However, I thought the transition function would handle this issue since I will define there what is possible and what is not. But anyway it is said that for a horizon of one the immidiate reward is given and the transition function isn't even considered. This leads to arbitrary result. So do I have to consider the "physics" of my world?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-23T09:20:59.530Z
Comments.Text: Regarding " But anyway it is said that for a horizon of one the immidiate reward is given and the transition function isn't even considered" - could you reference where you have read this. It is entirely wrong, but perhaps it is taken out of context or a misunderstanding
Comments.UserDisplayName: Neil Slater
Tags: <rewards><markov-decision-process>
Title: Do we have to consider the feasability of an action when defining the reward function of a MDP?
UserDisplayName: Bryan McGill
ThreadText: # Do we have to consider the feasability of an action when defining the reward function of a MDP?
  
  (Asked by: username_0 on 2019-03-22)
  
  Do we have to consider if (s is given) an action a can lead to s' when defining a reward function?
  
  To be more specific:
  Let's say I have a 1D Map like: `|A|B|C|D|`
  To define a reward function, I simply defined a matrix for every action, where the columns and rows represent the states (A-D) and the entries represent the reward. But I made it even simpler. As reaching a specific state gives a reward of 1 I just assigned the reward to a column (C).
  
  $$
  \begin{matrix} -1&0&1&0\\ -1&0&1&0\\-1&0&1&0\\-1&0&1&0 \end{matrix}
  $$
  However, lets say the matrix is specified for the action "going right". Now there are entries reading: `D ==> going right ==> C getting reward of 1`. This is actually not possible. However, I thought the transition function would handle this issue since I will define there what is possible and what is not. But anyway it is said that for a horizon of one the immidiate reward is given and the transition function isn't even considered. This leads to arbitrary result. So do I have to consider the "physics" of my world?
  
  **Tags:** rewards, markov-decision-process
  
  > **Comments:**
  > **username_1**: Regarding " But anyway it is said that for a horizon of one the immidiate reward is given and the transition function isn't even considered" - could you reference where you have read this. It is entirely wrong, but perhaps it is taken out of context or a misunderstanding  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-23. Score: 1
  
  Your issue is related to how you are representing your rewards, and not anything to worry about for the MDP.
  
  You have chosen to use a matrix to represent your reward function, which maps $(s,s')$ to $r$. If some transition $s \rightarrow s'$ doesn't happen, then it doesn't matter at all what you put there for the reward value for $(s,s')$. It is only because you have decided to use a matrix for this that you even need to think about it.
  
  A *complete* reward function would map $s, a, s'$ to a scalar value, and can also include a random factor. You don't need to use all the factors - a MDP can use any or all of them, and all the MDP theory is still correct. In your case, it looks like arriving in a "goal state" $s' = C$ is what triggers a +1 reward. So instead of a matrix you could define a function:
  
  $$r(s,a,s') = \begin{cases}
  -1,& \text{if } s' = A\\
  1,& \text{if } s' = C\\
  0, & \text{otherwise}
  \end{cases} $$
  
  This is equally valid in the MDP as your matrix, and avoids the issue of storing data about impossible transitions.
  
  > I thought the transition function would handle this issue since I will define there what is possible and what is not.
  
  Yes that should be the case. If your transition function does not allow for certain state changes, then there is no need to handle them in any particular way in the reward function.
  
  > But anyway it is said that for a horizon of one the imm[e]diate reward is given and the transition function isn't even considered
  
  I am not sure where you have read this, but it does not relate to your representation issue or resolving "impossible" state transitions.
  
  If you are using a model-based method, such as Policy Iteration or Value Iteration, then you do use the transition function and reward function - more or less directly in the form of the [Bellman equations](https://en.wikipedia.org/wiki/Bellman_equation#Example). In this case, the transition function will assign a weight of 0 to the impossible transitions, so the reward value doe not matter (and efficient code would likely skip even looking up or calculating the reward in that case).
  
  If you are using a model-free method, such as Q learning, then the *agent* does not use the transition function or the reward function directly. They are part of the environment that it is learning. However, any code for the simulated environment has to implement the physics of your world, and that includes using the transition function to resolve what happens when the agent takes an action. In that case, the simulated model of the environment would prevent the agent ever experiencing impossible transitions, so there is never any need to calculate the reward for them or allow for them as edge cases in a reward function (you might still choose to check validity and/or return something as defensive programming of the reward function, but it is not required for the MDP and reinforcement learning to work).
  
  
  ---
  
  