-
Notifications
You must be signed in to change notification settings - Fork 0
/
LIA.py
45 lines (31 loc) · 1.14 KB
/
LIA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from sys import argv
from sys import exit
def main():
if len(argv) != 3:
exit("Please use proper command line arugments.")
generations = int(argv[1])
# The amount of organisms in the last generation
organisms = 2 ** generations
# The amount of organisms that can have genotype Aa Bb
success = organisms - int(argv[2]) + 1
# The probability that will be outputted
total = 0
""" Calculates the probability of success
(the amount of possible Aa Bb organisms greater
than argv[2] using the binomial distribution equation."""
for i in range(organisms - success + 1, success + 1, 1):
total += binomial_distribution(organisms, i)
print(total)
# Calculates the factorial of ubound.
def factorial(ubound):
fact = 1
for i in range(1, ubound + 1, 1):
fact *= i
return fact
# The binomial distribution formula.
def binomial_distribution(n, X):
numerator = factorial(n) * (0.25 ** X) * 0.75 ** (n - X)
denominator = factorial(n - X) * factorial(X)
return numerator / denominator
if __name__ == "__main__":
main()