Answers.Body: <p>First, the problem you're raising also applies to tabular Q-learning or DQN without the target network because the max operation exists in those algorithms too.</p>
  <p>Second, note that the Q-network should be initialised randomly, so that means that the initial <span class="math-container">$Q(s, a)$</span> should be different for all states and actions pairs (at least at the beginning).</p>
  <p>Let's ignore the target network then.</p>
  <p>Now, you should look at algorithm 1 in <a href="https://storage.googleapis.com/deepmind-media/dqn/DQNNaturePaper.pdf" rel="nofollow noreferrer">the DQN paper</a></p>
  <p>You're right the max operation selects only one value. However, as you can see from the algorithm, we don't use this target value to update all state-action pairs, but just one, the one at time-step <span class="math-container">$t$</span>, denoted by <span class="math-container">$(s_t, a_t)$</span> in tabular Q-learning, and <span class="math-container">$(\phi_t, a_t)$</span> in DQN. The target would be denoted by <span class="math-container">$y_t$</span> in DQN.</p>
  <p>Note also that the target is not just the max, but also the reward. The reward you observe may be different for each state-action. So, no, the target value is not always the same, even if you keep the target network frozen forever, which is not usually the case - we update the target network every <span class="math-container">$C$</span> steps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-07T12:13:14.137Z
Answers.Text: I know the reward(prediction of the target network) will change in time. I understood mostly you said thanks but just to make sure one more question: So, the prediction network's "target output" for the third output will be the value of the third output of the target network even if it isn't the maximum Q value between the predictions, right?
Answers.UserDisplayName: Ege
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-07T13:14:27.290Z
Answers.Text: The reward and the prediction of the target network are not the same thing. The target network estimates the return. The return is not the same thing as the reward. The return is the (cumulative/discounted) sum of rewards. The reward that I meant was what you denoted by $R(t+1)$. In the paper's algorithm, it's denoted by $r_t$. I am not sure what you mean by "prediction network". In any case, the target value is calculated using $r_t$, which depends on the action that you take while exploring (see the algorithm), and the maximum value at the state $s_t$.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-07T13:15:49.270Z
Answers.Text: In the same state $s_t$, the maximum Q-value is always the same if the Q-network does not change. However, it might be different across states, of course. The reward $r_t$ in the same state $s_t$ may also be different. This depends on the reward function (which is not the reward, return or Q-network - it's a function that also defines the MDP, problem, and gives you the reward) because you may end up in the state $s_t$ because of different events.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-07T16:24:22.373Z
Answers.Text: Yes sorry for the stupid mixing the reward and target Q value, when I am writing it, in my mind it was Q value but I wrote it as reward. Silly mistake. I am asking again and again sorry but I want to understand it well. To be more clear, in my DQN I am using MSE loss function. All I am asking is when calculating the MSE's derivative for the gradient decant, I am subtracting the predictions from target values for all output values(O1-o1, O2-o2, O3-o3...) and should I do that like this also in DQN. I am confused because at DQN loss is calculated according to max of the Q values beside the normal
Answers.UserDisplayName: Ege
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-07T21:30:51.867Z
Answers.Text: If you're doing some kind of batch GD, you should calculate the maximum value and reward, so the target, for each different $(s_t, a_t)$. They might not be the same. But, tbh, I'm not familiar with the typical DQN implementations.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-07T12:00:25.640Z
Answers.LastActivityDate: 2023-08-07T12:00:25.640Z
Answers.UserDisplayName: nbro
Body: <p>So I am trying to understand and make a DQN. But I didn't understand a part. So basically state's Q values computed with the network and the target Q values will also compute with a target network according to the next state. Then the results will pass into the Bellman equation that is (R(t+1) + Q_max(s(t+1),a'). But this taking the maximum thing makes all actions' Q values same, right? And target's Q values being same means the network try to make predictions for different actions (in other words network's outputs) very similar. Am I missing somewhere or is there something I didn't know?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-06T19:04:33.643Z
Comments.Text: please consider checking the structure/spelling of the question, it's very hard to get what's your point
Comments.UserDisplayName: Alberto
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-07T11:43:01.897Z
Comments.Text: Well, you can ask the same question without the target network. What happens in tabular Q-learning? There's a max there too.
Comments.UserDisplayName: nbro
Tags: <neural-networks><reinforcement-learning><dqn>
Title: Are All the Target Q Values in DQN same?
UserDisplayName: Ege
ThreadText: # Are All the Target Q Values in DQN same?
  
  (Asked by: username_0 on 2023-08-06)
  
  So I am trying to understand and make a DQN. But I didn't understand a part. So basically state's Q values computed with the network and the target Q values will also compute with a target network according to the next state. Then the results will pass into the Bellman equation that is (R(t+1) + Q\_max(s(t+1),a'). But this taking the maximum thing makes all actions' Q values same, right? And target's Q values being same means the network try to make predictions for different actions (in other words network's outputs) very similar. Am I missing somewhere or is there something I didn't know?
  
  **Tags:** neural-networks, reinforcement-learning, dqn
  > **Comments:**
  > **username_1**: please consider checking the structure/spelling of the question, it's very hard to get what's your point  
  > **username_2**: Well, you can ask the same question without the target network. What happens in tabular Q-learning? There's a max there too.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2023-08-07. Score: 3 | Accepted answer
  
  First, the problem you're raising also applies to tabular Q-learning or DQN without the target network because the max operation exists in those algorithms too.
  
  Second, note that the Q-network should be initialised randomly, so that means that the initial $Q(s, a)$ should be different for all states and actions pairs (at least at the beginning).
  
  Let's ignore the target network then.
  
  Now, you should look at algorithm 1 in [the DQN paper](https://storage.googleapis.com/deepmind-media/dqn/DQNNaturePaper.pdf)
  
  You're right the max operation selects only one value. However, as you can see from the algorithm, we don't use this target value to update all state-action pairs, but just one, the one at time-step $t$, denoted by $(s\_t, a\_t)$ in tabular Q-learning, and $(\phi\_t, a\_t)$ in DQN. The target would be denoted by $y\_t$ in DQN.
  
  Note also that the target is not just the max, but also the reward. The reward you observe may be different for each state-action. So, no, the target value is not always the same, even if you keep the target network frozen forever, which is not usually the case - we update the target network every $C$ steps.
  
  > **Comments:**
  > **username_0**: I know the reward(prediction of the target network) will change in time. I understood mostly you said thanks but just to make sure one more question: So, the prediction network's "target output" for the third output will be the value of the third output of the target network even if it isn't the maximum Q value between the predictions, right?  
  > **username_2**: The reward and the prediction of the target network are not the same thing. The target network estimates the return. The return is not the same thing as the reward. The return is the (cumulative/discounted) sum of rewards. The reward that I meant was what you denoted by $R(t+1)$. In the paper's algorithm, it's denoted by $r_t$. I am not sure what you mean by "prediction network". In any case, the target value is calculated using $r_t$, which depends on the action that you take while exploring (see the algorithm), and the maximum value at the state $s_t$.  
  > **username_2**: In the same state $s_t$, the maximum Q-value is always the same if the Q-network does not change. However, it might be different across states, of course. The reward $r_t$ in the same state $s_t$ may also be different. This depends on the reward function (which is not the reward, return or Q-network - it's a function that also defines the MDP, problem, and gives you the reward) because you may end up in the state $s_t$ because of different events.  
  > **username_0**: Yes sorry for the stupid mixing the reward and target Q value, when I am writing it, in my mind it was Q value but I wrote it as reward. Silly mistake. I am asking again and again sorry but I want to understand it well. To be more clear, in my DQN I am using MSE loss function. All I am asking is when calculating the MSE's derivative for the gradient decant, I am subtracting the predictions from target values for all output values(O1-o1, O2-o2, O3-o3...) and should I do that like this also in DQN. I am confused because at DQN loss is calculated according to max of the Q values beside the normal  
  > **username_2**: If you're doing some kind of batch GD, you should calculate the maximum value and reward, so the target, for each different $(s_t, a_t)$. They might not be the same. But, tbh, I'm not familiar with the typical DQN implementations.  
  
  ---
  
  