Answers.Body: <blockquote>
    <p>Do I have to associate to each output an action?</p>
  </blockquote>
  
  <p>You are absolutely correct! In DQN, each output node of the neural network will be associated with one of your possible actions (assuming a <em>finite</em> discrete action space). After passing an input through the network, the value of each output node is the estimated q-value of the corresponding action. One benefit of this architecture is that you <strong>only need to pass the input through the neural network once to compute the q-value of each action</strong>, which is constant in the number of actions. If you were to include an action as an input to the neural network along with an observation, then you would need to pass an input for each action, which scales linearly in the number of actions. This is mentioned in paragraph 2 of Section 4.1 in the original DQN paper (<a href="https://arxiv.org/abs/1312.5602" rel="nofollow noreferrer">https://arxiv.org/abs/1312.5602</a>)</p>
  
  <blockquote>
    <p>Is it really the correct way? If so, how do you compute the argmax or the max?</p>
  </blockquote>
  
  <p>It's one possible way that is used in many popular algorithms such as DQN. To find the argmax, you simply take the action corresponding to the output node with highest q-value after passing an input through the network.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-05T17:54:27.773Z
Answers.LastActivityDate: 2020-06-05T17:54:27.773Z
Answers.UserDisplayName: DeepQZero
Body: <p>I'm new to RL and to deep q-learning and I have a simple question about the architecture of the neural network to use in an environment with a continous state space a discrete action space. </p>
  
  <p>I tought that the action <span class="math-container">$a_t$</span> should have been included as an input of the neural network, togheter with the state. It also made sense to me as when you have to compute the argmax or the max w.r.t. <span class="math-container">$a_t$</span> it was like a "standard" function. Then I've seen some examples of networks that had as inputs only <span class="math-container">$s_t$</span> and that had as many outputs as the number of possible actions. I quite understand the logic behind this (replicate the q-values pairs of action-state) but is it  really the correct way? If so, how do you compute the <span class="math-container">$argmax$</span> or the <span class="math-container">$max$</span>? Do I have to associate to each output an action?</p>
  
Tags: <deep-learning><reinforcement-learning><dqn><deep-neural-networks>
Title: What's the right way of building a deep Q-network?
UserDisplayName: alerd
ThreadText: # What's the right way of building a deep Q-network?
  
  (Asked by: username_0 on 2020-06-05)
  
  I'm new to RL and to deep q-learning and I have a simple question about the architecture of the neural network to use in an environment with a continous state space a discrete action space.
  
  I tought that the action $a\_t$ should have been included as an input of the neural network, togheter with the state. It also made sense to me as when you have to compute the argmax or the max w.r.t. $a\_t$ it was like a "standard" function. Then I've seen some examples of networks that had as inputs only $s\_t$ and that had as many outputs as the number of possible actions. I quite understand the logic behind this (replicate the q-values pairs of action-state) but is it really the correct way? If so, how do you compute the $argmax$ or the $max$? Do I have to associate to each output an action?
  
  **Tags:** deep-learning, reinforcement-learning, dqn, deep-neural-networks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-05. Score: 1 | Accepted answer
  
  > Do I have to associate to each output an action?
  
  You are absolutely correct! In DQN, each output node of the neural network will be associated with one of your possible actions (assuming a *finite* discrete action space). After passing an input through the network, the value of each output node is the estimated q-value of the corresponding action. One benefit of this architecture is that you **only need to pass the input through the neural network once to compute the q-value of each action**, which is constant in the number of actions. If you were to include an action as an input to the neural network along with an observation, then you would need to pass an input for each action, which scales linearly in the number of actions. This is mentioned in paragraph 2 of Section 4.1 in the original DQN paper (<https://arxiv.org/abs/1312.5602>)
  
  > Is it really the correct way? If so, how do you compute the argmax or the max?
  
  It's one possible way that is used in many popular algorithms such as DQN. To find the argmax, you simply take the action corresponding to the output node with highest q-value after passing an input through the network.
  
  
  ---
  
  