-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrate_optim_par.m
294 lines (252 loc) · 16 KB
/
calibrate_optim_par.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
function [output_prev, output_cascade, output_cascade_PWID, output_disease, output_cases,output_ost, output_nsp, output_diagnoses] = calibrate_optim(maxiter, swarmsize)
global infect prev0 progression imp1 imp2 imp3 imp4 imp5 imp6 imp7 imp8 imp9 cascade0 cascade0_PWID disease0 cases0 ost0 nsp0 diagnoses0...
data y0_init t0_init y0 t0 treat Tin infect_base progression_base ost_enrollment nsp_enrollment r_inc_up start_year followup...
num_pops num_cascade num_age num_intervention num_engagement num_region infect_factor treat_projected
data = {prev0, cascade0, cascade0_PWID, disease0, cases0, ost0, nsp0, diagnoses0}; % prevalence, cascade to calibrate to
lag = 1; % iterations between successive samples
xp = [10*infect,...
progression(1,1:4,2,1), ... %PWID first 4 steps
progression(2,1:4,2,1),... %former PWID first 4 steps
progression(3,1:4,2,1),... % Other first 4 steps
imp1, imp2, imp3, imp4, imp5, imp6, imp7, imp8, imp9, ...
ost_enrollment, nsp_enrollment,r_inc_up, start_year];
nvars = length(xp);
lb = max(0.1*xp, 0.001*ones(1,length(xp)));
lb(1) = 0.2; lb(22) = 0;
lb(25) = 0.5; lb(26) = 0; % lower bounds for height of rel_incidence function and epidemic start year
ub = 10*xp;
ub(14:21) = 4500; ub(21) = 1000; ub(22) = 0;
ub(25) = 5; ub(26) = 30; % upper bounds for height of rel_incidence function and epidemic start year
%options.UseVectorized = true;
ms = MultiStart('UseParallel', true);
options = optimoptions('particleswarm', 'Display', 'iter', 'MaxIter', maxiter,'StallIterlimit',20,'Swarmsize',swarmsize,'UseParallel',false);
[x, fval, exitflag, output] = particleswarm(@objective,nvars,lb,ub, options)
[infect, progression, imp1, imp2, imp3, imp4, imp5 ,imp6 ,imp7, imp8, imp9,...
ost_enrollment, nsp_enrollment, r_inc_up, start_year] = feval(@assign,x);
Run=16; %Years to run the model
P=1000; %Population to start the model
infected0=0.10; % initial proportion of PWID infected (in 1950)
PWID0=P*0.5; %Equilibrium proportion of PWID to former PWID
S=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
S1=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
S2=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
S3=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
S4=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
A=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T1=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T2=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T3=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T4=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
F0=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
F1=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
F2=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
F3=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
F4=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
DC=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
HCC=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
LT=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
LT2=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
F4_transfer=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Ldeath=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T_total=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
HCC_transfer=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
T_F4on_total=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Liver_transplants=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Inc=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Cas1=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Cas2=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Cas3=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Cas4=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Cas5=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
Cas6=zeros(num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region);
S(1,1,1,1,2,1)=(1-infected0)*PWID0;
S(2,1,1,1,2,1)=P-PWID0;
F0(1,1,1,1,2,1)=infected0*PWID0;
y0=reshape(cat(7,S,S1,S2,S3,S4,A,T,T1,T2,T3,T4,F0,F1,F2,F3,F4,DC,HCC,LT,LT2,F4_transfer,Ldeath,T_total,HCC_transfer,T_F4on_total,Liver_transplants,Inc,Cas1,Cas2,Cas3,Cas4,Cas5,Cas6),...
num_pops, num_cascade, num_age, num_intervention, num_engagement, num_region,33);
t0=0;
for k = 6:13
if x(k) < 0.9*x(k-4)
x(k) = x(k-4);
end
end
if x(14) < 500
x(14) = 500;
end
% for k = 15:(length(x)-2)
% if x(k)< 0.9*x(k-1)
% x(k) = x(k-1);
% end
% end
infect = x(1) / 10;
progression(1,1:4,2,1) = x(2:5);
progression(2,1:4,2,1) = x(6:9);
progression(3,1:4,2,1) = x(10:13);
imp1 = x(14);
imp2 = x(15);
imp3 = x(16);
imp4 = x(17);
imp5 = x(18);
imp6 = x(19);
imp7 = x(20);
imp8 = x(21);
imp9 = x(22);
ost_enrollment = x(23);
nsp_enrollment = x(24);
r_inc_up = x(25);
start_year = x(26);
[TT, y] = DE_track_age(Tin, y0, 0, treat);
[output_prev, output_cascade, output_cascade_PWID, output_disease, output_cases, output_ost, output_nsp, output_diagnoses] = model_vals(TT,y)
%%
function probX = objective(xp)
%loaddata
[infect, progression, imp1, imp2, imp3, imp4, imp5 ,imp6 ,imp7, imp8, imp9, ost_enrollment, nsp_enrollment, r_inc_up, start_year] = feval(@assign,xp);
data = {prev0, cascade0, cascade0_PWID, disease0, cases0, ost0, nsp0, diagnoses0}; % prevalence, cascade to calibrate to
for k = 6:13
if xp(k) < 0.9*xp(k-4)
xp(k) = xp(k-4);
end
end
if xp(14) < 500
xp(14) = 500;
end
% for k = 15:(length(xp)-2)
% if xp(k)< 0.9*xp(k-1)
% xp(k) = xp(k-1);
% end
% end
infect = xp(1) / 10;
progression(1,1:4,2,1) = xp(2:5);
progression(2,1:4,2,1) = xp(6:9);
progression(3,1:4,2,1) = xp(10:13);
imp1 = xp(14);
imp2 = xp(15);
imp3 = xp(16);
imp4 = xp(17);
imp5 = xp(18);
imp6 = xp(19);
imp7 = xp(20);
imp8 = xp(21);
imp9 = xp(22);
ost_enrollment = xp(23);
nsp_enrollment = xp(24);
r_inc_up = xp(25);
start_year = xp(26);
probX = 0;
[TT, y] = DE_track_age(Tin, y0_init, 0, treat);
%infect, progression, imp1, imp2, imp3, imp4, imp5 ,imp6 ,imp7);
[output_prev, output_cascade, output_cascade_PWID, output_disease, output_cases, output_ost, output_nsp, output_diagnoses] = model_vals(TT,y);
sigma_prev = 0.01*data{1}(:,2:end); %standard deviations for prevalence by year
sigma_cascade = 0.1*data{2}(:,2:end); %standard deviations for cascade by year
sigma_cascade_PWID = 0.1*data{3}(:,2:end); %standard deviations for cascade by year
sigma_disease = 0.5*data{4}(:,2:end); %standard deviations for disease by year
sigma_cases = 0.01*data{5}(:,2:end); %standard deviations for cases by year
sigma_ost = 0.001*data{6}(:,2:end); %standard deviations for proportion of PWID on ost by year
sigma_nsp = 0.001*data{7}(:,2:end); %standard deviations for proportion of PWID accessing NSP by year
sigma_diagnoses = 0.1*data{8}(:,2:end); %standard deviations for proportion of PWID accessing NSP by year
for years = 1:length(output_prev(:,1))
probX = probX - (-(data{1}(years,2)-output_prev(years))^2/(2*sigma_prev(years)^2)); %*...
%exp(-(data(2)-output(2))^2/(2*sigma(2)^2))/sigma(2); % Gaussian with SD
end
for years = 1:length(output_cascade(:,1))
for vals = 1:length(output_cascade(years,:))
probX = probX - (-(data{2}(years,vals+1)-output_cascade(years, vals))^2/(2*sigma_cascade(vals)^2));%/sigma_cascade(vals); %*...
end
end
for years = 1:length(output_cascade_PWID(:,1))
for vals = 1:length(output_cascade_PWID(years,:))
probX = probX - (-(data{3}(years,vals+1)-output_cascade_PWID(years, vals))^2/(2*sigma_cascade_PWID(vals)^2));%/sigma_cascade(vals); %*...
end
end
if data{4}(1,1) ~= 0
for years = 1:length(output_disease(:,1))
for vals = 1:length(output_disease(years,:))
probX = probX - (-(data{4}(years,vals+1)-output_disease(years,vals))^2/(2*sigma_disease(years)^2));%/sigma_disease(years); %*...
end
end
end
for years = 1:length(output_cases(:,1))
probX = probX - (-(data{5}(years,2)-output_cases(years))^2/(2*sigma_cases(years)^2));%/sigma_cases(years); %*...
end
for years = 1:length(output_ost(:,1))
probX = probX - (-(data{6}(years,2)-output_ost(years))^2/(2*sigma_ost(years)^2));%/sigma_cases(years); %*...
end
for years = 1:length(output_nsp(:,1))
probX = probX - (-(data{7}(years,2)-output_nsp(years))^2/(2*sigma_nsp(years)^2));%/sigma_cases(years); %*...
end
for years = 1:length(output_diagnoses(:,1))
probX = probX - (-(data{8}(years,2)-output_diagnoses(years))^2/(2*sigma_diagnoses(years)^2));%/sigma_cases(years); %*...
end
end
function [output_prev, output_cascade, output_cascade_PWID, output_disease, output_cases, output_ost, output_nsp, output_diagnoses] = model_vals(TT,y)
output_prev = zeros(length(prev0(:,1)),1);
output_cascade = zeros(length(cascade0(:,1)),1);
output_cascade_PWID = zeros(length(cascade0_PWID(:,1)),1);
output_disease = zeros(length(disease0(:,1)),1);
output_cases = zeros(length(cases0(:,1)),1);
output_ost = zeros(length(ost0(:,1)),1);
output_nsp = zeros(length(nsp0(:,1)),1);
output_diagnoses = zeros(length(diagnoses0(:,1)),1);
for years = 1:length(prev0(:,1))
output_prev(years) = sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-prev0(years,1)),1),1,:,:,:,:,1,6:20))))))./sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-prev0(years,1)),1),1,:,:,:,:,1,1:20))))));
end
for years = 1:length(cascade0(:,1))
output_cascade(years,1) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,2:10,:,:,:,1,6:20)))))))./sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,1:10,:,:,:,1,6:20)))))));
output_cascade(years,2) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,3:10,:,:,:,1,6:20)))))))./sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,1:10,:,:,:,1,6:20)))))));
output_cascade(years,3) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,4:10,:,:,:,1,6:20)))))))./sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,1:10,:,:,:,1,6:20)))))));
output_cascade(years,4) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,6:10,:,:,:,1,6:20)))))))./sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),:,1:10,:,:,:,1,6:20)))))));
%output_cascade(years,5) = sum(sum(sum(y(find(TT>=Tin-(2015-cascade0(years,1)),1),:,8,:,6:20))))./sum(sum(sum(sum(y(find(TT>=Tin-(2015-cascade0(years,1)),1),:,:,:,6:20)))));
end
for years = 1:length(cascade0_PWID(:,1))
output_cascade_PWID(years,1) = sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0_PWID(years,1)),1),1,2:10,:,:,:,1,6:20))))))./sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),1,1:10,:,:,:,1,6:20))))));
output_cascade_PWID(years,2) = sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0_PWID(years,1)),1),1,3:10,:,:,:,1,6:20))))))./sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),1,1:10,:,:,:,1,6:20))))));
output_cascade_PWID(years,3) = sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0_PWID(years,1)),1),1,4:10,:,:,:,1,6:20))))))./sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),1,1:10,:,:,:,1,6:20))))));
output_cascade_PWID(years,4) = sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0_PWID(years,1)),1),1,6:10,:,:,:,1,6:20))))))./sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cascade0(years,1)),1),1,1:10,:,:,:,1,6:20))))));
%output_cascade(years,5) = sum(sum(sum(y(find(TT>=Tin-(2015-cascade0(years,1)),1),:,8,:,6:20))))./sum(sum(sum(sum(y(find(TT>=Tin-(2015-cascade0(years,1)),1),:,:,:,6:20)))));
end
for years = 1:length(disease0(:,1))
dummy = max(2016, disease0(years,1));
output_disease(years,1) = sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,12:13))))))))./sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,12:20)))))))); %F0-1
output_disease(years,2) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,14)))))))./sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,12:20)))))))); %F2
output_disease(years,3) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,15)))))))./sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,12:20)))))))); %F3
output_disease(years,4) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,16)))))))./sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,12:20)))))))); %F4
output_disease(years,5) = sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,17:20))))))))./sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-dummy),1),:,:,:,:,:,:,12:20))))))));
end
for years = 1:length(cases0(:,1))
output_cases(years) = sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-cases0(years,1)),1),:,1:10,:,:,:,:,[6:20]))))))));
end
for years = 1:length(ost0(:,1))
output_ost(years) = sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-ost0(years,1)),1),1,:,:,3:4,:,:,1:20)))))))) / sum(sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-ost0(years,1)),1),1,:,:,:,:,:,1:20))))))));
end
for years = 1:length(nsp0(:,1))
output_nsp(years) = sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-nsp0(years,1)),1),1,:,:,[2,4],:,1,1:20))))))) / sum(sum(sum(sum(sum(sum(y(find(TT>=Tin-(2016-nsp0(years,1)),1),1,:,:,:,:,1,1:20)))))));
end
for years = 1:length(diagnoses0(:,1))
temp = Tin-(2016-diagnoses0(years,1));
output_diagnoses(years) = sum(sum(sum(sum(sum(sum(sum(...
y(find(TT>=temp-1,1):find(TT>=temp,1)-1,:,2,:,:,:,:,28))))))));
end
end
function[infect, progression, imp1, imp2, imp3, imp4, imp5 ,imp6 ,imp7, imp8, imp9, ost_enrollment, nsp_enrollment, r_inc_up, start_year] = assign(x)
%loaddata
infect = x(1) / 10;
progression = zeros(num_pops,num_cascade,num_engagement,num_region);
progression(1,1:4,2,1) = x(2:5);
progression(2,1:4,2,1) = x(6:9);
progression(3,1:4,2,1) = x(10:13);
imp1 = x(14);
imp2 = x(15);
imp3 = x(16);
imp4 = x(17);
imp5 = x(18);
imp6 = x(19);
imp7 = x(20);
imp8 = x(21);
imp9 = x(22);
ost_enrollment = x(23);
nsp_enrollment = x(24);
r_inc_up = x(25);
start_year = x(26);
end
end