a numpy implementation of a simple neural network solving the xor problem with documented code
this small neural net is implemented without using any deep learning frameworks like pytorch or tensorflow to classify the 4 xor samples. xor refers to an exclusive-or boolean expression where this OR that is true but this and that is not. If we take true as 1 and false as 0, then we can generate samples and labels. the xor problem is non-linearly separable (which becomes more clear if you plot the xor samples shown below), requiring a hidden layer and non-linear activation functions to solve
- built using only numpy for computations and matplotlib for visualization
- custom implementation of:
- feed-forward logic
- backpropagation algorithm
- sigmoid activation function
- loss calculation
- total trainable parameters: 9
- modular design for clear separation of components
training progression:
initial predictions:
final predictions:
requirements:
- numpy
- matplotlib
usage:
open model.py and run
note: due to random weight initialization, you might need to run the model multiple times to avoid local minima.
the model classifies the following xor truth table:
(0,0) -> 0
(1,0) -> 1
(0,1) -> 1
(1,1) -> 0