| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
|
This is a very simple exercise that will allow you to see how genetic algorithms work. Try and evolve pi! This exercise obviously assumes you have read the basic Generation5 GA essays.
OutlineWhile this sounds rather complicated it is very easy. Create a population of floating point numbers and run it through a fitness function. Then average all the good values together to create the next generation. Keep on going until you're satified with the results.
GuidelinesThis project is very open because there are many ways to do it. For example, the fitness function could return the error between a fixed value of pi and the value passed to it:
#define gPI 3.14159f
float error_pi(float value) {
return abs(value - gPI / gPI);
}
This would only evolve a value as good as the constant defined. You could use data that relates a radius of a circle with the circumference. Again, that would only evolve pi as good as defined in the data. Try different methods. For a high-precision evaluation, I used Texas Instruments' Derive 5 to generate pi to 100 decimal places:3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067 Again, you can keep evolving until you reach a certain precision, x-number of iterations, or you can keep it going infinitely until you otherwise specify. Tip: At least for the first few generations, print out the best results so that you can see how the GA generates "fit" chromosomes. This project really strips down what a genetic algorithm does into the simplest form - but this simplicity comes with the added bonus that it makes it very accessible to people with little experience with GAs. You can see how the GA works, therefore it is definitely in your interest to try this project out if you are novice. Here is a printout from my solution: Current best: 3.18944 Current best: 3.15513 Current best: 3.13034 Current best: 3.14163 Current best: 3.14214 Current best: 3.1416 Current best: 3.14157 Current best: 3.1416 Current best: 3.14159 Current best: 3.14159 Best value: 3.14159.
Solutions
Submitted: 12/03/2001 Article content copyright © James Matthews, 2001.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -