Solved – How does the XOR neural net work?

neural networksweights

I'm new to neural nets, and I'm having a hard time wrapping my head around the concept of weights and whatnot.

I've been staring at a diagram of the XOR neural network for an hour, and I genuinely have no idea what I'm looking at. I just can't figure out how it works.

Can someone explain how the four possible cases work here? I've tried walking through a simple example like (1,1), but I don't even have a basic grasp of how this is supposed to work. I've watch a bunch of tutorials on this, but I'm just totally lost on this simple example. Clearly misunderstanding something, would be awesome to get a simple explanation of how XOR works.

Best Answer

No wonder you're struggling, because there's no standard way of visualizing NNs. Everyone does what they can to confuse the beginners.

  • you have two inputs, set both to 1: $x_1=x_2=1$
  • first neuron of the first layer gets these inputs with the weights: $z[1,1] = x_1 + x_2 = 1$
  • "OR": $a[1,1] = ( z[1,1]>0.5 ) = 1$
  • second neuron of the first layer gets these inputs with the weights: $z[1,2] = -x_1 -x_2 = -2$
  • "NOT AND": $a[1,1] = ( z[1,2]>-1.5 ) = 0$
  • neuron of the second layer gets the outputs of first layer with the weights: $z[2,1] = a[1,1] + a[1,2] = 1$
  • "AND": $a[2,1] = ( z[2,1]>1.5 ) = 0$ Do the same for inputs (1,0),(0,0) and (0,1). Voila your XOR!

The values on connectors are weights, and the values in circles are thresholds for perceptrons to fire.

Python code:

for x1 in (0,1):
  for x2 in (0,1):
    a11=(x1+x2)>0.5
    a12=(-x1-x2)>-1.5
    a21 = (a11+a12)>1.5
    print(x1,' xor ',x2,' = ',a21)

Did another ML MOOC session just started?

Related Question