# Programming a Modelling Neurons (XOR Operation) in PHP

- tresnamaulanafahrudin
- Sep, 13, 2016
- Artificial Intelligent, Intelligent Computing and Application
- No Comments

**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 *y *value is 1 or 0 with threshold=2.

**XOR Calculation**

- Assume x1=1,x2=1 (XOR table).
- w1=2, w2=-1, w3=-1, w4=2, w5=2, and w6=2.
- threshold=2.
- Find y1,y2, and y.
**First (Input layer),**output1 =(x1*w1)+(x2*w2) = (1*2)+(1*(-1))= 2 + (-1)= 2-1=1.- if output1 more or equal than threshold (threshold=2), then y1=1; else then y1=0.
- Because output1=1, then output1 lower than threshold. Therefore y1 value = 0.
**Second(Input layer),**output2 =(x3*w3)+(x4*w4) = (1*(-1))+(1*2)= (-1)+2=1.- if output2 more or equal than threshold (threshold=2), then y2=1; else then y2=0.
- Because output2=1, then output2 lower than threshold. Therefore y2 value = 0.
**Third (Hidden layer),**y1=0, y2=0**.****Fourth(Output layer),**output3 =(y1*w5)+(y2*w6) = (0*2)+(0*2)= 0+0=0.- if output3 more or equal than threshold (threshold=2), then y=1; else then y = 0.
- Because output3=0, then output3 lower than threshold. Therefore final y output value = 0.
- 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.

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

Thank you.