ADALINE (Adaptive Linear Neuron or later Adaptive Linear Element) is an early single-layer artificial neural network and the name of the physical device that implemented this network. The problem here is to implement AND-NOT using Adaline network. Here we perform 5 epochs of training and calculate total mean error in each case, the total mean error decreases after each epochs and later becomes nearly constant.
The Truth Table for AND-NOT Gate is as follows:
x1 x2 t
1 1 -1
1 -1 1
-1 1 -1
-1 -1 -1
#include <iostream>
using namespace std;
int main()
{
int arr[4][2] = { { 1, 1 },
{ 1, -1 },
{ -1, 1 },
{ -1, -1 }
};
int t[4] = { -1, 1, -1, -1 }, i, j;
float yi, dif, dw1, dw2, db, w1 = 0.2, w2 = 0.2, b = 0.2, err[4];
for (i = 0; i < 5; i++)
{
float avg = 0;
cout << "EPOCH " << i + 1 << " Errors" << endl
<< endl;
for (j = 0; j < 4; j++)
{
yi = arr[j][0] * w1 + arr[j][1] * w2 + 1 * b;
dif = t[j] - yi;
w1 += 0.2 * dif * arr[j][0];
w2 += 0.2 * dif * arr[j][1];
b += 0.2 * dif * 1;
err[j] = dif * dif;
cout << err[j] << " " ;
avg += err[j];
}
cout << endl
<< "Total Mean Error :" << avg << endl
<< endl
<< endl;
}
return 0;
}
|
Output:
EPOCH 1 Errors
2.56 1.2544 0.430336 1.47088
Total Mean Error :5.71562
EPOCH 2 Errors
0.951327 0.569168 0.106353 0.803357
Total Mean Error :2.43021
EPOCH 3 Errors
0.617033 0.494715 0.369035 0.604961
Total Mean Error :2.08574
EPOCH 4 Errors
0.535726 0.496723 0.470452 0.541166
Total Mean Error :2.04407
EPOCH 5 Errors
0.515577 0.503857 0.499932 0.520188
Total Mean Error :2.03955
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
18 Jun, 2019
Like Article
Save Article