All problems
Roulette Selection Probabilities
Problem
Compute roulette-wheel selection probabilities.
Return each fitness divided by the total fitness. If the total is 0, return equal probabilities; an empty list returns [].
Hint
Normalize the fitness values so they sum to one.
Test cases
case 1
in: [[1,2,1]]
expected: [0.25,0.5,0.25]
case 2
in: [[0,0]]
expected: [0.5,0.5]
case 3
in: [[4]]
expected: [1]
case 4
in: [[]]
expected: []
Starter codePython
def roulette_selection_probs(fitness):
# Your code here
pass4 test cases · run your code against them in the editor