-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp1x2x-mobility-patch_cont-patch_infect.py
180 lines (132 loc) · 4.68 KB
/
exp1x2x-mobility-patch_cont-patch_infect.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#%%
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.colors as colors
mpl.rc('text', usetex=True)
mpl.rc('font', family='serif')
mpl.rc('font', size=10)
#%%
# file with data from the experiment
# Note: header=6 is for NetLogo data
exp1_desc = 'exp1-mobility-patch_cont-patch_infect'
exp2_desc = 'exp2x-mobility-patch_cont-patch_infect'
exp_desc = 'v3w_exp1x2x'
data1 = pd.read_csv(exp1_desc + '.csv', header=6)
data2 = pd.read_csv(exp2_desc + '.csv', header=6)
#%%
# select variables for the analysis
# this depends on the experiment
# variables
# 1st is different for each plot
# 2nd and 3rd vars provide axes for plots
# 4th variable is visualized
# variant 1
# v = ['mobility-prob', 'patch-infection-weight', 'patch-contamination-prob','mean-infected']
# variant 2
v = ['patch-infection-prob', 'mobility-prob', 'patch-contamination-prob','mean-infected']
vl = [r'$w_3$', r'$\mu$', r'$p^{\mathrm{patch}}$']
# selection for plotting
# selected values of the 1st variable
# mrs = [0.1, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.75, 0.9, 1]
#var0s = [0.1, 0.2, 0.3, 0.4, 0.5, 0.55, 0.6, 0.7, 0.75]
var0s = [0.15, 0.30, 0.45, 0.75]
# all vaues for 2nd dna 3rd variable
var1s = data1[v[1]].unique()
var2s = data1[v[2]].unique()
df1 = pd.DataFrame(columns=v)
df2 = pd.DataFrame(columns=v)
#%%
# calculate mean for the presented variable
for v0 in var0s:
for v1 in var1s:
for v2 in var2s:
df1.loc[len(df1.index)] = [
v0,
v1,
v2,
data1[ (data1[v[0]] == v0) & (data1[v[1]] == v1) & (data1[v[2]] == v2) ] ['%infected'].mean()
]
df2.loc[len(df2.index)] = [
v0,
v1,
v2,
data2[ (data2[v[0]] == v0) & (data2[v[1]] == v1) & (data2[v[2]] == v2) ] ['%infected'].mean()
]
#%%
fig = mpl.figure.Figure(figsize=(6,3.5))
levels = [1,10,20,30,40,50,60,70]
for i,v0 in enumerate(var0s):
axs = fig.add_subplot(241+i);
plot_data = df1[df1[v[0]] == v0][[v[1], v[2], v[3]]].to_numpy()
axs.contour(
plot_data.T[0].reshape(len(var1s), len(var1s)),
plot_data.T[1].reshape(len(var2s), len(var2s)),
plot_data.T[2].reshape(21,21),
levels = levels,
colors = 'k',linestyles='dotted'
)
im=axs.contourf(
plot_data.T[0].reshape(len(var1s), len(var1s)),
plot_data.T[1].reshape(len(var2s), len(var2s)),
plot_data.T[2].reshape(21,21),
levels = levels,
cmap = 'Oranges',
norm=colors.Normalize(vmin=0, vmax=70),
)
axs.grid(True,linestyle=':', linewidth=0.5, c='k')
axs.set_title("abcd"[i]+") "+vl[0]+'='+str(v0))
axs.set_xticks(np.arange(0,1.01,0.2))
axs.set_xticks([0,0.25,0.5,0.75,1.0])
axs.set_xticklabels([])
axs.set_yticks([0,0.25,0.5,0.75,1.0])
axs.set_yticklabels([0,0.25,0.5,0.75,1.0])
if i not in [0]:
axs.set_yticklabels([])
if i == 0:
axs.set_ylabel(vl[2])
# lower panels (from experiment exp2x)
for i,v0 in enumerate(var0s):
axs = fig.add_subplot(245+i);
plot_data = df2[df2[v[0]] == v0][[v[1], v[2], v[3]]].to_numpy()
axs.contour(
plot_data.T[0].reshape(len(var1s), len(var1s)),
plot_data.T[1].reshape(len(var2s), len(var2s)),
plot_data.T[2].reshape(21,21),
levels = levels,
colors = 'k',linestyles='dotted'
)
im=axs.contourf(
plot_data.T[0].reshape(len(var1s), len(var1s)),
plot_data.T[1].reshape(len(var2s), len(var2s)),
plot_data.T[2].reshape(21,21),
levels = levels,
cmap = 'Oranges',
norm=colors.Normalize(vmin=0, vmax=70),
)
axs.grid(True,linestyle=':', linewidth=0.5, c='k')
axs.set_title("efgh"[i]+") "+vl[0]+'='+str(v0))
axs.set_xticks([0,0.25,0.5,0.75,1.0])
axs.set_xticklabels([0,0.25,0.5,0.75,1.0])
axs.set_yticks([0,0.25,0.5,0.75,1.0])
axs.set_yticklabels([0,0.25,0.5,0.75,1.0])
#if i not in [0,3,6]:
# axs.set_yticklabels([])
axs.set_xlabel(vl[1])
if i not in [0]:
axs.set_yticklabels([])
if i == 0:
axs.set_ylabel(vl[2])
# fig.colorbar(p)
# fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.125, 1.035, 0.8, 0.025])
cbar = fig.colorbar(im, cax=cbar_ax, orientation="horizontal")
cbar.set_ticklabels([str(l)+"\%" for l in levels])
fig.tight_layout()
display(fig)
#%%
fName = "plot_" + exp_desc + ".pdf"
print("INFO] Saving " + fName)
fig.savefig(fName, format="pdf", bbox_inches='tight')