This repository contains implementations of basic logic gates (AND, OR, NOT, XOR) using artificial neural networks (ANNs) with TensorFlow/Keras. Each script trains a neural network to approximate the behavior of its respective logic gate.
Each Python script defines, trains, and evaluates a neural network to mimic a specific logic gate:
and.py
β Simulates an AND gate.or.py
β Simulates an OR gate.not.py
β Simulates a NOT gate.xor.py
β Simulates an XOR gate.
The models use a simple feedforward neural network architecture with fully connected layers.
Ensure you have the following dependencies installed before running the scripts:
pip install numpy tensorflow keras
- Each model consists of one or more dense (fully connected) layers.
- Activation functions used:
ReLU
,Tanh
, andSigmoid
. - Optimizer:
Adam
. - Loss function:
binary_crossentropy
(for classification tasks).
Run the desired logic gate script to train and evaluate the neural network:
python and.py
python or.py
python not.py
python xor.py
After training, the model evaluates its accuracy and prints predictions based on the input dataset.
binary_accuracy: 100.00%
[[0.]
[0.]
[0.]
[1.]]