-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_two_methods_y2.m
161 lines (144 loc) · 5.01 KB
/
run_two_methods_y2.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
155
156
157
158
159
160
161
% SEIR model, when only observe I
T = 30;
t1 = 25;
dy = [14; 2];
sys = @seir;
c =
n_unobs = 2;
nu = feval(sys,'nu');
[n, m] = size(nu);
n_obs = n-n_unobs;
x0 = feval(sys,'x0');
Ns = 10000;
num_trial = 10;
susceptible_naive = zeros(num_trial, Ns);
exposed_naive = zeros(num_trial, Ns);
w_naive = zeros(num_trial, Ns);
susceptible_gt = zeros(num_trial, Ns);
exposed_gt = zeros(num_trial, Ns);
w_gt = zeros(num_trial, Ns);
%%
tic;
for trial = 1:num_trial
[V_naive, w_naive(trial,:)] = get_V_w_naive(T, dy, sys, c, Ns);
susceptible_naive(trial,:) = V_naive(1,:);
exposed_naive(trial,:) = V_naive(2,:);
[V_gt, w_gt(trial,:)] = get_V_wl_y2(T, t1, sys, dy, c, Ns);
susceptible_gt(trial,:) = V_gt(1,:);
exposed_gt(trial,:) = V_gt(2,:);
end
toc;
%% Plot
xmin = 15;
xmax = 40;
x_range = xmin:xmax;
x_prob_naive = zeros(num_trial, xmax-xmin+1);
x_prob_gt = zeros(num_trial, xmax-xmin+1);
for i = 1:5
x_prob_naive(i,:) = get_hist(susceptible_naive(i,:), w_naive(i,:), x_range);
x_prob_gt(i,:) = get_hist(susceptible_gt(i,:), w_gt(i,:), x_range);
end
hold on
plot(x_range, x_prob_naive(1,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(2,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(3,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(4,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(5,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_gt(1,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(2,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(3,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(4,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(5,:), '-b', 'LineWidth', 1)
xlabel('Susceptible population at T = 30')
ylabel('Conditional probability')
hold off
saveas(gcf, 'susceptible-dy12-2.png')
%%
figure
xmin = 0;
xmax = 10;
x_range = xmin:xmax;
x_prob_naive = zeros(num_trial, xmax-xmin+1);
x_prob_gt = zeros(num_trial, xmax-xmin+1);
for i = 1:5
x_prob_naive(i,:) = get_hist(exposed_naive(i,:), w_naive(i,:), x_range);
x_prob_gt(i,:) = get_hist(exposed_gt(i,:), w_gt(i,:), x_range);
end
hold on
plot(x_range, x_prob_naive(1,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(2,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(3,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(4,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(5,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_gt(1,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(2,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(3,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(4,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(5,:), '-b', 'LineWidth', 1)
xlabel('Exposed population at T = 30')
ylabel('Conditional probability')
hold off
saveas(gcf, 'exposed-dy14-2.png')
%%
%% Plot
xmin = 15;
xmax = 40;
x_range = xmin:xmax;
x_prob_naive = zeros(num_trial, xmax-xmin+1);
x_prob_gt = zeros(num_trial, xmax-xmin+1);
for i = 1:num_trial
x_prob_naive(i,:) = get_hist(susceptible_naive(i,:), w_naive(i,:), x_range);
x_prob_gt(i,:) = get_hist(susceptible_gt(i,:), w_gt(i,:), x_range);
end
figure
hold on
errorbar(x_range, mean(x_prob_gt), 2*std(x_prob_gt)/sqrt(num_trial), '-b','LineWidth', 2)
errorbar(x_range, mean(x_prob_naive), 2*std(x_prob_naive)/sqrt(num_trial), '-r','LineWidth', 2)
%{
plot(x_range, x_prob_naive(1,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(2,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(3,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(4,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(5,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_gt(1,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(2,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(3,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(4,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(5,:), '-b', 'LineWidth', 1)
%}
xlabel('Susceptible population at T = 30')
ylabel('Conditional probability')
lgd=legend('naive', 'two stage');
lgd.Location = 'north';
hold off
saveas(gcf, 'susceptible-dy14-2-ci.png')
%%
figure
xmin = 0;
xmax = 10;
x_range = xmin:xmax;
x_prob_naive = zeros(num_trial, xmax-xmin+1);
x_prob_gt = zeros(num_trial, xmax-xmin+1);
for i = 1:num_trial
x_prob_naive(i,:) = get_hist(exposed_naive(i,:), w_naive(i,:), x_range);
x_prob_gt(i,:) = get_hist(exposed_gt(i,:), w_gt(i,:), x_range);
end
hold on
errorbar(x_range, mean(x_prob_naive), 2*std(x_prob_naive)/sqrt(num_trial), '-r','LineWidth', 2)
errorbar(x_range, mean(x_prob_gt), 2*std(x_prob_gt)/sqrt(num_trial), '-b','LineWidth', 2)
%{
plot(x_range, x_prob_naive(1,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(2,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(3,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(4,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_naive(5,:), '-r', 'LineWidth', 1)
plot(x_range, x_prob_gt(1,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(2,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(3,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(4,:), '-b', 'LineWidth', 1)
plot(x_range, x_prob_gt(5,:), '-b', 'LineWidth', 1)
%}
xlabel('Exposed population at T = 30')
ylabel('Conditional probability')
hold off
saveas(gcf, 'exposed-dy14-2-ci.png')