Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.

Repository files navigation

Simple NEAT Addition Model

This project demonstrates how to use the NEAT (NeuroEvolution of Augmenting Topologies) algorithm to train a simple neural network to perform addition. It is designed to be an educational entry point for new developers looking to understand how NEAT works, how it can be implemented using neat-python, and how to visualize its evolving networks.

Project Structure

The project is broken down into three main Python files to keep the code modular and easy to read:

  • generator.py: Responsible for generating the training and testing data. It creates random pairs of numbers and normalizes them (a best practice in machine learning) to help the network learn faster.
  • visualize.py: Contains utility functions for rendering the neural network topology (using Graphviz) and plotting the fitness evolution over generations (using Matplotlib). Visualizing these structures is key to understanding how NEAT adds complexity to networks over time.
  • main.py: The core script. It sets up the NEAT configuration, defines the fitness function (how well a genome adds two numbers), runs the evolutionary simulation, and then tests and visualizes the best performing neural network.
  • config-feedforward: The configuration file that dictates the rules for the evolutionary algorithm (mutation rates, population size, activation functions, etc.).

Prerequisites

This project is built using Python and relies on a few key dependencies:

  • neat-python (The core NEAT implementation)
  • graphviz (For drawing network topologies)
  • matplotlib (For plotting fitness graphs)

You will also need the Graphviz executable installed on your operating system for visualize.py to generate the .svg topology maps.

  • Ubuntu/Debian: sudo apt install graphviz
  • MacOS: brew install graphviz
  • Windows: Download from the Graphviz website

Running the Project

To run the training simulation:

uv run main.py

What happens when you run it?

  1. The script initializes a population of 1000 random neural networks.
  2. For each generation, it asks the networks to add pairs of numbers.
  3. Networks that get closer to the real answer are rewarded with a higher "fitness" score.
  4. The best performing networks are selected to "breed" and mutate to create the next generation.
  5. Once a network reaches the target fitness (0.99999), or the maximum number of generations (500) is reached, training stops.
  6. The script prints the results of the best network and generates network_topology.gv.svg and fitness_history.svg in the output/ directory.

Visualizing NEAT

After a successful run, open the generated .svg files in the output/ directory!

  • output/fitness_history.svg: Shows how the population improved over time.
  • output/network_topology.gv.svg: Shows the exact structure of the "winning" neural network, including the hidden nodes and connections it created to solve the addition problem.
  • output/data_distribution.svg: Shows the uniform distribution of the generated training data (Input A vs Input B, colored by their target sum).
  • output/predictions_over_time.svg: Shows a grid of scatter plots comparing the network's predictions against the expected perfect answers (the blue line) at different generational checkpoints. Watch the red dots converge to perfection!
  • output/speciation.svg: A stackplot showing how the population is divided into different species over time, visualizing how NEAT protects new structural innovations.
  • output/complexity.svg: Tracks the number of nodes and connections of the best performing genome over time, demonstrating NEAT's "augmenting topologies" philosophy (starting simple and adding complexity only as needed).

Happy evolving!

About

A simple Neural Network using NEAT

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages