Hebbian and C++

This is a discussion on Hebbian and C++ within the C++ Programming forums, part of the General Programming Boards category; Hi , i have a project in neural network (hebbian learning rule) i just want to apply it (AND gate) ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Hebbian and C++

    Hi , i have a project in neural network (hebbian learning rule) i just want to apply it (AND gate) , I wrote a simple program but i get it to work just like it should can some one help me tracing the program .
    Input pattern 1 (0,0) corresponding output -1
    Input pattern 2 (0,1) corresponding output -1
    Input pattern 3 (1,0) corresponding output -1
    Input pattern 4 (1,1) corresponding output 1

    here is the program :-
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    int x[4][3],w[3],y[4][1],i,j,p;
    for(i=0;i<=2;++i)
    w[i]=0;
    for(p=1;p<=4;++p)
    x[p][0]=1;
    for(p=1;p<=4;++p) {
    cout<<"Enter the input Pattern number "<<p<<" : \n";
    for(i=1;i<=2;++i)
    cin>>x[p][i];
    cout<<"Enter the corresponding output \n";
    for(j=1;j<=1;++j)
    cin>>y[p][j];
    for(i=0;i<=2;++i)
    for(j=1;j<=1;++j){
    w[i]+=x[p][i]*y[p][j];
    cout<<endl;
    
    }
    }
    cout<<"The final weights = [ "<<w[0]<<" "<<w[1]<<" "<<w[2]<<" ]"<<endl;
    clrscr();
    return 0;
    }
    the weird thing is after enter the input patterns i get weight =[1 2 2] which supposed to be w=[1 1 1] .Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,414
    Quote Originally Posted by haneya
    can some one help me tracing the program
    Use your debugger to help you trace the program.

    Quote Originally Posted by haneya
    here is the program
    Good to see that you posted your code in code bbcode tags, but please indent the code properly. You provided the expected output and actual output, but you might also want to tell us the exact input that you tested.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    2
    Use your debugger to help you trace the program.
    First thanks for replying , After building and compiling the code i got no error at all I dont know if that what you mean by using your debugger

    Quote:
    Good to see that you posted your code in code bbcode tags, but please indent the code properly. You provided the expected output and actual output, but you might also want to tell us the exact input that you tested.
    OK I will next time , Input I want to test
    Code:
     { 0 0 0 , 0 1 0 , 1 0 0 , 1 1 1 }
    after each number use enter , Is that clear enough ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,414
    Quote Originally Posted by haneya
    After building and compiling the code i got no error at all I dont know if that what you mean by using your debugger
    You did get an error, according to you, except that the error was some kind of logic error, not a compile error. A debugger can help you debug such errors. Such a tool is available with Visual Studio, and you can configure a debugger named gdb for use on some other IDEs like Code::Blocks.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21