liveBook · Manning

NEAT-Python

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

NEAT-Python is a Python library that implements neuroevolution of augmenting topologies and provides configurable evolutionary neural-network components.

NEAT-Python is a configuration-driven Python framework for evolving neural networks with NeuroEvolution of Augmenting Topologies (NEAT). It packages population evolution, genome evaluation, network construction, reporting, and topology changes so that weights, connections, nodes, and activation choices can adapt over generations without backpropagation-based weight updates. section 10.0 section 10.6

A typical workflow defines a fitness evaluator, writes a configuration file, creates a `neat.Config` and `neat.Population`, and runs evolution. The evaluator receives genomes, builds a feed-forward network from each genome, activates it on inputs, and assigns fitness from its error. The winning genome can then be converted into a network and tested on the same inputs. section 10.1

Listing 10.3 EDL_10_1_NEAT_XOR.ipynb: Creating the evaluation function
def eval_genomes(genomes, config):
  for genome_id, genome in genomes:                 #1
    genome.fitness = 4.0                            #2
    net = neat.nn.FeedForwardNetwork.create
     (genome, config)                             #3
    for xi, xo in zip(xor_inputs, xor_outputs):     #4
      output = net.activate(xi)            
      genome.fitness -= (output[0] - xo[0]) ** 2    #5

This evaluator shows the core integration point: construct each genome's network, activate it for every XOR input, and subtract squared error from fitness. section 10.1

Configuration controls both the evolutionary run and the kinds of networks it can produce:

  • Set population size, fitness criterion, fitness threshold, and extinction behavior in the `[NEAT]` section. section 10.1
  • Specify input, output, and initial hidden-node counts; choose initial connectivity; and set probabilities for adding or deleting nodes and connections. section 10.3
  • Choose activation functions and their mutation rate, such as sigmoid, identity, and relu. section 10.3
  • Tune weight initialization, mutation, replacement, and mutation power when gradual weight adjustment is more useful than frequent topology changes. section 10.5.1
  • Control speciation with compatibility distance and stagnation settings so unproductive species can be checked for extinction. section 10.5.1

Evolving XOR

For first-order XOR, define the four binary input pairs and expected outputs, begin each genome with maximum fitness, and subtract mean squared error after each activation. A configuration with a population of 150 and a fitness threshold of 3.99 is used to evolve a winner, whose outputs are printed beside the expected values. section 10.1

Inspecting classification behavior

For moons and circles classification, evolve a network against generated two-dimensional data, display its predictions as a contour plot, and draw the resulting network. The setup uses input, output, and middle-node counts rather than assuming that evolved nodes will form conventional layers. section 10.3 section 10.5.1

NEAT-Python offers substantial control, but that flexibility makes complex problems harder to evolve because configuration choices interact. For circles, reducing node and connection changes while using small weight mutations focuses evolution on gradual weight adaptation; compatibility thresholds and stagnation limits further shape how species persist or are removed. section 10.5.1 section 10.6

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

How deep it goes
Walks through installation, fitness evaluation, configuration, population execution, visualization, and speciation tuning without formal derivations.
Examples
Uses XOR, moons, and circles datasets, feed-forward networks, contour predictions, evolved-network drawings, and a custom reporter.
What it assumes
Assumes familiarity with Python notebooks, neural-network evaluation, fitness functions, and mean squared error.
What you can do after
Apply it via NEAT-Python to configure populations, score genomes, evolve feed-forward networks, and inspect classification predictions.
How it connects
Connects neuroevolution with neural-network architecture, hyperparameter optimization, fitness evaluation, speciation, and backpropagation.

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.