- #1
timthereaper
- 479
- 33
Hey all, I'm trying to learn how to write genetic algorithms. I've constructed a kind of crude experiment just to see how the algorithm solves:
An array of integers is my "genome". The "ideal genome" is an array of the first ten numbers of the Fibonacci sequence (1,1,2,3,5,8,13,21,34,55). I'm starting with a random population of 10 "organisms" with random genomes (each of the ten numbers are random integers from 0-100) and hopefully the algorithm will yield something close to the ideal.
Now, I don't entirely understand how to choose an appropriate "fitness" function for the selection part of the algorithm. I've read online about some ideas but can't seem to implement them in my experiment. I see several potential problems with bad fitness functions:
1. The population grows and grows because I will choose the best candidate in that generation to reproduce n times and the population size will grow from 10 in the first generation to like 15 in the second, 20 in the third, etc.
2. Choosing only the best 5 candidates and stopping all potential for a more complete solution. This would happen if one gene of all the top 5 candidates was equally far away (or something like that).
I'm sure there are other problems, but like I said, I'm learning. I would appreciate any help with this. I'm a decent programmer in both C++ and Java, so programming really isn't an issue for me.
An array of integers is my "genome". The "ideal genome" is an array of the first ten numbers of the Fibonacci sequence (1,1,2,3,5,8,13,21,34,55). I'm starting with a random population of 10 "organisms" with random genomes (each of the ten numbers are random integers from 0-100) and hopefully the algorithm will yield something close to the ideal.
Now, I don't entirely understand how to choose an appropriate "fitness" function for the selection part of the algorithm. I've read online about some ideas but can't seem to implement them in my experiment. I see several potential problems with bad fitness functions:
1. The population grows and grows because I will choose the best candidate in that generation to reproduce n times and the population size will grow from 10 in the first generation to like 15 in the second, 20 in the third, etc.
2. Choosing only the best 5 candidates and stopping all potential for a more complete solution. This would happen if one gene of all the top 5 candidates was equally far away (or something like that).
I'm sure there are other problems, but like I said, I'm learning. I would appreciate any help with this. I'm a decent programmer in both C++ and Java, so programming really isn't an issue for me.