Programming a Modelling Neurons (XOR Operation) in PHP

Programming a Modelling Neurons (XOR Operation) in PHP

neuralaa

Neural Network, Figure taken from www.extremetech.com

XOR Operation

In the previous discussion, we have known and implemented about basic concept neural network, AND operation, and OR operation. The input layer in XOR operation will process one  x input value which has two weighting input values, it is different with AND,OR operation which has one weighting input for one x input value. Furthemore, XOR has hidden layer which has two nodes (called z1,z2 or y1,y2) to get values from input layer. Each nodes in hidden layer has threshold=2 for determining y1,y2 value is 1 or 0. The output layer will process y1,y2 values with weighting value w5,w6. The final output determine  value is 1 or 0 with threshold=2.

xor_

XOR operation

XOR Calculation

  1. Assume x1=1,x2=1 (XOR table).
  2. w1=2, w2=-1, w3=-1, w4=2, w5=2, and w6=2.
  3. threshold=2.
  4. Find y1,y2, and y.
  5. First (Input layer), output1 =(x1*w1)+(x2*w2) = (1*2)+(1*(-1))= 2 + (-1)= 2-1=1.
  6. if output1 more or equal than threshold (threshold=2), then y1=1; else then y1=0.
  7. Because  output1=1, then output1 lower than threshold. Therefore y1 value = 0.
  8. Second(Input layer), output2 =(x3*w3)+(x4*w4) = (1*(-1))+(1*2)= (-1)+2=1.
  9. if output2 more or equal than threshold (threshold=2), then y2=1; else then y2=0.
  10. Because  output2=1, then output2 lower than threshold. Therefore y2 value = 0.
  11. Third (Hidden layer), y1=0, y2=0.
  12. Fourth(Output layer),output3 =(y1*w5)+(y2*w6) = (0*2)+(0*2)= 0+0=0.
  13. if output3 more or equal than threshold (threshold=2), then y=1; else then y = 0.
  14. Because  output3=0, then output3 lower than threshold. Therefore final y output value = 0.
  15. For combination input x1=1,x2=0; x1=0,x2=1;and x1=0,x2=0, can follow step 1-14.

You can follow the source code below, please re-type for understanding this discussion.

code1

Part 1 of code

code2

Part 2 of code

code3

Part 3 of code

OK, i hope you can understand this discussion about XOR operation.

Thank you.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *