The XOR problem is a compact binary-classification task: two input values map to one when exactly one input is active, and zero otherwise. It provides a practical test for evolving a NEAT neural network. section 10.1
A NEAT-Python implementation follows this workflow:
- Represent the four input pairs and their expected outputs. section 10.1
- Create a feed-forward network for each genome and activate it on every input. section 10.1
- Start fitness at four and subtract each output's squared error from it. section 10.1
- Configure the population, genome activation, fitness threshold, and evolutionary components before running evolution. section 10.1
Listing 10.2 EDL_10_1_NEAT_XOR.ipynb: The data setup
xor_inputs = [(0.0, 0.0), (0.0, 1.0), (1.0, 0.0), (1.0, 1.0)] #1 xor_outputs = [ (0.0,), (1.0,), (1.0,), (0.0,)] #2
Inspect the complete XOR dataset: four input pairs with outputs encoding exclusive-or. section 10.1
Evaluating the evolved network
After evolution, activate the winning network on each input pair and print the expected and produced outputs to inspect its solution. section 10.1
