-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sardegna.m
188 lines (161 loc) · 4.62 KB
/
Sardegna.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
%%
clc
clear all
close all
% GET DATA FROM SCRIPT
% add folders to path
addpath('./data/');
addpath('./models/');
addpath('./results/');
addpath('./results/overview');
addpath('./results/january');
addpath('./results/october');
addpath('./models/SIR');
addpath('./models/SEIR');
addpath('./models/SEIIR');
addpath('./models/SEIIRHD');
%retrieve the data structs
[data, dates] = getDataByRegion("Sardegna");
sizes = size(dates);
size_data = sizes(2);
N = 1611621;
t0 = find(dates=="08-Oct-2020");
tf = find(dates=="23-Nov-2020");
%% PLOT DATA
plot_data(data, dates(t0:tf), N, t0, tf, "./results/october/Sardegna/octoberPlot.png");
%% FITTING SIR MODEL
beta0 = 0.962/N;
gamma0 = 0.37;
I = cast((data.totale_positivi), 'double');
R = cast((data.dimessi_guariti), 'double');
S = N-I-R;
X_SIR = [S, I, R];
X_ad_SIR = [S, I, R]/N;
% initial conditions
I0 = I(t0);
R0 = R(t0);
S0 = N-I0-R0;
X0_ad_SIR = [S0 I0 R0]/N;
beta0 = beta0*N;
p0_SIR = [beta0, gamma0];
p_SIR = fit_SIR(X_ad_SIR, X0_ad_SIR, p0_SIR, t0, tf);
fprintf("--- SIR FITTING DONE --- \n");
fprintf("beta: %f, gamma: %f \n", p_SIR(1), p_SIR(2));
%% R0 SIR
F = p_SIR(1);
V = p_SIR(2);
G = F*inv(V);
R0 = eigs(G,1);
fprintf("R0: %f \n", R0);
%% PLOT SIR
close all
tp = [7, 14, 21];
plot_SIR(X_SIR, X0_ad_SIR, N, p_SIR, dates, t0, tf, tp, "./results/october/Sardegna/SIR_fitting.png");
%% FITTING SEIR MODEL
% [S, E, I, R]
E = 0.3*(I);
S = N-I-E-R;
X = [S, E, I, R];
X_SEIR = [S, E, I, R];
X_ad_SEIR = [S, E, I, R]/N;
% adimensional SEIR model for fitting
% We divide every variable by N
% s = S/N, e= E/N etc.
% [s, e, i, r]
% s' = -(beta*N)*(S/N)*(I/N) = -(beta*N)*s*i
% e' = (beta*N)*(S/N)*(I/N) - alpha*(E/N) = (beta*N)*s*i - alpha*e
% i' = alpha*(E/N)-gamma*(I/N) = alpha*e-gamma*i
% r' = gamma*(I/N) = gamma*i
% initial conditions
E0 = E(t0);
I0 = I(t0);
R0 = R(t0);
S0 = N-E0-I0-R0;
X0_ad_SEIR = [S0 E0 I0 R0]/N;
S0 = N;
tau = 5.1; %paper SEIR
alpha0=1/tau;
% initial beta and gamma are taken from the previous simulation results
beta0 = p_SIR(1);
gamma0 = p_SIR(2);
p0_SEIR = [beta0, alpha0, gamma0];
p_SEIR = fit_SEIR(X_ad_SEIR, X0_ad_SEIR, p0_SEIR, t0, tf);
fprintf("--- SEIR FITTING DONE --- \n");
fprintf("beta: %f, alpha: %f, gamma: %f \n", p_SEIR(1), p_SEIR(2), p_SEIR(3));
%% R0 SEIR
F = [0 p_SEIR(1); 0 0];
V = [p_SEIR(2) 0; -p_SEIR(2) p_SEIR(3)];
G = F*inv(V);
R0 = eigs(G,1);
fprintf("R0: %f\n", R0);
%% PLOT SEIR
close all
tp = [7,14, 21];
plot_SEIR(X_SEIR, X0_ad_SEIR, N, p_SEIR, dates, t0, tf, tp,"./results/october/Sardegna/SEIR_fitting.png");
%% FITTING SEIIR MODEL
S = N-E-I-R;
f0 = 0.4264;
I_a = (1-f0)*I;
I_s = f0*I;
X_SEIIR = [S, E, I_a, I_s, R];
X_ad_SEIIR = [S, E, I_a, I_s, R]/N;
% initial conditions
E0 = E(t0);
I_a0 = I_a(t0);
I_s0 = I_s(t0);
R0 = R(t0);
X0_ad_SEIIR = [S0 E0 I_a0 I_s0 R0]/N;
alpha0 = p_SEIR(2);
gamma0 = p_SEIR(3);
beta_a0 = 0.05;
beta_s0 = 0.67; % changed
p0_SEIIR = [f0, alpha0, gamma0, beta_a0, beta_s0 ];
p_SEIIR = fit_SEIIR(X_ad_SEIIR, X0_ad_SEIIR, p0_SEIIR, t0, tf);
fprintf("--- SEIIR FITTING DONE --- \n");
fprintf("f0: %f, alpha: %f, gamma: %f, beta_a: %f, beta_s: %f\n"...
, p_SEIIR(1), p_SEIIR(2), p_SEIIR(3), p_SEIIR(4), p_SEIIR(5));
%% PLOT SEIIR
close all
tp = [7,14, 21];
plot_SEIIR(X_SEIIR, X0_ad_SEIIR, N, p_SEIIR, dates, t0, tf, tp, "./results/october/Sardegna/SEIIR_fitting.png");
%% FITTING SEIIRHD MODEL
S = N-E-I-R;
R = cast(data.dimessi_guariti, 'double');
H = cast(data.totale_ospedalizzati, 'double');
D = cast(data.deceduti, 'double');
X_SEIIRHD = [S, E, I_a, I_s, H, R, D];
X_ad_SEIIRHD = [S, E, I_a, I_s, H, R, D]/N;
% initial conditions
E0 = E(t0);
I_a0 = I_a(t0);
I_s0 = I_s(t0);
H0 = H(t0);
R0 = R(t0);
D0 = D(t0);
X0_ad_SEIIRHD = [S0 E0 I_a0 I_s0 H0 R0 D0]/N;
f0 = p_SEIIR(1);
alpha0 = p_SEIIR(2);
gamma0 = p_SEIIR(3);
beta_a0 = p_SEIIR(4);
beta_s0 = p_SEIIR(5);
nu_s0 = 0.08;
mu0 = 0.0204;
p0_SEIIRHD = [f0, alpha0, gamma0, beta_a0, beta_s0, nu_s0, mu0];
p_SEIIRHD = fit_SEIIRHD(X_ad_SEIIRHD, X0_ad_SEIIRHD, p0_SEIIRHD, t0, tf);
fprintf("--- SEIIRHD FITTING DONE --- \n");
fprintf("f0: %f, alpha: %f, gamma: %f, \n beta_a: %f, beta_s: %f \n nu_s0: %f, mu0: %f \n"...
, p_SEIIRHD(1), p_SEIIRHD(2), p_SEIIRHD(3), ...
p_SEIIRHD(4), p_SEIIRHD(5), p_SEIIRHD(6),...
p_SEIIRHD(7));
%% RO SEIIRHD
F = [0 p_SEIIRHD(4) p_SEIIRHD(5); 0 0 0; 0 0 0];
V = [p_SEIIRHD(2) 0 0; ...
((p_SEIIRHD(1)-1)* p_SEIIRHD(2)) 0 p_SEIIRHD(3);
(-(p_SEIIRHD(2)*p_SEIIRHD(1))) (p_SEIIRHD(3) + p_SEIIRHD(6) + p_SEIIRHD(7)) 0];
G = F*inv(V);
R0 = eigs(G,1);
fprintf("R0: %f\n", R0);
%% PLOT SEIIRHD
close all
tp = [7,14, 21];
plot_SEIIRHD(X_SEIIRHD, X0_ad_SEIIRHD, N, p_SEIIRHD, dates, t0, tf, tp, "./results/october/Sardegna/SEIIRHD_fitting.png");