-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_param_swipe.m
155 lines (134 loc) · 5.49 KB
/
main_param_swipe.m
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
%%% main K-swipe %%%
clear all
close all
clc
%% Definition of general variables
load('DefColors.mat')
load('Colores.mat')
mode = 0;
m_max = 100; % number of random seeds to create the fi trends;
K_ind = 10:5:500; % number of total samples considered throughout
q = [.025 .16 0.5 0.84 .975];
labels_resorted = {'variant 2','variant 3','variant 4','variant 5'};
for expno = 2:4
for mode = [1 0]
filename = strcat('Fig_2_Exp_',num2str(expno),'_mode_',num2str(mode));
load(strcat('Ground_truth_Experiment_', num2str(expno),'.mat'))
%% Empty matrices
Tdet_com = cell(4,1);
Tdet_POE = cell(4,1);
for i = 1:k-1
Tdet_com{i} = NaN(m_max,length(K_ind));
Tdet_POE{i} = NaN(m_max,length(K_ind));
end
%% accumulating and discretising weekly cases
Nobs_com_weekly = nan(k,floor((tf-ti)/7) + 1);
Nobs_POE_weekly = nan(k,floor((tf-ti)/7) + 1);
T = floor(ti/7):floor(tf/7);
for i = 2:floor((tf-ti)/7) + 1
for j = 1:k
idx = t/7 >= T(i-1) & t/7 <= T(i);
Nobs_com_weekly(j,i) = floor(trapz(t(idx),Nobs_com(j,idx)));
Nobs_POE_weekly(j,i) = floor(trapz(t(idx),Nobs_POE(j,idx)));
end
end
T(1) = [];
Nobs_com_weekly(:,1) = [];
Nobs_POE_weekly(:,1) = [];
%% C(A)RD parameters
for ind = 1:length(K_ind)
P.K = K_ind(ind);
P.kcom_i = floor(0.6*P.K);
P.kcom_max = floor(0.95*P.K);
P.kcom_min = P.kcom_i;
P.k = k;
P.s_alpha = 5;
P.s_zeta = 1;
P.Lambda12 = .25;
P.Theta12 = 10;
P.Deltakcom_max = 10;
P.f_alpha = 1.25;
%% sorting and sampling in weekly cases
kcom = P.kcom_i*ones(size(T));
kcom = repmat(kcom,m_max,1);
kPOE = P.K - kcom;
V_sampli_com = cell(k,1);
V_sampli_POE = cell(k,1);
if mode == 0
for variant = 1:k
V_aux_com = nan(m_max,floor((tf-ti)/7));
V_aux_POE = nan(m_max,floor((tf-ti)/7));
for m = 1:m_max
rng(m)
for i = 1:floor((tf-ti)/7)
% community
fi_hat_com = GS(Nobs_com_weekly(:,i),kcom(m,i),m);
V_aux_com(m,i) = fi_hat_com(variant);
% POE
fi_hat_POE = GS(Nobs_POE_weekly(:,i),kPOE(m,i),m);
V_aux_POE(m,i) = fi_hat_POE(variant);
end
end
V_sampli_com{variant} = V_aux_com;
V_sampli_POE{variant} = V_aux_POE;
end
for variant = 1:k-1
Tdet_var_com = nan(m_max,1);
Tdet_var_POE = nan(m_max,1);
for m = 1:m_max
try
[~,B] = find(V_sampli_com{variant+1}(m,:)>0,1,'first');
Tdet_var_com(m) = T(B);
catch err
end
try
[~,B] = find(V_sampli_POE{variant+1}(m,:)>0,1,'first');
Tdet_var_POE(m) = T(B);
catch err
end
end
Tdet_com{variant}(:,ind) = Tdet_var_com;
Tdet_POE{variant}(:,ind) = Tdet_var_POE;
end
else
for i = 1:k
V_sampli_com{i} = nan(m_max,floor((tf-ti)/7));
V_sampli_POE{i} = nan(m_max,floor((tf-ti)/7));
end
for i = 1:floor((tf-ti)/7)
for m = 1:m_max
if i>2
[kcom,kPOE] = adapt_kcom(T,i,V_sampli_com,V_sampli_POE,m,kcom,kPOE,Nobs_POE_weekly(:,i),P);
end
fi_hat_com = GS(Nobs_com_weekly(:,i),kcom(m,i),m);
% POE
fi_hat_POE = GS(Nobs_POE_weekly(:,i),kPOE(m,i),m);
for variant = 1:k
V_sampli_POE{variant}(m,i) = fi_hat_POE(variant);
V_sampli_com{variant}(m,i) = fi_hat_com(variant);
end
end
end
for variant = 1:k-1
Tdet_var_com = nan(m_max,1);
Tdet_var_POE = nan(m_max,1);
for m = 1:m_max
try
[~,B] = find(V_sampli_com{variant+1}(m,:)>0,1,'first');
Tdet_var_com(m) = T(B);
catch
end
[~,B] = find(V_sampli_POE{variant+1}(m,:)>0,1,'first');
try
Tdet_var_POE(m) = T(B);
catch
end
end
Tdet_com{variant}(:,ind) = Tdet_var_com;
Tdet_POE{variant}(:,ind) = Tdet_var_POE;
end
end
end
% save(strcat(filename,'.mat'))
end
end