I've been watching "neural network Design_hagan"
Then you want to implement an XOR network yourself.
Because the single layer neural network can not divide the different or the judgment to two kinds.
According to a^b= (a&~b) | (~A&B)
And I tried it. Or and with both can be solved with sensory neurons, that is, one.
Then with and or by the implementation:
Hardlim (n) =a, n>=0 when a=1;n<0 a=0;
Obviously requires three neurons.
The expression of the neuron is as follows:
int fun (int w[],int x[],int b)
{
return w[0]*x[0]+w[1]*x[1]+b;
}
int Main ()
{
int w1[2]={1,1},w2[2]={1,1},w3[2]={1,1};
int x[2];
while (scanf ("%d%d", &x[0],&x[1])!=eof)
{
int x2[2];
X[0]=!X[0];
X2[0] =hardlim (Fun (w1,x,-2));
X[0]=!X[0];
X[1]=!X[1];
X2[1] = Hardlim (Fun (w2,x,-2));
X[1]=!X[1];
printf ("%d XOR%d =%d\n", x[0],x[1], Hardlim (Fun (w3,x2,-1)) );
return 0;
}
Note that the x1,x2 input needs to be reversed.
Verified correctly.