OR Gate using Perceptron Network
Perceptron networks come under single-layer feed-forward networks and are also called simple perceptrons. The perceptron network consists of three units, namely, sensory unit (input unit), associator unit (hidden unit), response unit (output unit). The sensory units are connected to associator units with fixed weights having values 1, 0 or -1, which are assigned at random.
The problem is to implement or gate using a perceptron network using c++ code.
#include<iostream> using namespace std; int main() { //Array for Binary Input int arr[4][2] = { {0,0}, {0,1}, {1,0}, {1,1} }; //Target array for Binary Input int t[4] = {0,1,1,1}; // Considering learning rate=1 int alp = 1; // yi = input // yo = output int w1 = 0, w2 = 0, b = 0, count = 0, i, yi, yo; int dw1,dw2,db; while(1) { cout<<"x1"<<" "<<"x2"<<" "<<"b"<<" "<<"yi"<<" "<< "yo"<<" "<<"t"<<" "<<"dw1"<<" "<<"dw2"<<" "<<"db"<< " "<<"w1"<<" "<<"w2"<<" "<<"b"<<endl; for(i = 0; i < 4; i++) { // Calaulating Input yi = arr[i][0] * w1 + arr[i][1] * w2 + b; if(yi >= 0) { yo = 1; } else { yo = 0; } if(t[i] == yo) { count++; dw1 = 0; dw2 = 0; db = 0; } // Calaulating Change in Weight else { dw1 = alp*(t[i] - yo) * arr[i][0]; dw2 = alp*(t[i] - yo) * arr[i][1]; db = alp*(t[i] - yo); } w1 = w1 + dw1; w2 = w2 + dw2; b = b + db; cout<<arr[i][0]<<" "<<arr[i][1]<<" "<<1<<" "<<yi<<" "<<yo <<" "<<t[i]<<" "<<dw1<<" "<<dw2<<" "<<db<<" "<<w1<<" "<<w2 <<" "<<b<<endl; } cout<<endl; if(count == 4) { return 0; } else { count = 0; } } } |
Output :
x1 x2 b yi yo t dw1 dw2 db w1 w2 b 0 0 1 0 1 0 0 0 -1 0 0 -1 0 1 1 -1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 0 x1 x2 b yi yo t dw1 dw2 db w1 w2 b 0 0 1 0 1 0 0 0 -1 0 1 -1 0 1 1 0 1 1 0 0 0 0 1 -1 1 0 1 -1 0 1 1 0 1 1 1 0 1 1 1 2 1 1 0 0 0 1 1 0 x1 x2 b yi yo t dw1 dw2 db w1 w2 b 0 0 1 0 1 0 0 0 -1 1 1 -1 0 1 1 0 1 1 0 0 0 1 1 -1 1 0 1 0 1 1 0 0 0 1 1 -1 1 1 1 1 1 1 0 0 0 1 1 -1 x1 x2 b yi yo t dw1 dw2 db w1 w2 b 0 0 1 -1 0 0 0 0 0 1 1 -1 0 1 1 0 1 1 0 0 0 1 1 -1 1 0 1 0 1 1 0 0 0 1 1 -1 1 1 1 1 1 1 0 0 0 1 1 -1
Recommended Posts:
- Implementing ANDNOT Gate using Adaline Network
- Introduction to ANN | Set 4 (Network Architectures)
- Generative Adversarial Network (GAN)
- Importance of Convolutional Neural Network | ML
- Introduction to Artificial Neural Network | Set 2
- Introduction to Recurrent Neural Network
- Building a Generative Adversarial Network using Keras
- Applying Convolutional Neural Network on mnist dataset
- Text Generation using Recurrent Long Short Term Memory Network
- How Should a Machine Learning Beginner Get Started on Kaggle?
- Synchronous Chatting Application using C++ boost::asio
- C/C++ For loop with Examples
- 8 Best Topics for Research and Thesis in Artificial Intelligence
- How to input a comma separated string in C++?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



