Neural Representation of Basic Gates(AND,OR,NOT) (Perceptron Algorithm)
Before we get into the gates topics, we need to understand the concept of Perceptron Algorithm.
1.A Perceptron is a unit which is used the built the ANN systems
2.A Perceptron takes a vector of real valued inputs, calculates the linear combination of these inputs ,then outputs 1 if the value is above the threshold value otherwise it will give 0
3.More precisely the inputs are in the form of Xi(x1,x2,…….,xn) and the output will be that Oi(o1,o2,…..,on)
4.where here each wi is the real constant or the weights that determines the contribution of xi to the perceptron output.
Here in this image x1,x2,……,xn are being the inputs that will be taken into function where weights and the inputs will be get multiplied and it will be taken into the activation function and the output from the activation function will be classified according to the thresh hold function.
How we train the perceptron to get perfect output?
One way to learn acceptable weight vector is to begin with random weights then apply iteratively to the each of the training example and modifies the perceptron weights if it misclassifies the output. The weights are being modified at each step according to the perceptron rule such that
n →learning rate, t →target output, o →original output, xi → inputs of the data
The Algorithm is given below
Perceptron_training_rule (X, n)
initialize w (wi = an initial (small) random value)
repeat
for each training instance (x, tx) = X
compute the real output ox = Activation(Summation(w.x))
if (tx != ox)
for each wi
wi = wi + Awi
Awi = 9 (tx — ox)xi
end for
end if
end for
until all the training instances in X are correctly classified
return w
AND GATE
From our knowledge of logic gates, we know that an AND logic table is given by the diagram below
We will try to understand this through the Mathematical knowledge lets consider the w1=1.2,w2=0.6,learning rate=0.5 and Threshold=1
1)When x1=0, x2=0
Output= w1*x1+w2*x2+w0 à 1.2*0+0.6*0=0
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
2)When x1=0, x2=1
Output= w1*x1+w2*x2+w0 à 1.2*0+0.6*1=0.6
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
3)When x1=1, x2=0
Output= w1*x1+w2*x2+w0 à 1.2*1+0.6*1=1.2
Whose threshold it is equal to one so its one.
But The actual output and the output of the functions are being not the same so there is a need of changing the weights.
Lets look into it how I am going to change the values inside of it.
W1=W1+n(t-o)xi=1.2+0.5*(0–1)*1=0.7
W2=W2+n(t-o)xi=0.6+0.5*(0–1)*1=0.6
So the new weights will be w1=0.7 and w2=0.6
1)When x1=0, x2=0
Output= w1*x1+w2*x2+w0 à 0.7*0+0.6*0=0
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
2)When x1=0, x2=1
Output= w1*x1+w2*x2+w0 à 0.7*0+0.6*1=0.6
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
3)When x1=1, x2=0
Output= w1*x1+w2*x2+w0 à 0.7*1+0.6*0=0.7
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
3)When x1=1, x2=1
Output= w1*x1+w2*x2+w0 à 0.7*1+0.6*1=1.3
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are being same so there is no need to change the values of weights
It satisfies all the conditions so it will be the correct weights for the system
OR GATE
From our knowledge of logic gates, we know that an OR logic table is given by the diagram below
From the diagram, the OR gate is 0 only if both inputs are 0.
We will try to understand this through the Mathematical knowledge lets consider the w1=0.6,w2=0.6,learning rate=0.5 and Threshold=1
1)When x1=0, x2=0
Output= w1*x1+w2*x2+w0 à 0.6*0+0.6*0=0
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
2)When x1=0, x2=1
Output= w1*x1+w2*x2+w0 à 0.6*0+0.6*1=0.6
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are not being same so we need change the values of the weights.
Lets look into it how I am going to change the values inside of it.
W1=W1+n(t-o)xi=0.6+0.5*(1–0)*0=0.6
W2=W2+n(t-o)xi=0.6+0.5*(1–0)*1=1.1
So the new weights will be w1=0.6 and w2=1.1
1)When x1=0, x2=0
Output= w1*x1+w2*x2+w0 à 0.6*0+1.1*0=0
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
2)When x1=0, x2=1
Output= w1*x1+w2*x2+w0 à 0.6*0+1.1*1=1.1
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are being same so there is no need to change the values of weights
3)When x1=1, x2=0
Output= w1*x1+w2*x2+w0 à 0.6*1+1.1*0=0.6
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are not being same so we need to change the values of the weights.
Lets look into it how I am going to change the values inside of it.
W1=W1+n(t-o)xi=0.6+0.5*(1–0)*1=1.1
W2=W2+n(t-o)xi=0.6+0.5*(1–0)*0=1.1
So the new weights will be w1=1.1 and w2=1.1
1)When x1=0, x2=0
Output= w1*x1+w2*x2+w0 à 1.1*0+1.1*0=0
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
2)When x1=0, x2=1
Output= w1*x1+w2*x2+w0 à 1.1*0+1.1*1=1.1
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are being same so there is no need to change the values of weights
3)When x1=1, x2=0
Output= w1*x1+w2*x2+w0 à 1.1*1+1.1*0=1.1
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are being same so there is no need to change the values of weights
4)When x1=1, x2=1
Output= w1*x1+w2*x2+w0 à 1.1*1+1.1*1=2.2
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are being same so there is no need to change the values of weights
It satisfies all the conditions so it will be the correct weights for the system
NOT GATE
From the diagram, the output of a NOT gate is the inverse of a single input.
We will try to understand this through the Mathematical knowledge lets consider the w1=0.6,learning rate=0.5 and Threshold=1
1)When x1=0
Output= w1*x1+w0 à 0.6*0=0
Whose threshold it is not equal to one so its zero.
The actual output and the output of the functions are being same so there is no need to change the values of weights
2) When x1=1
Output= w1*x1+w0 à 0.6*1=0.6
Whose threshold it is not equal to one so its one.
The actual output and the output of the functions are being same so there is no need to change the values of weights
It satisfies all the conditions so it will be the correct weights for the system