Answers.Body: <p>To answer your questions in order:</p>
  
  <blockquote>
    <p>What is <span class="math-container">$r_s $</span> used in the case where the score has not changed ?</p>
  </blockquote>
  
  <p>It is <span class="math-container">$0$</span>.</p>
  
  <blockquote>
    <p>Therefore what is the immediate rewards being modelled for temporal credit assignment problems in atari game ?</p>
  </blockquote>
  
  <p>Rewards <em>can</em> be re-modelled to aid speed of learning. This is called "<a href="https://pdfs.semanticscholar.org/41c5/0331ed5d3ffa51d879cc2e1a675c99445bc3.pdf" rel="nofollow noreferrer">reward shaping</a>", and is typically done by domain experts who can adjust numbers to reward known good intermediate states and actions.</p>
  
  <p>For DQN Atari, this was not done. Instead, the researchers performed a reward normalisation/scaling so that games which used moderate scoring system in single digits could be handled by the same neural network approximator as games that handed out thousands of points at a go.</p>
  
  <p>Using sparse rewards is standard practice in reinforcement learning, and the credit assignment problem is solved to some degree by <em>all</em> reinforcement learning methods. Essentially the value functions work as a prediction mechanism theoretically whatever the reward sparsity, so if they are correct, thay can be used to drive policy whether the next reward is 1, 50 or 1000 time steps away. The reward <em>backup</em> updates in everything from Value Iteration, through Monte Carlo Control, SARSA, Q-Learning and Actor-Critic all backup values to states/actions seen in earlier time steps. This value backup is a basic mechanism that addresses credit assignment in principle. The credit assignment problem is then a matter of degree and difficulty of different environments, such that sometimes it is readily solved, and other times it is a major hurdle.</p>
  
  <p>In the case of video games, especially older arcade games, it is often not a very hard part of the problem. The games are designed to reward human players by incrementing scores frequently, with very many sub-goals already within the game. In fact this is one of the attractions of video games as toy environments for developing new algorithms.</p>
  
  <p>For example the classic space invaders does not simply score +1 for surviving a wave of enemies, but adds points for every player missile that hits. Although the score does not increment on every frame, the reward sparsity is relatively low for games like this, and simple single-step Q learning with experience replay can solve the credit assignment problem readily for that environment (experience replay does help a little with credit assignment). This was what was demonstrated with the original DQN Atari paper, there were no extra allowances made for reward sparsity.</p>
  
  <blockquote>
    <p>If <span class="math-container">$r_s$</span> is indeed 0 until score changes, would it affect the accuracy of the DQN ?</p>
  </blockquote>
  
  <p>Not directly, the DQN predicts future expected rewards and can in principle account for delay and sparsity in its estimates. However, if this becomes very sparse you get two problems:</p>
  
  <ul>
  <li><p>Discovering the positive rewards within the environment may take a long time, and may require more advanced techniques, such as reward shaping to encourage searching behaviour (a small negative reward per time step) or "<a href="https://towardsdatascience.com/curiosity-driven-learning-made-easy-part-i-d3e5a2263359" rel="nofollow noreferrer">curiousity</a>"</p></li>
  <li><p>Credit assignment becomes much harder as the possible number of combinations that <em>could</em> of contributed to success can grow exponentially with temporal distance between rewards. Resolving whch ones are important, especially early in a trajectory leading to reward, can take many samples.</p></li>
  </ul>
  
  <blockquote>
    <p>What are some of the current methods used to solve the temporal credit assignment problem ?</p>
  </blockquote>
  
  <p>As noted above, this is core problem in RL, so there are many approaches in the literature. Some standard approaches are:</p>
  
  <ul>
  <li><p>Background planning as used by DynaQ, or experience replay. This re-evaluates states and actions seen before whilst using latest estimates, and can backup values to where important decisions are made within a trajectory. <a href="https://arxiv.org/abs/1511.05952" rel="nofollow noreferrer">Prioritised experience replay</a> helps even more by focusing on updates that make the most difference to the current estimates.</p></li>
  <li><p>TD(<span class="math-container">$\lambda$</span>) with <a href="https://towardsdatascience.com/eligibility-traces-in-reinforcement-learning-a6b458c019d6" rel="nofollow noreferrer">eligibility traces</a>. Eligibility traces are intuitively a credit-assignment mechanism, they track state features that were active recently and multiply value updates based on the trace vector. Again, this causes state or state action values to backup to earlier parts of trajectories faster.</p></li>
  <li><p>Reward shaping as discussed above. In some research settings this might be seen as "cheating" - for instance when facing a standardised environment test for developing algorithms, adding in domain knowledge to help the agent just demonstrates the core algorithm is weaker than claimed. However, when the challenge presented is to solve an environment with the best agent possible, it is fine to use any knoweldge (or of course not to use RL at all).</p></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-12T01:36:04.697Z
Answers.Text: hey Neil thank you for the detailed explanation above ! but why would you need to normalise the rewards for a NN to handle large and moderate rewards and what do you mean by reward backup ?
Answers.UserDisplayName: calveeen
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-12T07:40:00.103Z
Answers.Text: @calveeen: i explain why you need to normalise the rewards in the answer - to prevent the NN needing to handle value predictions (and associated errors) ranging from +1 to +10000 depending on the game. This would impact hyperparameters such as learning rate, and the goal of the exercise was to have one agent that could solve all games without interventions such as hyperparameter search specific to each game. I.e. the agent is ia generalist Atarii game solver out of the box.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-12T07:43:17.043Z
Answers.Text: @calveeen: reward backup is the process of propagating reward values seen backwards through the trajectory, which is what all the value-based methods do in their update steps. It is related to the backup diagrams, see https://towardsdatascience.com/all-about-backup-diagram-fefb25aaf804
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-11T20:20:22.417Z
Answers.LastActivityDate: 2020-02-11T20:52:06.233Z
Answers.LastEditDate: 2020-02-11T20:52:06.233Z
Answers.UserDisplayName: Neil Slater
Body: <p>I am trying to understand the different reward functions modelled in a reinforcement learning problem. I want to be able to know how the temporal credit assignment problem, (where the reward is observed only after many sequences of actions, and hence no immediate rewards observed) can be mitigated. </p>
  
  <p>From reading the DQN paper, I am not able to sieve out how the immediate rewards are being modelled when <span class="math-container">$Q_{target}(s,a; \theta) = r_s + argmax_aQ(s',a'; \theta)$</span>. What is <span class="math-container">$r_s $</span> used in the case where the score has not changed ? Therefore what is the immediate rewards being modelled for temporal credit assignment problems in atari game ? </p>
  
  <p>If <span class="math-container">$r_s$</span> is indeed 0 until score changes, would it affect the accuracy of the DQN ? it seems like the update equation would not be accurate if you do not even know what is the immediate reward if you take that action.</p>
  
  <p>What are some of the current methods used to solve the temporal credit assignment problem ?</p>
  
  <p>Also, I can't seem to find many papers that address the temporal credit assignment problem</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-11T17:02:03.487Z
Comments.Text: Hi Neil, yes immediate reward is the word. I will change it
Comments.UserDisplayName: calveeen
Tags: <reinforcement-learning><deep-rl><rewards>
Title: Immediate reward received in Atari game using DQN
UserDisplayName: calveeen
ThreadText: # Immediate reward received in Atari game using DQN
  
  (Asked by: username_0 on 2020-02-11)
  
  I am trying to understand the different reward functions modelled in a reinforcement learning problem. I want to be able to know how the temporal credit assignment problem, (where the reward is observed only after many sequences of actions, and hence no immediate rewards observed) can be mitigated.
  
  From reading the DQN paper, I am not able to sieve out how the immediate rewards are being modelled when $Q\_{target}(s,a; \theta) = r\_s + argmax\_aQ(s',a'; \theta)$. What is $r\_s $ used in the case where the score has not changed ? Therefore what is the immediate rewards being modelled for temporal credit assignment problems in atari game ?
  
  If $r\_s$ is indeed 0 until score changes, would it affect the accuracy of the DQN ? it seems like the update equation would not be accurate if you do not even know what is the immediate reward if you take that action.
  
  What are some of the current methods used to solve the temporal credit assignment problem ?
  
  Also, I can't seem to find many papers that address the temporal credit assignment problem
  
  **Tags:** reinforcement-learning, deep-rl, rewards
  
  > **Comments:**
  > **username_0**: Hi username_1, yes immediate reward is the word. I will change it  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-11. Score: 2 | Accepted answer
  
  To answer your questions in order:
  
  > What is $r\_s $ used in the case where the score has not changed ?
  
  It is $0$.
  
  > Therefore what is the immediate rewards being modelled for temporal credit assignment problems in atari game ?
  
  Rewards *can* be re-modelled to aid speed of learning. This is called "[reward shaping](https://pdfs.semanticscholar.org/41c5/0331ed5d3ffa51d879cc2e1a675c99445bc3.pdf)", and is typically done by domain experts who can adjust numbers to reward known good intermediate states and actions.
  
  For DQN Atari, this was not done. Instead, the researchers performed a reward normalisation/scaling so that games which used moderate scoring system in single digits could be handled by the same neural network approximator as games that handed out thousands of points at a go.
  
  Using sparse rewards is standard practice in reinforcement learning, and the credit assignment problem is solved to some degree by *all* reinforcement learning methods. Essentially the value functions work as a prediction mechanism theoretically whatever the reward sparsity, so if they are correct, thay can be used to drive policy whether the next reward is 1, 50 or 1000 time steps away. The reward *backup* updates in everything from Value Iteration, through Monte Carlo Control, SARSA, Q-Learning and Actor-Critic all backup values to states/actions seen in earlier time steps. This value backup is a basic mechanism that addresses credit assignment in principle. The credit assignment problem is then a matter of degree and difficulty of different environments, such that sometimes it is readily solved, and other times it is a major hurdle.
  
  In the case of video games, especially older arcade games, it is often not a very hard part of the problem. The games are designed to reward human players by incrementing scores frequently, with very many sub-goals already within the game. In fact this is one of the attractions of video games as toy environments for developing new algorithms.
  
  For example the classic space invaders does not simply score +1 for surviving a wave of enemies, but adds points for every player missile that hits. Although the score does not increment on every frame, the reward sparsity is relatively low for games like this, and simple single-step Q learning with experience replay can solve the credit assignment problem readily for that environment (experience replay does help a little with credit assignment). This was what was demonstrated with the original DQN Atari paper, there were no extra allowances made for reward sparsity.
  
  > If $r\_s$ is indeed 0 until score changes, would it affect the accuracy of the DQN ?
  
  Not directly, the DQN predicts future expected rewards and can in principle account for delay and sparsity in its estimates. However, if this becomes very sparse you get two problems:
  
  * Discovering the positive rewards within the environment may take a long time, and may require more advanced techniques, such as reward shaping to encourage searching behaviour (a small negative reward per time step) or "[curiousity](https://towardsdatascience.com/curiosity-driven-learning-made-easy-part-i-d3e5a2263359)"
  * Credit assignment becomes much harder as the possible number of combinations that *could* of contributed to success can grow exponentially with temporal distance between rewards. Resolving whch ones are important, especially early in a trajectory leading to reward, can take many samples.
  
  > What are some of the current methods used to solve the temporal credit assignment problem ?
  
  As noted above, this is core problem in RL, so there are many approaches in the literature. Some standard approaches are:
  
  * Background planning as used by DynaQ, or experience replay. This re-evaluates states and actions seen before whilst using latest estimates, and can backup values to where important decisions are made within a trajectory. [Prioritised experience replay](https://arxiv.org/abs/1511.05952) helps even more by focusing on updates that make the most difference to the current estimates.
  * TD($\lambda$) with [eligibility traces](https://towardsdatascience.com/eligibility-traces-in-reinforcement-learning-a6b458c019d6). Eligibility traces are intuitively a credit-assignment mechanism, they track state features that were active recently and multiply value updates based on the trace vector. Again, this causes state or state action values to backup to earlier parts of trajectories faster.
  * Reward shaping as discussed above. In some research settings this might be seen as "cheating" - for instance when facing a standardised environment test for developing algorithms, adding in domain knowledge to help the agent just demonstrates the core algorithm is weaker than claimed. However, when the challenge presented is to solve an environment with the best agent possible, it is fine to use any knoweldge (or of course not to use RL at all).
  
  > **Comments:**
  > **username_0**: hey username_1 thank you for the detailed explanation above ! but why would you need to normalise the rewards for a NN to handle large and moderate rewards and what do you mean by reward backup ?  
  > **username_1**: @username_0: i explain why you need to normalise the rewards in the answer - to prevent the NN needing to handle value predictions (and associated errors) ranging from +1 to +10000 depending on the game. This would impact hyperparameters such as learning rate, and the goal of the exercise was to have one agent that could solve all games without interventions such as hyperparameter search specific to each game. I.e. the agent is ia generalist Atarii game solver out of the box.  
  > **username_1**: @username_0: reward backup is the process of propagating reward values seen backwards through the trajectory, which is what all the value-based methods do in their update steps. It is related to the backup diagrams, see https://towardsdatascience.com/all-about-backup-diagram-fefb25aaf804  
  
  ---
  
  