All problems
Moran Fixation Probability
Problem
In the Moran process with population size N, initial mutants and relative fitness r, the probability that the mutants take over is:
(1 - (1 / r)^initial) / (1 - (1 / r)^N)
for r different from 1, and initial / N for r = 1. Return 0.0 for invalid arguments.
Hint
Use the ratio 1 / r so beneficial mutants have r > 1.
Test cases
case 1
in: [10,2,1]
expected: 0.5004887585532747
case 2
in: [10,1,1]
expected: 0.1
case 3
in: [10,2,5]
expected: 0.9696969696969697
case 4
in: [10,1,10]
expected: 1
case 5
in: [10,0.5,1]
expected: 0.0009775171065493646
Starter codePython
def moran_fixation_probability(population, fitness, initial):
# Your code here
pass5 test cases · run your code against them in the editor