Implementation of Artificial Neural Network for XOR Logic Gate with 2-bit Binary Input
Artificial Neural Network (ANN) is a computational model based on the biological neural networks of animal brains. ANN is modeled with three types of layers: an input layer, hidden layers (one or more), and an output layer. Each layer comprises nodes (like biological neurons) are called Artificial Neurons. All nodes are connected with weighted edges (like synapses in biological brains) between two layers. Initially, with the forward propagation function, the output is predicted. Then through backpropagation, the weight and bias to the nodes are updated to minimizing the error in prediction to attain the convergence of cost function in determining the final output.
XOR logical function truth table for 2-bit binary variables, i.e, the input vector and the corresponding output –
0 0 0 0 1 1 1 0 1 1 1 0
Attention reader! Don’t stop learning now. Get hold of all the important Machine Learning Concepts with the Machine Learning Foundation Course at a student-friendly price and become industry ready.
Step1: Import the required Python libraries
Step2: Define Activation Function : Sigmoid Function
Step3: Initialize neural network parameters (weights, bias)
and define model hyperparameters (number of iterations, learning rate)
Step4: Forward Propagation
Step5: Backward Propagation
Step6: Update weight and bias parameters
Step7: Train the learning model
Step8: Plot Loss value vs Epoch
Step9: Test the model performance
[[ 1. 0. 0. 1.]]
Here, the model predicted output for each of the test inputs are exactly matched with the XOR logic gate conventional output () according to the truth table and the cost function is also continuously converging.
Hence, it signifies that the Artificial Neural Network for the XOR logic gate is correctly implemented.