title: Understanding Neural Network Backpropagation
body: <p>Update: a better formulation of the issue.</p>
  
  <p>I'm trying to understand the backpropagation algorithm with an XOR neural network as an example.  For this case there are 2 input neurons + 1 bias, 2 neurons in the hidden layer + 1 bias, and 1 output neuron.</p>
  
  <pre><code> A   B  A XOR B
   1    1   -1
   1   -1    1
  -1    1    1
  -1   -1   -1
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/h1BHt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/h1BHt.png" alt="A sample XOR neural network"></a><br>
  <sub>(source: <a href="https://upload.wikimedia.org/wikipedia/en/7/7b/XOR_perceptron_net.png" rel="noreferrer">wikimedia.org</a>)</sub>  </p>
  
  <p>I'm using <a href="http://pandamatak.com/people/anand/771/html/node37.html" rel="noreferrer">stochastic backpropagation</a>.</p>
  
  <p>After reading a bit more I have found out that the error of the output unit is propagated to the hidden layers... initially this was confusing, because when you get to the input layer of the neural network, then each neuron gets an error adjustment from both of the neurons in the hidden layer.  In particular, the way the error is distributed is difficult to grasp at first.</p>
  
  <p><strong>Step 1</strong> calculate the output for each instance of input.<br>
  <strong>Step 2</strong> calculate the error between the output neuron(s) (in our case there is only one) and the target value(s):<br>
  <a href="https://i.stack.imgur.com/YJTHr.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/YJTHr.gif" alt="Step 2"></a><br>
  <strong>Step 3</strong> we use the error from Step 2 to calculate the error for each hidden unit h:<br>
  <a href="https://i.stack.imgur.com/bFVPz.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/bFVPz.gif" alt="Step 3"></a></p>
  
  <p>The 'weight kh' is the weight between the hidden unit h and the output unit k, well this is confusing because the input unit does not have a direct weight associated with the output unit.  After staring at the formula for a few hours I started to think about what the summation means, and I'm starting to come to the conclusion that each input neuron's weight that connects to the hidden layer neurons is multiplied by the output error and summed up.  This is a logical conclusion, but the formula seems a little confusing since it clearly says the 'weight kh' (between the output layer k and hidden layer h).</p>
  
  <p>Am I understanding everything correctly here? Can anybody confirm this?  </p>
  
  <p>What's O(h) of the input layer? My understanding is that each input node has two outputs: one that goes into the the first node of the hidden layer and one that goes into the second node hidden layer. Which of the two outputs should be plugged into the <code>O(h)*(1 - O(h))</code> part of the formula?<br>
  <a href="https://i.stack.imgur.com/bFVPz.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/bFVPz.gif" alt="Step 3"></a></p>