Answers.Body: <p>This depends on whether the output is a continuous or discrete variable. If the output variable is discrete (there are a finite number of possibilities that it can be), as in a classification task (such as this one, where you are trying to place the input into one of 5 categories), you want to use one output neuron for each class. If the variable is continuous, however, you should only use one output neuron. </p>
  
  <p>This is because of how the training process works. When training your network successively makes adjustments to try and reduce the errors. These adjustments are made in the direction of the error – so if the network predicts a value which is too high then the network's weights are adjusted to make the output value lower. On the other hand if the network's predicts a value which is too low the network's weights are adjusted to make the output bigger.</p>
  
  <p>If you have output neurons labeled 0 to 4 and a training sample with some input value and a target prediction of 2 then the neural network will make its prediction. Once the prediction has made each neuron is adjusted individually – in this case neuron 2 will be adjusted in the direction of the correct probability and all the other neurons will be adjusted in the direction of the incorrect probability. In this way you have one prediction for each class. </p>
  
  <p>Backpropagation is a about error attribution, and using multiple neurons allows the error of the neural network to be better attributed as the neural network can adjust each neuron individually, and thus adjust the required probabilities for each class. </p>
  
  <p>Using a single neuron with a sigmoid activation function would be less good as the sigmoid function saturates values close to 0 and 1 so there would be an unnatural bias towards category 0 and category 4 over the other categories. The neural network could learn to overcome this, but it would take more time.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-14T05:45:45.490Z
Answers.Text: Thanks. Various sources [such as this](https://stats.stackexchange.com/questions/207049/neural-network-for-binary-classification-use-1-or-2-output-neurons) suggest that in the case of BINARY classification it is OK to use a single neuron with sigmoid and round to TRUE or FALSE based on a >0.5 and <0.5 criteria. But based on your response, I infer that if we have more classes, this approach is not so OK because referring back to our example, the sigmoid 'squashing' can result in an inability to distinguish between say a 0 and 1 rating, or a 3 and 4 rating. Do I infer correctly?
Answers.UserDisplayName: samiant
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-14T06:39:06.700Z
Answers.Text: Yes. If you have only two classes it's fine to use a single output neuron to predict the probability of one of the classes and (as probabilities sum to 1) calculate the probability of the other class as 1 - [predicted probability of the first class]. The network can learn to handle the squashing caused by the sigmoid function but it will learn better and more efficiently using multiple output neurons.
Answers.UserDisplayName: Teymour
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-13T15:52:40.207Z
Answers.LastActivityDate: 2019-08-14T06:43:52.777Z
Answers.LastEditDate: 2019-08-14T06:43:52.777Z
Answers.UserDisplayName: Teymour
Answers.Body: <p>A somewhat large set of designs and set-ups can be made to learn a rating function for a given set of labeled examples.  If the objectives are simplicity and effectiveness (accuracy, reliability, and speed), then a third option should be considered.</p>
  
  <p>The requirement in the question includes, "Outputs an integer rating 0 [through] 4 [inclusive]."  For such a discrete result, the number of required output bits <span class="math-container">$b$</span> (where <span class="math-container">$s$</span> is the number of possible states and <span class="math-container">$I$</span> is the set of integers) is given as follows.</p>
  
  <p><span class="math-container">$$\min_b \, (b \in I \; \land \; b \ge \log_2 s)$$</span></p>
  
  <p>In this case, we require three bits of output.</p>
  
  <p><span class="math-container">$$s = 5 \quad \implies \quad b = 3$$</span></p>
  
  <p>Note that with similar configuration ratings of 0 through 7 would also require only three bits of output.  Either way, the output layer would likely be simplest and most efficient if its activation function was binary step function.  This removes the need for rounding after it is applied.  The output layer would then provide a binary value indicating rating.  The goal of learning would be to reduce the error between the feed forward output and the associated the binary value of the label for each example.</p>
  
  <p>Previous layer(s) could be sigmoid or a more contemporary and less problematic continuous activation function like ISRLU.</p>
  
  <p>Since the engineer can select the error function used by the learning framework to accept any input range and distribution, normalizing the labels for supervised learning is primarily employed to remove redundancy from time and resource consuming operations required to compute error.  With ratings as the labels, unless the distribution of ratings is skewed and the data set is such that learning time is excessive, normalization may not be necessary.  If it is, it would likely be because improving the label distribution in advance (requiring floating point input to the error function and removing skew) would reduce learning time.</p>
  
  <p>The other two approaches introduce unnecessary complexities mentioned in context above.  A consequence of removing complexities without adding impediments to convergence is more efficiency during learning and during execution after learning.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-20T12:28:34.353Z
Answers.LastActivityDate: 2019-08-20T12:28:34.353Z
Answers.UserDisplayName: Douglas Daseeco
Answers.Body: <p>In the case of one output neuron, you don't have to use sigmoid. As Teymour Aldridge suggested, it would cause a tendency to output 0 or 1. What I normally do is that I set the layer before the output layer to sigmoid of tanh so it won't output ridiculously off numbers, and set the output layer to linear. There would be cases that it outputs something like 1.5, but over time that disappears.</p>
  
  <p>Hope it helps :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-15T22:58:34.947Z
Answers.Text: I have one hidden layer consisting of sigmoid-ed neurons, and one sigmoid-ed output neuron. This structure is really for 'regression' problems, but based on responses so far, would it be correct to say that it can be 'adapted' for my classification problem by removing the sigmoid on the output neuron so that the result becomes unbounded, and then classify per: rating 0 if <0.5. rating 1 if >0.5 and <1.5. rating 2 if >1.5 and <2.5. rating 3 if >2.5 and <3.5. rating 4 if >3.5. What are the expected disadvantages of doing it this way - eg. less accuracy for the same number of epochs?
Answers.UserDisplayName: samiant
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-14T08:14:56.780Z
Answers.LastActivityDate: 2019-08-14T08:14:56.780Z
Answers.UserDisplayName: Kenivia
Body: <p>Consider an MLP that outputs an integer 'rating' of 0 to 4. Would it be correct to say this could be modeled in either of the following ways:</p>
  
  <ol>
  <li><p>map each rating in the dataset to a 'normalized set' between 0 and 1 (i.e. 0, 0.25, 0.5, 0.75, 1), have a single neuron with sigmoid activation at output provide a single decimal value and then take as the rating whatever is closest to that value in the 'normalized set'</p></li>
  <li><p>have 5 output neurons with a softmax activation function output 5 values, each representing a probability of one of the 5 ratings as the outcome, and then take as the rating whichever neuron gives the highest probability?</p></li>
  </ol>
  
  <p>If this is indeed the case, how does one typically decide 'which way to go'? Approach 1 certainly appears to yield a simpler model. What are the considerations, pros/cons of each approach? Perhaps a couple of concrete examples to illustrate?</p>
  
Tags: <neural-networks><machine-learning><ai-design><multilayer-perceptrons>
Title: One vs multiple output neurons
UserDisplayName: samiant
ThreadText: # One vs multiple output neurons
  
  (Asked by: username_0 on 2019-08-13)
  
  Consider an MLP that outputs an integer 'rating' of 0 to 4. Would it be correct to say this could be modeled in either of the following ways:
  
  1. map each rating in the dataset to a 'normalized set' between 0 and 1 (i.e. 0, 0.25, 0.5, 0.75, 1), have a single neuron with sigmoid activation at output provide a single decimal value and then take as the rating whatever is closest to that value in the 'normalized set'
  2. have 5 output neurons with a softmax activation function output 5 values, each representing a probability of one of the 5 ratings as the outcome, and then take as the rating whichever neuron gives the highest probability?
  
  If this is indeed the case, how does one typically decide 'which way to go'? Approach 1 certainly appears to yield a simpler model. What are the considerations, pros/cons of each approach? Perhaps a couple of concrete examples to illustrate?
  
  **Tags:** neural-networks, machine-learning, ai-design, multilayer-perceptrons
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2019-08-13. Score: 1
  
  This depends on whether the output is a continuous or discrete variable. If the output variable is discrete (there are a finite number of possibilities that it can be), as in a classification task (such as this one, where you are trying to place the input into one of 5 categories), you want to use one output neuron for each class. If the variable is continuous, however, you should only use one output neuron.
  
  This is because of how the training process works. When training your network successively makes adjustments to try and reduce the errors. These adjustments are made in the direction of the error – so if the network predicts a value which is too high then the network's weights are adjusted to make the output value lower. On the other hand if the network's predicts a value which is too low the network's weights are adjusted to make the output bigger.
  
  If you have output neurons labeled 0 to 4 and a training sample with some input value and a target prediction of 2 then the neural network will make its prediction. Once the prediction has made each neuron is adjusted individually – in this case neuron 2 will be adjusted in the direction of the correct probability and all the other neurons will be adjusted in the direction of the incorrect probability. In this way you have one prediction for each class.
  
  Backpropagation is a about error attribution, and using multiple neurons allows the error of the neural network to be better attributed as the neural network can adjust each neuron individually, and thus adjust the required probabilities for each class.
  
  Using a single neuron with a sigmoid activation function would be less good as the sigmoid function saturates values close to 0 and 1 so there would be an unnatural bias towards category 0 and category 4 over the other categories. The neural network could learn to overcome this, but it would take more time.
  
  > **Comments:**
  > **username_0**: Thanks. Various sources [such as this](https://stats.stackexchange.com/questions/207049/neural-network-for-binary-classification-use-1-or-2-output-neurons) suggest that in the case of BINARY classification it is OK to use a single neuron with sigmoid and round to TRUE or FALSE based on a >0.5 and <0.5 criteria. But based on your response, I infer that if we have more classes, this approach is not so OK because referring back to our example, the sigmoid 'squashing' can result in an inability to distinguish between say a 0 and 1 rating, or a 3 and 4 rating. Do I infer correctly?  
  > **username_1**: Yes. If you have only two classes it's fine to use a single output neuron to predict the probability of one of the classes and (as probabilities sum to 1) calculate the probability of the other class as 1 - [predicted probability of the first class]. The network can learn to handle the squashing caused by the sigmoid function but it will learn better and more efficiently using multiple output neurons.  
  
  ---
  
  ### Answer by username_2 on 2019-08-20. Score: 0
  
  A somewhat large set of designs and set-ups can be made to learn a rating function for a given set of labeled examples. If the objectives are simplicity and effectiveness (accuracy, reliability, and speed), then a third option should be considered.
  
  The requirement in the question includes, "Outputs an integer rating 0 [through] 4 [inclusive]." For such a discrete result, the number of required output bits $b$ (where $s$ is the number of possible states and $I$ is the set of integers) is given as follows.
  
  $$\min\_b \, (b \in I \; \land \; b \ge \log\_2 s)$$
  
  In this case, we require three bits of output.
  
  $$s = 5 \quad \implies \quad b = 3$$
  
  Note that with similar configuration ratings of 0 through 7 would also require only three bits of output. Either way, the output layer would likely be simplest and most efficient if its activation function was binary step function. This removes the need for rounding after it is applied. The output layer would then provide a binary value indicating rating. The goal of learning would be to reduce the error between the feed forward output and the associated the binary value of the label for each example.
  
  Previous layer(s) could be sigmoid or a more contemporary and less problematic continuous activation function like ISRLU.
  
  Since the engineer can select the error function used by the learning framework to accept any input range and distribution, normalizing the labels for supervised learning is primarily employed to remove redundancy from time and resource consuming operations required to compute error. With ratings as the labels, unless the distribution of ratings is skewed and the data set is such that learning time is excessive, normalization may not be necessary. If it is, it would likely be because improving the label distribution in advance (requiring floating point input to the error function and removing skew) would reduce learning time.
  
  The other two approaches introduce unnecessary complexities mentioned in context above. A consequence of removing complexities without adding impediments to convergence is more efficiency during learning and during execution after learning.
  
  
  ---
  
  ### Answer by username_3 on 2019-08-14. Score: 0
  
  In the case of one output neuron, you don't have to use sigmoid. As username_1 Aldridge suggested, it would cause a tendency to output 0 or 1. What I normally do is that I set the layer before the output layer to sigmoid of tanh so it won't output ridiculously off numbers, and set the output layer to linear. There would be cases that it outputs something like 1.5, but over time that disappears.
  
  Hope it helps :)
  
  > **Comments:**
  > **username_0**: I have one hidden layer consisting of sigmoid-ed neurons, and one sigmoid-ed output neuron. This structure is really for 'regression' problems, but based on responses so far, would it be correct to say that it can be 'adapted' for my classification problem by removing the sigmoid on the output neuron so that the result becomes unbounded, and then classify per: rating 0 if <0.5. rating 1 if >0.5 and <1.5. rating 2 if >1.5 and <2.5. rating 3 if >2.5 and <3.5. rating 4 if >3.5. What are the expected disadvantages of doing it this way - eg. less accuracy for the same number of epochs?  
  
  ---
  
  