Answers.Body: <p>It's not on your end, as a creator of flight simulator, to worry about what action should get the credit for the reward that happened some time after the action was taken. You should return the reward when the actual event happens not when the action that caused it happened. It's the job of the reinforcement learning agent to figure that out. For example if you want to give a reward when airplane nose is at 45 degrees from the horizontal axis, you should return the reward when that event actually happens, RL agent should figure out that the crucial action happened some time ago. This may be difficult for the agent but its up to the user to use a proper algorithm and proper exploration strategy to solve the problem.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T15:32:02.337Z
Answers.Text: I think you got me wrong: I'm not the creator of the flight simulator, but the creator of the agent and of the gym-interface. What you said in the second half of your response is the interesting part for me: When I get you right, you propose, that the agent sees the reward corresponding to the current situation, no matter when the action happend, that led to this situation.
  
  So the delay between action and reward shall be figured out by a proper algorithm in the agent. Will we need some special treatment in the agent, or will this turn out in the course of learning?
Answers.UserDisplayName: opt12
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T15:54:09.290Z
Answers.Text: Strong feature of RL is that it deals well with temporal credit assignment problem, in general you shouldn't need any specialized techniques, standard deep RL algorithms like PPO, ACER, DQN, etc. should be able to work fine, some better, some worse, you should try it out. Your case isn't unique, currently in OpenAI Gym there are environments with same challenges, especially Atari games. For example Pong, you get a reward when you score against opponent, but the action that "scored" happened when you touched the ball with paddle and between those 2 moments several frames and actions happened.
Answers.UserDisplayName: Brale
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T15:08:59.973Z
Answers.LastActivityDate: 2019-05-27T15:08:59.973Z
Answers.UserDisplayName: Brale
Body: <p>I'm about to create an OpenAI Gym environment for a flight simulator. I'm wondering, how to cope with the fact, that the result and reward for some action needs a considerable time to advance through the system due to the inherent time constants.</p>
  
  <p>In the easy example Gym-environments (e. g. cartpole, or some games) the step can anstantly be executed and the resulting reard can be calculated.</p>
  
  <p>In my continuous control system (aka flight simulator), There is some reaction time needed, until I can calculate the result from my action. E. g. When I pull the stick, it takes some time, until the aircraft lifts it's nose. So there is a considerable delay (maybe in the seconds ballpark) from commanding the action to the environment, and the earliest observation of that result and it's corresponding reward.</p>
  
  <p>How can I cope with that. As far as I understood, the <code>env.step(action)</code> function blocks till it comes back with a new observation and a corresponding reward.</p>
  
  <ul>
  <li>How can I cope with long lasting reward caclulations?</li>
  <li>Is it possible to have overlapping actions somehow? E. g. command a new action every 100ms, but get the reward for that action only 1 second later. In this case there would be always 10 rewards pending.</li>
  </ul>
  
  <p>I hope I made my point clear. Don't hesitate to ask for further details in the comments.</p>
  
  <p>Any hints are welcome. Is there anything to read out in the wild dealing with a similar issue?</p>
  
  <p>Cheers,</p>
  
  <p>Felix</p>
  
Tags: <reinforcement-learning><open-ai><gym>
Title: OpenAI Gym interface when reward calculation is delayed? (continuous control with considerable reaction time)
UserDisplayName: opt12
ThreadText: # OpenAI Gym interface when reward calculation is delayed? (continuous control with considerable reaction time)
  
  (Asked by: username_0 on 2019-05-27)
  
  I'm about to create an OpenAI Gym environment for a flight simulator. I'm wondering, how to cope with the fact, that the result and reward for some action needs a considerable time to advance through the system due to the inherent time constants.
  
  In the easy example Gym-environments (e. g. cartpole, or some games) the step can anstantly be executed and the resulting reard can be calculated.
  
  In my continuous control system (aka flight simulator), There is some reaction time needed, until I can calculate the result from my action. E. g. When I pull the stick, it takes some time, until the aircraft lifts it's nose. So there is a considerable delay (maybe in the seconds ballpark) from commanding the action to the environment, and the earliest observation of that result and it's corresponding reward.
  
  How can I cope with that. As far as I understood, the `env.step(action)` function blocks till it comes back with a new observation and a corresponding reward.
  
  * How can I cope with long lasting reward caclulations?
  * Is it possible to have overlapping actions somehow? E. g. command a new action every 100ms, but get the reward for that action only 1 second later. In this case there would be always 10 rewards pending.
  
  I hope I made my point clear. Don't hesitate to ask for further details in the comments.
  
  Any hints are welcome. Is there anything to read out in the wild dealing with a similar issue?
  
  Cheers,
  
  Felix
  
  **Tags:** reinforcement-learning, open-ai, gym
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-27. Score: 1
  
  It's not on your end, as a creator of flight simulator, to worry about what action should get the credit for the reward that happened some time after the action was taken. You should return the reward when the actual event happens not when the action that caused it happened. It's the job of the reinforcement learning agent to figure that out. For example if you want to give a reward when airplane nose is at 45 degrees from the horizontal axis, you should return the reward when that event actually happens, RL agent should figure out that the crucial action happened some time ago. This may be difficult for the agent but its up to the user to use a proper algorithm and proper exploration strategy to solve the problem.
  
  > **Comments:**
  > **username_0**: I think you got me wrong: I'm not the creator of the flight simulator, but the creator of the agent and of the gym-interface. What you said in the second half of your response is the interesting part for me: When I get you right, you propose, that the agent sees the reward corresponding to the current situation, no matter when the action happend, that led to this situation.  So the delay between action and reward shall be figured out by a proper algorithm in the agent. Will we need some special treatment in the agent, or will this turn out in the course of learning?  
  > **username_1**: Strong feature of RL is that it deals well with temporal credit assignment problem, in general you shouldn't need any specialized techniques, standard deep RL algorithms like PPO, ACER, DQN, etc. should be able to work fine, some better, some worse, you should try it out. Your case isn't unique, currently in OpenAI Gym there are environments with same challenges, especially Atari games. For example Pong, you get a reward when you score against opponent, but the action that "scored" happened when you touched the ball with paddle and between those 2 moments several frames and actions happened.  
  
  ---
  
  