I'm doing a genetic algorithm where each inidividual generates 3 new offsprings. The new individuals are evaluated using the fitness function, which may return negative and positive values. What is the correct approach to choose between the offsprings using the roulette wheel selection if I want to minimize?
Some possible values of the fitness function are: fitness_offspring_1 = -98.74; fitness_offspring_2 = -10.1; fitness_offspring_3 = 100.31
I'm working on Python but I only need the idea so I can implement it by myself.
Roulette wheel selection is simply assigning probability values proportional to an individuals fitness. And then randomly selecting from that distribution. Fit individuals get a better chance at being selected, while less-fit individuals get lower chances.
You can easily adapt this to your code by using the offspring list instead of the individuals.
Lets start with as simple pseudo-codeish implementation in python, you can modify it to your needs:
Now, the code above (by the nature of roulette wheel) assumes all fitness values are positive. So in your case we need to normalize it. You can simply sum all values by the absolute value of smallest offspring. But that would make its probability 0 so you could simply add a bias to all to give it a slight chance as well.
Lets see how it works with simple values, say [1, 5, 14]
I'm sure there are much better pseudo-codes or implementations in python you can search for. Just wanted to give you an idea.