All problems
Mutation Apply Seeded
Problem
Apply Gaussian mutation to an individual with a fixed seed.
After random.seed(seed), for each gene draw random.random(): if it is below rate, add random.gauss(0.0, sigma) to the gene, otherwise keep it. Return the mutated list.
Hint
Decide the mutation first; only mutated genes consume a Gaussian draw.
Test cases
case 1
in: [[1,2,3],0.5,0.1,0]
expected: [1,2,2.993299348427094]
case 2
in: [[0,0],1,0.2,7]
expected: [0.1693037251631145,0.2356605569278974]
case 3
in: [[-1,1],0,1,3]
expected: [-1,1]
Starter codePython
def mutation_apply(individual, rate, sigma, seed):
# Your code here
pass3 test cases · run your code against them in the editor