This repository was archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobabilityplot.py
More file actions
74 lines (57 loc) · 1.69 KB
/
probabilityplot.py
File metadata and controls
74 lines (57 loc) · 1.69 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import matplotlib.pyplot as plt
import numpy as np
def pfunction(N: int, i: int, r: float) -> float:
"""
calculates the probability of fixation according to equation (5) and (9)
:param int N: population size
:param int i: number of initial individuals A
:param float r: fitness of A
:return: probability of fixation
"""
if r == 1:
return i/N
if (1-1/r**N) == 0:
p = 0.0
else:
p = (1-1/r**i)/(1-1/r**N)
return p
# Plot i = 1
plt.style.use("seaborn-talk")
plt.subplots(figsize=[10, 10])
X = np.arange(1, 100, 0.1)
Y = {}
# different fitness values
for r in [0.5, 0.9, 1, 1.1, 2]:
Y[r] = [pfunction(N, 1, r) for N in X]
plt.plot(X, Y[r], label=f"i = 1; r = {r}")
plt.legend(frameon=False)
plt.plot()
plt.ylabel('fixation probability', labelpad=15)
plt.xlabel('population size (N)', labelpad=15)
plt.show()
# Plot i = N//2
plt.subplots(figsize=[10, 10])
X = np.arange(1, 100, 0.1)
Y = {}
# different fitness values
for r in [0.5, 0.9, 1, 1.1, 2]:
Y[r] = [pfunction(N, N // 2, r) for N in X]
plt.plot(X, Y[r], label=f"i = \u230AN/2\u230B; r = {r}")
plt.legend(frameon=False, loc='upper right', bbox_to_anchor=(1, 0.9))
plt.plot()
plt.ylabel('fixation probability', labelpad=15)
plt.xlabel('population size (N)', labelpad=15)
plt.show()
# Plot i = N-1
plt.subplots(figsize=[10, 10])
X = np.arange(1, 100, 0.1)
Y = {}
# different fitness values
for r in [0.5, 0.9, 1, 1.1, 2]:
Y[r] = [pfunction(N, N - 1, r) for N in X]
plt.plot(X, Y[r], label=f"i = N-1; r = {r}")
plt.legend(frameon=False)
plt.plot()
plt.ylabel('fixation probability', labelpad=15)
plt.xlabel('population size (N)', labelpad=15)
plt.show()