Reputation: 751
On a Genetic Algorithm, would it be correct to make the Fitness Function something other than a mathematical ecuation? Could it have a recursive function and a loop inside of it?
The thing is I'm evaluating if I can work with Genetic Algorithms for my thesis and this fitness function I'm thinking about could be a little complicated. But maybe not, I'll just have to make sure the program can handle such function and it doesn't create a bottleneck, right?.
Basic idea:
FitnessFunction(){
fitness = RecursiveFunction();
}
RecursiveFunction(){
do{
//Do something
}while(other_condition);
if(another_condition){
return RecursiveFunction();
}
return fitness;
}
Upvotes: 1
Views: 615
Reputation: 499
It will be a bottleneck, but that is expected. The evaluation function usually takes the great majority of the execution time, since the genetic operators (crossover, mutation) are very simple operations in comparison. I've seen GA where the evaluation function is to simulate a house structure receiving an earthquake, so you should be fine.
Is worth, however, that you isolate, measure the time and try to optimize the function as much as possible. Consider that it will run for hundreds or thousands of individuals, for many generations, and you will repeat the whole process a lot, tweaking parameters and your GA implementation.
Upvotes: 2
Reputation: 1612
As long as your function returns a fitness value (it seems like it does), I don't see a problem with this. In fact, GA and evolutionary computation in general are perfectly suitable for complex fitness functions which are in many cases non-differentiable and therefore hard to use with other training methods like gradient descent.
Upvotes: 2