Write a program to implement and train an artificial neural network that can simulate an XOR operator.
The network should contain two input nodes that only relay the input signals, two hidden layer nodes and one output node.
You can initialize the weights of the connections with random numbers between 0 and 1, or assign 0.5 to all the connections (including the bias weights for the two hidden layer nodes and one output node).
The training instances are:
| X1 | X2 | Y |
| 1 (True) | 1 (True) | 0 (False) |
| 1 (True) | 0 (False) | 1 (True) |
| 0 (False) | 1 (True) | 1 (True) |
| 0 (False) | 0 (False) | 0 (False) |
Use logistic function
g(x) = 1 / (1 + e^(-x))as the firing/activation function for each node. The logistic function's derivative is
g'(x) = (1 - g(x))g(x)
Set the learning rate α = 0.001, and you can adjust it if the learning process takes too long.
During the learning process, show the weights every few steps so that you can view how the weights are learned from the training instances.