Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
README.md
demo.py

README.md

Super Simple Demo

This is intended as a super quick way to get off the ground and understand the basic process of how genetic algorithms work, without all the math and formality!

This code uses a very simplistic genetic algorithm to evolve numbers toward a goal number. The code is mostly comments, and explains this well. The basic code is 20 lines of Python.

Also is an explanation of some of the "knobs" you can turn to adjust how the algorithms work, and what to look for when fiddling with them.

Also inside is an explanation of how to "breed" good numbers from each generation, and a supplimental implimentation as an exercise for the reader.

Requirements

Python 2.6. Just run python demo.py

Example output

python demo.py
Starting evolution of 5 samples toward a goal of 95
Current population is [50, 50, 50, 50, 50]. Most fit is 50 with fitness of 45
Current population is [50, 47, 50, 52, 53]. Most fit is 53 with fitness of 42
Current population is [53, 49, 54, 56, 49]. Most fit is 56 with fitness of 39
Current population is [56, 56, 59, 59, 53]. Most fit is 59 with fitness of 36
Current population is [59, 62, 58, 58, 60]. Most fit is 62 with fitness of 33
Current population is [62, 62, 64, 63, 64]. Most fit is 64 with fitness of 31
Current population is [64, 60, 64, 62, 61]. Most fit is 64 with fitness of 31
Current population is [64, 64, 66, 60, 62]. Most fit is 66 with fitness of 29
Current population is [66, 63, 67, 66, 64]. Most fit is 67 with fitness of 28
Current population is [67, 68, 63, 70, 66]. Most fit is 70 with fitness of 25
Current population is [70, 70, 71, 68, 71]. Most fit is 71 with fitness of 24
Current population is [71, 72, 69, 67, 70]. Most fit is 72 with fitness of 23
Current population is [72, 72, 70, 72, 71]. Most fit is 72 with fitness of 23
Current population is [72, 71, 74, 72, 70]. Most fit is 74 with fitness of 21
Current population is [74, 72, 71, 73, 75]. Most fit is 75 with fitness of 20
Current population is [75, 71, 72, 76, 75]. Most fit is 76 with fitness of 19
Current population is [76, 74, 75, 79, 77]. Most fit is 79 with fitness of 16
Current population is [79, 78, 81, 81, 77]. Most fit is 81 with fitness of 14
Current population is [81, 81, 83, 79, 78]. Most fit is 83 with fitness of 12
Current population is [83, 85, 81, 85, 82]. Most fit is 85 with fitness of 10
Current population is [85, 84, 83, 84, 85]. Most fit is 85 with fitness of 10
Current population is [85, 87, 85, 84, 82]. Most fit is 87 with fitness of  8
Current population is [87, 89, 87, 84, 85]. Most fit is 89 with fitness of  6
Current population is [89, 88, 87, 92, 87]. Most fit is 92 with fitness of  3
Current population is [92, 88, 90, 92, 89]. Most fit is 92 with fitness of  3
Current population is [92, 94, 93, 92, 88]. Most fit is 94 with fitness of  1
Current population is [94, 92, 93, 93, 94]. Most fit is 94 with fitness of  1
Current population is [94, 94, 95, 95, 96]. Most fit is 95 with fitness of  0
Achieved goal in 27 generations