forked from ICRC-Models/HHCoM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrator.m
280 lines (246 loc) · 11.1 KB
/
calibrator.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
function negSumLogL = calibrator(initParams)
hpvOn = 1;
hivOn = 1;
% Load up parameters and data
paramDir = [pwd , '\Params\'];
load([paramDir, 'general'])
load([paramDir,'mixInfectIndices'])
load([paramDir,'vlAdvancer'])
load([paramDir,'fertMat'])
load([paramDir,'hivFertMats'])
load([paramDir,'fertMat2'])
load([paramDir,'hivFertMats2'])
load([paramDir,'deathMat'])
load([paramDir,'circMat'])
load([paramDir,'vaxer'])
load([paramDir,'mixInfectParams'])
load([paramDir,'popData'])
load([paramDir,'HIVParams'])
load([paramDir,'hivIndices'])
load([paramDir,'hpvIndices'])
load([paramDir,'ager'])
load([paramDir,'vlBeta'])
load([paramDir,'hpvTreatIndices'])
load([paramDir,'calibParams'])
load([paramDir,'vaxInds'])
load([paramDir,'settings'])
load([paramDir,'hpvData'])
load([paramDir,'calibData'])
load([paramDir,'calibInitParams'])
load([paramDir ,'cost_weights'])
import java.util.LinkedList
vaxerAger = ager;
vaxRate = 0;
startYear = 1980;
endYear = 2015; % run to 2015 for calibration
%% Initial population
load([paramDir , 'popData'])
load([paramDir , 'hpvData'])
% load('initPop')
% simulation
mInit = popInit(: , 1);
fInit = popInit(: , 2);
% test!!!!
riskDistF = riskDistM;
partnersF = partnersM;
MpopStruc = riskDistM;
FpopStruc = riskDistF;
mPop = zeros(age , risk);
fPop = mPop;
for i = 1 : age
mPop(i , :) = MpopStruc(i, :).* mInit(i) ./ 1.25;
fPop(i , :) = FpopStruc(i, :).* fInit(i) ./ 1.25;
end
dim = [disease , viral , hpvTypes , hpvStates , periods , gender , age ,risk];
initPop = zeros(dim);
initPop(1 , 1 , 1 , 1 , 1 , 1 , : , :) = mPop;
initPop(1 , 1 , 1 , 1 , 1 , 2 , : , :) = fPop;
initPop_0 = initPop;
if hivOn
initPop(3 , 2 , 1 , 1 , 1 , 1 , 4 : 6 , 2 : 3) = 0.005 / 2 .* ...
initPop_0(1 , 1 , 1 , 1 , 1 , 1 , 4 : 6 , 2 : 3); % initial HIV infected male (% prevalence)
initPop(1 , 1 , 1 , 1 , 1 , 1 , 4 : 6 , 2 : 3) = ...
initPop_0(1 , 1 , 1 , 1 , 1 , 1 , 4 : 6 , 2 : 3) .* (1 - 0.005 / 2); % moved to HIV infected
initPop(3 , 2 , 1 , 1 , 1 , 2 , 4 : 6 , 2 : 3) = 0.005 / 2 .*...
initPop_0(1 , 1 , 1 , 1 , 1 , 2 , 4 : 6 , 2 : 3); % initial HIV infected female (% prevalence)
initPop(1 , 1 , 1 , 1 , 1 , 2 , 4 : 6 , 2 : 3) = ...
initPop_0(1 , 1 , 1 , 1 , 1 , 2 , 4 : 6 , 2 : 3) .* (1 - 0.005 / 2); % moved to HIV infected
if hpvOn
initPopHiv_0 = initPop;
% HPV infected HIV+
% females
initPop(3 , 2 , 1 , 1 , 1 , 2 , 4 : 6 , 1 : 3) = 0.3 .* ...
initPopHiv_0(3 , 2 , 1 , 1 , 1 , 2 , 4 : 6 , 1 : 3);
% males
initPop(3 , 2 , 1 , 1 , 1 , 1 , 4 : 6 , 1 : 3) = 0.3 .* ...
initPopHiv_0(3 , 2 , 1 , 1 , 1 , 1 , 4 : 6 , 1 : 3);
for h = 2
% females
initPop(3 , 2 , h , 1 , 1 , 2 , 4 : 6 , 1 : 3) = 0.7 .* ...
initPopHiv_0(3 , 2 , 1 , 1 , 1 , 2 , 4 : 6 , 1 : 3);
% males
initPop(3 , 2 , h , 1 , 1 , 1 , 4 : 6 , 1 : 3) = 0.7 .* ...
initPopHiv_0(3 , 2 , 1 , 1 , 1 , 1 , 4 : 6 , 1 : 3);
end
end
end
assert(~any(initPop(:) < 0) , 'Some compartments negative after seeding HIV infections.')
if hpvOn
infected = initPop_0(1 , 1 , 1 , 1 , 1 , : , 4 : 9 , :) * 0.20; % 20% intial HPV prevalence among age groups 4 - 9 (sexually active)
initPop(1 , 1 , 1 , 1 , 1 , : , 4 : 9 , :) = ...
initPop_0(1 , 1 , 1 , 1 , 1 , : , 4 : 9 , :) - infected;
% Omni-HPV type (transition rates weighted by estimated prevalence in population)
initPop(1 , 1 , 2 , 1 , 1 , : , 4 : 9 , :) = infected;
end
assert(~any(initPop(:) < 0) , 'Some compartments negative after seeding HPV infections.')
% Intervention start years
circStartYear = 1990;
vaxStartYear = 2017;
%% calibration parameters
distWeight = [0.7 , 0.2 , 0.1];
kInf_Cin1 = sum(bsxfun(@times , kInf_Cin1 , distWeight) , 2);
kCin1_Cin2 = sum(bsxfun(@times , kCin1_Cin2 , distWeight) , 2);
kCin2_Cin3 = sum(bsxfun(@times , kCin2_Cin3 , distWeight) , 2);
kCin2_Cin1 = sum(bsxfun(@times , kCin2_Cin1 , distWeight) , 2);
kCin3_Cin2 = sum(bsxfun(@times , kCin3_Cin2 , distWeight) , 2);
kCC_Cin3 = sum(bsxfun(@times , kCC_Cin3 , distWeight) , 2);
kCin1_Inf = sum(bsxfun(@times , kCin1_Inf , distWeight) , 2);
rNormal_Inf = sum(bsxfun(@times , rNormal_Inf , distWeight) , 2);
vaxMat = ager .* 0;
maxRateM_vec = [0.40 , 0.40];% maxRateM_arr{sim};
maxRateF_vec = [0.60 , 0.60];% maxRateF_arr{sim};
hpv_hivMult = sum(bsxfun(@times , hpv_hivMult , distWeight) , 2);
% for quickCalibrateModel
kCin1_Inf = initParams(1) .* kCin1_Inf;
rNormal_Inf = initParams(2) .* rNormal_Inf;
kCC_Cin3 = initParams(3) .* kCC_Cin3;
kCin3_Cin2 = initParams(4) .* kCin3_Cin2;
rImmuneHiv = initParams(5 : 8);
c3c2Mults = initParams(9 : 12);
c2c1Mults = initParams(13 : 16);
artHpvMult = initParams(17);
perPartnerHpv= initParams(18);
lambdaMultImm = initParams(19 : 34);
hpv_hivClear = initParams(35 : 38);
partnersM(4 , :) = partnersM(4 , :) .* [1.25 , 1.75 , 1.75];
partnersF(4 , :) = partnersF(4 , :) .* [1.25 , 1.75 , 1.75];
partnersM(5 , :) = partnersM(5 , :) .* [1.25 , 1.5 , 1.75];
partnersF(5 , :) = partnersF(5 , :) .* [1.25 , 1.5 , 1.75];
femaleActs(4 : 5 , :) = femaleActs(4 : 5 , :) .* 1.2 ;
femaleActs(6 : 10 , :) = femaleActs(6 : 10 , :) .* 0.9;
maleActs(4 : 5 , :) = maleActs(4 : 5 , :);
for i = 0 : 2
maleActs(: , i + 1) = maleActs(: , i + 1) .* initParams(39 + i);
femaleActs(: , i + 1) = femaleActs(: , i + 1) .* initParams(42 + i);
end
for i = 0 : 2
partnersM(: , i + 1) = partnersM(: , i + 1) .* initParams(45 + i);
partnersF(: , i + 1) = partnersF(: , i + 1) .* initParams(48 + i);
end
for a = 1 : age
betaHIVF2M(a , : , :) = 1 - (bsxfun(@power, 1 - betaHIV_F2M , maleActs(a , :)')); % HIV(-) males
betaHIVM2F(a , : , :) = 1 - (bsxfun(@power, 1 - betaHIV_M2F , femaleActs(a , :)')); % HIV(-) females
end
betaHIVM2F = permute(betaHIVM2F , [2 1 3]); % risk, age, vl
betaHIVF2M = permute(betaHIVF2M , [2 1 3]); % risk, age, vl
%% Simulation variable preparation
fImm(1 : age) = 1; % all infected individuals who clear HPV get natural immunity
lambdaMultVax = ones(age , 2);
% Initialize vectors
timeStep = 1 / stepsPerYear;
years = endYear - startYear;
s = 1 : timeStep : years + 1; % stepSize and steps calculated in loadUp.m
artDistMat = zeros(size(prod(dim) , 20)); % initialize artDistMat to track artDist over past 20 time steps
popVec = spalloc(years / timeStep , prod(dim) , 10 ^ 8);
popIn = reshape(initPop , prod(dim) , 1); % initial population to "seed" model
newHiv = zeros(length(s) - 1 , gender , age , risk);
newHpv = zeros(length(s) - 1 , gender , disease , age , risk);
newImmHpv = newHpv;
newVaxHpv = newHpv;
newCC = zeros(length(s) - 1 , disease , hpvTypes , age);
ccDeath = newCC;
ccTreatCost = zeros(length(s) - 1 , disease , hpvTypes , age , 3); % 3 cancer stages: local, regional, distant
vaxd = zeros(length(s) - 1 , 1);
hivDeaths = zeros(length(s) - 1 , gender , age);
deaths = popVec;
artTreatTracker = zeros(length(s) - 1 , disease , viral , gender , age , risk);
popVec(1 , :) = popIn;
k = cumprod([disease , viral , hpvTypes , hpvStates , periods , gender , age]);
artDist = zeros(disease , viral , gender , age , risk); % initial distribution of inidividuals on ART = 0
vaxMat = ager .* 0;
maxRateM1 = 1 - exp(-maxRateM_vec(1));
maxRateM2 = 1 - exp(-maxRateM_vec(2));
maxRateF1 = 1 - exp(-maxRateF_vec(1));
maxRateF2 = 1 - exp(-maxRateF_vec(2));
%% Simulation
for i = 2 : length(s) - 1
tic
year = startYear + s(i) - 1;
currStep = round(s(i) * stepsPerYear);
tspan = [s(i) , s(i + 1)]; % evaluate diff eqs over one time interval
popIn = popVec(i - 1 , :);
if hpvOn
hystOption = 'on';
[~ , pop , newCC(i , : , : , :) , ccDeath(i , : , : , :) , ...
ccTreatCost(i , : , : , : , :)] ...
= ode4xtra(@(t , pop) ...
hpv(t , pop , immuneInds , infInds , cin1Inds , ...
cin2Inds , cin3Inds , normalInds , ccInds , ccRegInds , ccDistInds , ...
ccTreatedInds , kInf_Cin1 , kCin1_Cin2 , kCin2_Cin3 , ...
kCin2_Cin1 , kCin3_Cin2 , kCC_Cin3 , kCin1_Inf ,...
rNormal_Inf , hpv_hivClear , c3c2Mults , ...
c2c1Mults , fImm , kRL , kDR , muCC , kCCDet , ...
disease , viral , age , hpvTypes , ...
rImmuneHiv , vaccinated , hystOption) , tspan , popIn);
popIn = pop(end , :);
if any(pop(end , :) < 0)
disp('After hpv')
break
end
end
[~ , pop , newHpv(i , : , : , : , :) , newImmHpv(i , : , : , : , :) , ...
newVaxHpv(i , : , : , : , :) , newHiv(i , : , : , :)] = ...
ode4xtra(@(t , pop) mixInfect(t , pop , currStep , ...
gar , perPartnerHpv , perPartnerHpv_lr , perPartnerHpv_nonV , ...
lambdaMultImm , lambdaMultVax , artHpvMult , epsA_vec , epsR_vec , yr , modelYr1 , ...
circProtect , condProtect , condUse , actsPer , partnersM , partnersF , ...
hpv_hivMult , hpvSus , hpvImm , toHpv_Imm , hpvVaxd , hpvVaxd2 , toHpv , toHpv_ImmVax , ...
toHpv_ImmVaxNonV , hivSus , toHiv , mCurr , fCurr , mCurrArt , fCurrArt , ...
betaHIVF2M , betaHIVM2F , disease , viral , gender , age , risk , hpvStates , hpvTypes , ...
hrInds , lrInds , hrlrInds , periods , startYear , stepsPerYear , year) , tspan , popIn);
popIn = pop(end , :); % for next mixing and infection module
if any(pop(end , :) < 0)
disp('After mixInfect')
break
end
if hivOn
[~ , pop , hivDeaths(i , : , :) , artTreat] =...
ode4xtra(@(t , pop) hiv2a(t , pop , vlAdvancer , artDist , muHIV , ...
kCD4 , maxRateM1 , maxRateM2 , maxRateF1 , maxRateF2 , disease , ...
viral , gender , age , risk , k , hivInds , ...
stepsPerYear , year) , tspan , pop(end , :));
artTreatTracker(i , : , : , : , : ,:) = artTreat;
if any(pop(end , :) < 0)
disp('After hiv')
break
end
end
[~ , pop , deaths(i , :) , vaxd(i , :)] = ode4xtra(@(t , pop) ...
bornAgeDie(t , pop , ager , year , currStep , age , fertility , ...
fertMat , fertMat2 , hivFertPosBirth ,hivFertNegBirth , hivFertPosBirth2 , ...
hivFertNegBirth2 , deathMat , circMat , ...
vaxerAger , vaxMat , MTCTRate , circStartYear , vaxStartYear ,...
vaxRate , startYear , endYear, stepsPerYear) , tspan , pop(end , :));
if any(pop(end , :) < 0)
disp('After bornAgeDie')
break
end
% add results to population vector
popVec(i , :) = pop(end , :)';
end
popLast = popVec(end , :);
popVec = sparse(popVec); % compress population vectors
negSumLogL = likeFun(popVec , newCC , cinPos2014_obs , cinNeg2014_obs ,...
hpv_hiv_2008_obs , hpv_hivNeg_2008_obs , hpv_hiv_obs , hpv_hivNeg_obs , ...
hivPrevM_obs , hivPrevF_obs , disease , viral , gender , age , risk , ...
hpvTypes , hpvStates , periods , startYear , stepsPerYear);