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
Fitness function in genetic algorithms
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:
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement