-
Notifications
You must be signed in to change notification settings - Fork 1
Fitness
Fitness Functions are the center of genetic algorithms, they are where the pressure to evolve is defined. In this implementation the fitness function is not the focus of the project, but rather making a GA to which many different fitness functions can easily be implemented. Therefore this module (included in the Individual class) acts as an interface between the main GA code and fitness function logic.
To add a fitness function called my_fit_func, define it within the Fitness module and select it to be run in the config hash
config{:fitness_function => "my_fit_func"}
If (as intended) the fitness module is included in the Individual class then from within a fitness function definition the genetic material can be accessed with:
self.genome.sequence
Where the fitness function module is to be used is not set in stone and could well be included in the Genome class.
Creating an effective fitness function is some where between science and black art. Evolution will generally find the simplest solution which works (how BDD) but this is often not what is expected or wanted.
Effective fitness functions should not be over complex, but should not allow for a undesired solution to prevail. I once wrote a GA to evolve simple neural nets for simulated robots to move them though a world and avoid objects. I produced a race of robots which went in small circles. Why? Because they were being selected for minimizing the number of collisions and covering the greatest possible distance, and very sensibly evolutions’ answer was to go in small circles. This was cured by replacing total distance traveled with mean delta distance between time steps.
Imposing many constraints in a fitness function in an effort to guide the evolution toward a desired goal is often counter productive. Complex problems have complex and varied solutions and imposing too many constraints may over limit the scope of the search. In natural evolution the fitness function is the purest and simplest; continue existing. This is applied to all life forms with complexity being introduced by interaction with the environment. However as there is not a separate model of environment the fitness function has to full fill that role.