Realization of heterogeneous or xor__ neural network with simple multilayer neural network

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.