forked from justinbois/bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauria_delbruck.py
51 lines (37 loc) · 1.24 KB
/
lauria_delbruck.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
46
47
48
49
50
51
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
rc={'lines.linewidth': 2, 'axes.labelsize': 18, 'axes.titlesize': 18}
sns.set(rc=rc)
# Specify parameters
n_gen = 16
# Chance of having beneficial mutation.
r = 1e-5
# Total number of cells
n_cells = 2**(n_gen - 1)
# Adaptive immunity: binomial distribution
ai_samples = np.random.binomial(n_cells, r, size=100000)
# Report mean and std
print('AI mean:', np.mean(ai_samples))
print('AI std:', np.std(ai_samples))
print('AI Fano:', np.var(ai_samples) / np.mean(ai_samples))
# Function to draw out of random mutation hypothesis
def draw_random_mutation(n_gen, r):
"""Draw sample under random mutation hypothesis."""
# Initialize
n_mut = 0
for g in range(n_gen):
n_mut = 2*n_mut + np.random.binomial(2**g - 2 * n_mut, r)
return n_mut
def sample_random_mutation(n_gen, r, size=1):
# Initialize
samples = np.empty(size)
# Draw the samples
for i in range(size):
samples[i] = draw_random_mutation(n_gen,r)
return samples
rm_samples = sample_random_mutation(n_gen, r, 100000)
# Report mean and std
print('RM mean:', np.mean(rm_samples))
print('RM std:', np.mean(rm_samples))
print('RM Fano:', np.var(rm_samples) / np.mean(rm_samples))