Answers.Body: <blockquote>
    <p>In the case in which some of the states -but not all- are fully independent of the actions -but still obviously determine the optimal actions-, how could we take these state variables into account?</p>
  </blockquote>
  
  <p>I think the key thing here is the caveat <strong>but not all</strong>. What you have is a fully-featured MDP (states, actions, rewards, timesteps where next reward and next state depend on current state and action). The fact that next state is only marginally affected by the current action does not prevent it being an MDP. </p>
  
  <p>It would be a problem if the current state did not adequately describe this limitation e.g. if some other data, outside of observable state, decided whether action had any effect. Assuming that is not the case, then you still have a full reinforcement learning problem, but one with some unusual qualities.</p>
  
  <p>You can mitigate against problems caused by algorithms that will over-estimate likely reward (caused by algorithm associating lucky state trajectories with action choice), by using "double learning" - one estimate of return is used to select maximising action, and another used to estimate the actual return from the next state. You probably will also prefer single-step learning over learning based on trajectories as most of the time your state trajectories will not contain learnable data. So <a href="https://arxiv.org/abs/1509.06461" rel="noreferrer">Double Deep Q Networks</a> might be a good starting algorithm to try.</p>
  
  <p>If you know <em>absolutely</em> from inspecting a current state, that the next state is independent of the current action, and the next state could in theory be almost anything (from either the whole state space or some large subset) then you may be able to adapt the algorithm to allow for that knowledge. You would do this by altering the TD target and replacing the terms for bootstrap estimate of next state with a rolling mean over all <em>reachable</em> next states. In concept this is similar to <em>Expected SARSA</em> - and in practice if it is possible, it would go a long way to reducing variance during learning process, and may speed up learning significantly. If you know the distribution of next states, you could maybe use that, but basing it purely on samples seen should also be fine, provided you can allocate the means to correct group of states (your question implies you have some understanding of how the states will group). Note that transitions from states with no action effect on next state to states which do have an effect from the action will need careful handling - they should not be assigned to the same "mean group", but should instead affect the TD target normally when they occur.</p>
  
  <p>If it is not possible for the agent to know whether it is in a state where its action affects the next state, except through experience, then you really have to use a standard RL solver.</p>
  
  <p>Finally, if you have a situation where the current <em>action</em> does not affect next state, but the current <em>state</em> definitely does in all cases -  the state "evolves", maybe stochastically, independently of the action taken in most cases, and can only change to a relatively small subset of next states from any given current state - then this is best solved with a normal RL solver - again double Q Learning might be a reasonable starting algorithm in that case.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-12T15:25:19.460Z
Answers.LastActivityDate: 2018-06-12T18:40:31.970Z
Answers.LastEditDate: 2018-06-12T18:40:31.970Z
Answers.UserDisplayName: Neil Slater
Body: <p>In a reinforcement learning model, states depend on the previous actions chosen. In the case in which some of the states -but not all- are fully independent of the actions -but still obviously determine the optimal actions-, how could we take these state variables into account?</p>
  
  <p>If the problem was a multiarmed bandit problem (where none of the actions influence the states), the solution would be a contextual multiarmed bandit problem. Though, if we need a "contextual reinforcement learning problem", how can we approach it?</p>
  
  <p>I can think of separating a continuous context into steps, and creating a reinforcement learning model for each of these steps. Then, is there any solution where these multiple RL models are used together, where each model is used for prediction and feedback proportionally to the closeness between the actual context and the context assigned to the RL model? Is this even a good approach?</p>
  
Tags: <reinforcement-learning><multi-armed-bandits><contextual-bandits>
Title: How to implement a contextual reinforcement learning model?
UserDisplayName: freesoul
ThreadText: # How to implement a contextual reinforcement learning model?
  
  (Asked by: username_0 on 2018-06-12)
  
  In a reinforcement learning model, states depend on the previous actions chosen. In the case in which some of the states -but not all- are fully independent of the actions -but still obviously determine the optimal actions-, how could we take these state variables into account?
  
  If the problem was a multiarmed bandit problem (where none of the actions influence the states), the solution would be a contextual multiarmed bandit problem. Though, if we need a "contextual reinforcement learning problem", how can we approach it?
  
  I can think of separating a continuous context into steps, and creating a reinforcement learning model for each of these steps. Then, is there any solution where these multiple RL models are used together, where each model is used for prediction and feedback proportionally to the closeness between the actual context and the context assigned to the RL model? Is this even a good approach?
  
  **Tags:** reinforcement-learning, multi-armed-bandits, contextual-bandits
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-12. Score: 5
  
  > In the case in which some of the states -but not all- are fully independent of the actions -but still obviously determine the optimal actions-, how could we take these state variables into account?
  
  I think the key thing here is the caveat **but not all**. What you have is a fully-featured MDP (states, actions, rewards, timesteps where next reward and next state depend on current state and action). The fact that next state is only marginally affected by the current action does not prevent it being an MDP.
  
  It would be a problem if the current state did not adequately describe this limitation e.g. if some other data, outside of observable state, decided whether action had any effect. Assuming that is not the case, then you still have a full reinforcement learning problem, but one with some unusual qualities.
  
  You can mitigate against problems caused by algorithms that will over-estimate likely reward (caused by algorithm associating lucky state trajectories with action choice), by using "double learning" - one estimate of return is used to select maximising action, and another used to estimate the actual return from the next state. You probably will also prefer single-step learning over learning based on trajectories as most of the time your state trajectories will not contain learnable data. So [Double Deep Q Networks](https://arxiv.org/abs/1509.06461) might be a good starting algorithm to try.
  
  If you know *absolutely* from inspecting a current state, that the next state is independent of the current action, and the next state could in theory be almost anything (from either the whole state space or some large subset) then you may be able to adapt the algorithm to allow for that knowledge. You would do this by altering the TD target and replacing the terms for bootstrap estimate of next state with a rolling mean over all *reachable* next states. In concept this is similar to *Expected SARSA* - and in practice if it is possible, it would go a long way to reducing variance during learning process, and may speed up learning significantly. If you know the distribution of next states, you could maybe use that, but basing it purely on samples seen should also be fine, provided you can allocate the means to correct group of states (your question implies you have some understanding of how the states will group). Note that transitions from states with no action effect on next state to states which do have an effect from the action will need careful handling - they should not be assigned to the same "mean group", but should instead affect the TD target normally when they occur.
  
  If it is not possible for the agent to know whether it is in a state where its action affects the next state, except through experience, then you really have to use a standard RL solver.
  
  Finally, if you have a situation where the current *action* does not affect next state, but the current *state* definitely does in all cases - the state "evolves", maybe stochastically, independently of the action taken in most cases, and can only change to a relatively small subset of next states from any given current state - then this is best solved with a normal RL solver - again double Q Learning might be a reasonable starting algorithm in that case.
  
  
  ---
  
  