liveBook · Manning

XOR example

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

The XOR problem is a binary classification task whose desired output is the exclusive-or of two input values.

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

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Implements dataset setup, genome evaluation, fitness scoring, configuration, evolution, and output inspection.
Examples
Uses the four input pairs (0,0), (0,1), (1,0), and (1,1), then compares evolved outputs with expected labels.
What you can do after
Build it from scratch using NEAT-Python, evolve a candidate network, and inspect its predictions on all XOR inputs.
How it connects
Connects XOR with binary classification, feed-forward networks, genomes, fitness functions, mean squared error, and evolutionary optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.