This task implements a simple neural network using Python and NumPy to solve the XOR problem.
The main goal is to demonstrate how the backpropagation algorithm helps a neural network learn non-linear patterns that cannot be solved using a single-layer perceptron.
We use the XOR truth table as input.
- XOR is not linearly separable
- A single-layer perceptron cannot solve it
- A hidden layer is required
- Input Layer: 2 neurons
- Hidden Layer: 2 neurons
- Output Layer: 1 neuron
- Activation Function: Sigmoid
Inputs are passed through the network:
- Input to Hidden Layer
- Hidden Layer to Output Layer
Each neuron performs:
- Weighted sum
- Sigmoid activation
The loss is equal to half times the average of the squared difference between the actual output and the predicted output.
error = targets - final_output
loss = np.mean(error ** 2)