-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7) plot resulting distributions.py
165 lines (145 loc) · 6.28 KB
/
7) plot resulting distributions.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import matplotlib.pyplot as plt
import os
import numpy as np
import helpers
import pandas as pd
class Boltzmann:
def __init__(self, beta, index):
self.beta = beta
self.index = index
def log_density(self, x):
return self.beta * x[self.index]
if __name__ == "__main__":
mean_growth_rates = {}
maxent_growth_rates = {}
std_growth_rates = {}
all_mu = pd.read_csv('data/extracted_growth_rates_with_media.csv', index_col=0)
# select area method (we could have used others, but area works well)"
method = "area"
all_mu = all_mu[all_mu['method'].str.contains("area")]
pca_gluc_mu = all_mu[all_mu['medium'] == "PCA-Gluc"].reset_index()
gluc_mu = all_mu[all_mu['medium'] == "Glucose-MOPS"].reset_index()
citr_mu = all_mu[all_mu['medium'] == "Citrat-MOPS"].reset_index()
mean_growth_rates['iEZ481_PCA_Gluc'] = float(pca_gluc_mu['mu'].mean())
std_growth_rates['iEZ481_PCA_Gluc'] = float(pca_gluc_mu['mu'].std())
mean_growth_rates['iEZ481_Glucose-MOPS'] = float(gluc_mu['mu'].mean())
std_growth_rates['iEZ481_Glucose-MOPS'] = float(gluc_mu['mu'].std())
mean_growth_rates['iEZ481_Citrat-MOPS'] = float(citr_mu['mu'].mean())
std_growth_rates['iEZ481_Citrat-MOPS'] = float(citr_mu['mu'].std())
models = [
'iEZ481_PCA_Gluc',
'iEZ481_Glucose-MOPS',
'iEZ481_Citrat-MOPS',
]
media = {
'iEZ481_PCA_Gluc': 'PCA',
'iEZ481_Glucose-MOPS': 'GLC',
'iEZ481_Citrat-MOPS': 'CIT',
}
n_cols = 3
n_rows = 1
plt.figure(figsize=(n_cols * 3.5, n_rows * 3.5))
plt.subplot(n_rows, n_cols, 1)
n_bins = 20
for i, model in enumerate(models):
poltope = helpers.load_polytope('data', model)
biomass_index = 300
beta = float(pd.read_csv(f'data/{model}_beta.csv')['best_beta'][0][1:-1])
u_samples = np.load(file=os.path.join('data', f'{model}_uniform_samples_thinned.npz'))['samples'][:, :, :]
b_samples = np.load(file=os.path.join('data', f'{model}_boltzmann_samples_thinned.npz'))['samples'][:, :, :]
print(f'beta is {beta}')
print('u samples shape', u_samples.shape)
print('b samples shape', b_samples.shape)
maxent_growth_rates[model] = np.mean(b_samples[:, :, biomass_index])
beta_string = "%.3f" % beta
lambda_bar_string = "%.3f" % mean_growth_rates[model]
mean_string = "%.3f" % maxent_growth_rates[model]
mean_uniform = "%.3f" % np.mean(u_samples[:, :, biomass_index])
plt.subplot(n_rows, n_cols, i + 1)
plt.title(f'Substrate {media[model]}')
_, bins, _ = plt.hist(
b_samples[:, :, biomass_index].flatten(),
bins=n_bins,
alpha=0.25,
density=True,
# label=fr"Boltzmann ($\beta$={beta_string})" if i == 2 else None,
label=fr"Maxent (Boltzmann)" if i == 2 else None,
)
_ = plt.hist(
u_samples[:, :, biomass_index].flatten(),
bins=bins,
alpha=0.25,
density=True,
label="uniform" if i == 2 else None,
)
_ = plt.hist(
b_samples[:, :, biomass_index].flatten(),
histtype='step',
bins=bins,
density=True,
linewidth=2,
color='C0'
)
_ = plt.hist(
u_samples[:, :, biomass_index].flatten(),
histtype='step',
bins=bins,
density=True,
linewidth=2,
color='C1'
)
print(pca_gluc_mu['mu'])
print(pca_gluc_mu['mu'].values)
if model == 'iEZ481_PCA_Gluc':
_, bins, _ = plt.hist(pca_gluc_mu['mu'].values, density=True, bins=n_bins, color='C2', alpha=0.25)
plt.hist(pca_gluc_mu['mu'].values, histtype='step', density=True, color='C2', bins=bins, alpha=1)
elif model == 'iEZ481_Glucose-MOPS':
_, bins, _ = plt.hist(gluc_mu['mu'].values, density=True, bins=n_bins, color='C2', alpha=0.25)
plt.hist(gluc_mu['mu'].values, histtype='step', density=True, color='C2', bins=bins, alpha=1)
elif model == 'iEZ481_Citrat-MOPS':
_, bins, _ = plt.hist(citr_mu['mu'].values, density=True, bins=n_bins, color='C2', alpha=0.25, label='measured')
plt.hist(citr_mu['mu'].values, histtype='step', density=True, color='C2', bins=bins, alpha=1)
else:
raise RuntimeError("Error")
f_length = lambda f: f()[1] - f()[0]
f_offset = lambda f: f()[0]
x_scale = 0.5
y_scale = 0.94
x = x_scale * f_length(plt.xlim) + f_offset(plt.xlim)
y = y_scale * f_length(plt.ylim) + f_offset(plt.ylim)
plt.text(x, y, rf'$\beta=${beta_string}', horizontalalignment='left', c='k')
plt.text(x, y * 0.9, r'$\bar\lambda_{maxent}$'f'={mean_string}/h', horizontalalignment='left', c='C0')
plt.text(x, y * 0.8, r'$\bar\lambda_{uniform}$'f'={mean_uniform}/h', horizontalalignment='left', c='C1')
plt.text(x, y * .7, r'$\bar\lambda_{meas}$'f'={lambda_bar_string}/h', horizontalalignment='left', c='C2')
styles = [(0, (5, 1)), (0, (5, 10)), (0, (5, 15))]
plt.axvline(
x=maxent_growth_rates[model],
# label=r"Boltzmann mean $\bar\lambda_{maxent}$",
color='C0',
linewidth=3,
linestyle=styles[0]
)
plt.axvline(
x=mean_growth_rates[model],
# label=r"measured growth rate $\bar\lambda_{exp}$",
linewidth=2,
color='C2',
linestyle=styles[1]
)
plt.axvline(
float(mean_uniform),
# label=r"measured growth rate $\bar\lambda_{exp}$",
linewidth=2,
color='C1',
linestyle=styles[2]
)
# if i == 2:
# plt.legend(loc='upper right', bbox_to_anchor=(1.55, 1))
plt.xlabel(r'growth rate $\lambda$ [1/h]')
plt.ylabel(r'density')
# leg = plt.figlegend(loc='upper right', bbox_to_anchor=(1.175, 1))
plt.tight_layout()
plt.savefig('maxentResults+meas.pdf', bbox_inches='tight')# , bbox_extra_artists=(leg,))
plt.savefig('maxentResults+meas.svg', bbox_inches='tight')# , bbox_extra_artists=(leg,))
plt.savefig('maxentResults+meas.png', bbox_inches='tight')# , bbox_extra_artists=(leg,))
plt.show()