Advertisement

Fitness function in genetic algorithms

Started by February 12, 2006 10:21 AM
0 comments, last by Kylotan 18 years, 9 months ago
I was told the function that calculated the fitness for a genome in a genetic algorithm was the hardest thing to do in GA. Seems like the general public is right. Im having trouble to come up with one. Up until now (when other things in the GA class wasnt working) I had the fitness function simply do this to every genome:

gene->offset = 0;  // reset

for(int i = 0; i < DataSet.size() ++i)
   gene->offset = abs( gene->calculate( DataSet.Input, DataSet.TargetOutput ) );

gene->offset /= DataSet.size();   // make it the average offset

That is, go through the datasets, add up how far off we were on each, then divide by the number of datasets weve gone through. To make it the average. Now this seemed to work in theory. But the genomes in this example is supposed to learn the logical operation AND. Which means we have four datasets, and three of has a target output of zero. So a gene earns on outputting zero all the time, offset is low 3 of 4 times and high only one time. So all the genes I evolve simply outputs zero all the time and call it a go. I edited the code so it runs an equal amount of times on datasets that has a target output of one as those that has a target output of zero. I think it works for now, with the logical operations. But the genes outputs floats, I just do binary AND for now to have something simple to do. Any ideas how to do this? To have the genes not to earn on just outputting the most occuring target output?
Even though always outputting a zero is good 3 times out of 4, there should still eventually be solutions that produce the right answer all the time (ie. 4 times out of 4), so this shouldn't be a problem. Perhaps your algorithm is not creating enough diversity.

This topic is closed to new replies.

Advertisement