Visualizations
261 / 500

261 · Machine learning

NEAT Species

Networks grow their own topology to balance two poles, while species rise and fall.

NeuroEvolution of Augmenting Topologies, written from scratch, on the classic double pole benchmark: a 1 m pole and a short pole hinged on one cart, simulated with Wieland's equations at 200 Hz. Every genome starts with its inputs wired straight to the force output, and mutation can split a link with a new hidden node or add a link, each change stamped with a global innovation number so genomes line up gene by gene for crossover and speciation. Similar genomes share a species and its fitness, protecting new structure while it tunes, and stagnant species die out. Generations run headlessly; on screen the champion balances live, its network is drawn as a circuit that grows, the best of each big species balances in a gallery, and a Muller plot shows every species branching from its parent. Each time the task is solved the short pole gets longer.

Try it. Drag sideways across the canvas to shove the champion's cart and see whether its network recovers (an autopilot shoves it now and then too). Press R to restart evolution from minimal networks with a new seed.

  • NEAT with innovation numbers and speciation
  • Double pole cart physics
  • Muller plot of species lineages
  • Orthogonal circuit routing

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a NEAT (NeuroEvolution of Augmenting Topologies) demo with JavaScript and the HTML canvas element, where evolving neural networks learn to balance a pole on a cart. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Simulate a cart on a 4.8 m track with a 1 m pole hinged on top (standard cart-pole equations, 50 steps per second). A controller pushes with up to 10 N. The run fails if the pole tips past 12 degrees or the cart leaves the track.
- A genome is a list of node ids plus connection genes (from, to, weight, enabled, innovation number). Start every genome minimal: the four inputs (cart position and velocity, pole angle and angular velocity) plus a bias wired straight to one output.
- Keep a global table of innovation numbers so the same new connection always gets the same number.
- Mutations: perturb weights, add a connection between two unconnected nodes (never creating a cycle), or add a node by splitting an existing connection in two.
- Crossover lines up two parents by innovation number. Speciate with the NEAT distance (excess and disjoint genes plus average weight difference) and divide each genome's fitness by its species size.
- Fitness is steps balanced, up to 1000. Evaluate a population of 150 without drawing, a slice per frame, and run the current champion live on screen.

Once that works, make it beautiful:
- Draw the champion's network with inputs on the left and the output on the right, hidden nodes placed by depth, and connections colored by sign with width by weight.
- Plot species sizes over generations as a stacked area chart.
- Let me drag the mouse to shove the cart and test the champion.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as the harder double pole version, removing the velocity inputs so it must evolve recurrent memory, or animating new nodes as they appear.
PreviousOscilloscope MusicA phosphor XY scope draws a 4D tesseract, knots and text from the stereo sound you hear. NextPhyllotaxisThe golden angle emerges from inhibition on a growing shoot tip, then builds a sunflower.

Related visualizations

  • CPPN GardenMachine learning Breed images grown by tiny neural networks by picking the ones you like.
  • Neural EcosystemEmergence Herbivores and predators with tiny neural brains evolve in a pastel petri dish.
  • Tree of LifeSimulation A living phylogeny: species branch, die out and survive mass extinctions in a ring.
  • Ghost RacersMachine learning Sixty neural-net cars evolve to race a track, then face one you draw.
  • BiomorphsAlgorithms Dawkins' Blind Watchmaker: breed recursive ink creatures by choosing a child.
  • Fitness LandscapeAlgorithms Five populations climb a rugged fitness landscape, then get stranded when it shifts.
  • Growing Neural CellsMachine learning Cells running one tiny learned rule grow a gecko from a single seed and heal its wounds.
  • Embryo StripesSimulation A fly embryo's gene network paints seven even-skipped stripes, nucleus by nucleus.
  • Symbolic RegressionMachine learning Genetic programming breeds formulas until it rediscovers the law behind the data.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs