libspatialSEIR  0.1
Bayesian Spatial SEIR Modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ModelContext.hpp
Go to the documentation of this file.
1 #ifndef SPATIALSEIR_INCLUDEFILES
2 #define SPATIALSEIR_INCLUDEFILES
3 
4 #include<cstring>
5 #include<vector>
6 #endif
7 
8 #ifndef MODEL_CONTEXT_INC
9 #define MODEL_CONTEXT_INC
10 
11 #define LSS_DEGENERATE_DATA_MODEL 1
12 #define LSS_OVERDISPERSED_DATA_MODEL 2
13 
14 #include<Eigen/Core>
15 namespace SpatialSEIR
16 {
17 
18  typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> MatrixType;
19  typedef Eigen::Map<MatrixType, Eigen::ColMajor> MatrixMapType;
20  typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> IntMatrixType;
21  typedef Eigen::Map<IntMatrixType, Eigen::ColMajor> IntMatrixMapType;
22 
23  class FullConditional;
24  class IterationTask;
28  class FC_S0;
29  class FC_E0;
30  class FC_I0;
31  class FC_R0;
32  class FC_S_Star;
33  class FC_E_Star;
34  class FC_R_Star;
35  class FC_Beta;
36  class FC_Gamma_EI;
37  class FC_Gamma_IR;
38  class FC_Beta_P_RS;
39  class FC_Rho;
41  class FC_Phi;
42  class InitData;
43 
45  class CovariateMatrix;
46  class DistanceMatrix;
48  class OCLProvider;
49  class IOProvider;
50  struct covariateArgs;
51  struct compartmentArgs;
52  struct distanceArgs;
53  struct scaledDistanceArgs;
54  struct gammaArgs;
55  struct sliceParameters;
56  struct priorControl;
57 
63  {
70  int dataModel;
71  };
72 
73 
74 
83  {
84  public:
85  //Methods
86  ModelContext();
87  ~ModelContext();
91  void populate(InitData* _A0,
93  covariateArgs* xArgs,
97  covariateArgs* xPrsArgs,
101  double* offset,
103  int* Y,
106  compartmentArgs* S_starArgs,
110  compartmentArgs* E_starArgs,
114  compartmentArgs* I_starArgs,
118  compartmentArgs* R_starArgs,
122  scaledDistanceArgs* scaledDistArgs,
126  double* rho,
127  double* phi,
128  double* beta,
129  double* gamma_ei,
130  double* gamma_ir,
131  double* betaPrs,
132  int* N,
133  sliceParameters* sliceWidths,
135  priorControl* priorInformation,
137  modelConfiguration _config
139  );
140 
141  /*buildModel is called at the end of the populate function to fill the ModelContext.model vector with the required
142  full conditional distributions.*/
143  void buildModel();
144 
148 
150  void calculateS_CPU();
151 
156  void calculateS_CPU(int startLoc, int startTime);
157 
160  void calculateS_givenE_CPU();
161 
166  void calculateS_givenE_CPU(int startLoc, int startTime);
167 
170  void calculateS_OCL();
171 
173  void calculateE_CPU();
174 
179  void calculateE_CPU(int startLoc, int startTime);
180 
183  void calculateE_givenI_CPU();
184 
189  void calculateE_givenI_CPU(int startLoc, int startTime);
190 
193  void calculateE_OCL();
194 
196  void calculateI_CPU();
197 
202  void calculateI_CPU(int startLoc, int startTime);
203 
206  void calculateI_givenR_CPU();
207 
212  void calculateI_givenR_CPU(int startLoc, int startTime);
213 
216  void calculateI_OCL();
217 
219  void calculateR_CPU();
220 
225  void calculateR_CPU(int startLoc, int startTime);
226 
229  void calculateR_givenS_CPU();
230 
235  void calculateR_givenS_CPU(int startLoc, int startTime);
236 
239  void calculateR_OCL();
240 
245  int *comp0,
246  CompartmentalModelMatrix *compStarAdd,
247  CompartmentalModelMatrix *compStarSub
248  );
249 
255  int *comp0,
256  CompartmentalModelMatrix *compStarAdd,
257  CompartmentalModelMatrix *compStarSub,
258  int startLoc,
259  int startTime
260  );
261 
264  void calculateGenericCompartment_OCL(int *comp,
265  int *comp0,
266  int *compStarAdd,
267  int *compStarSub
268  );
269 
272  int checkCompartmentBounds();
273 
276  void printFCValues();
277 
280  void setRandomSeed(unsigned int seedValue);
281 
284  void simulationIter(bool verbose, bool debug);
285 
288  void runSimulation(int nIterations, bool verbose, bool debug);
289 
294  void updateSamplingParameters(double desiredRatio,
295  double targetWidth,
296  double proportionChange
297  );
298 
301  void setCompartmentSamplingMode(int mode);
302 
305 
308  void setParameterSamplingMode(int mode);
309 
312 
313 
314 
315 
316 
321  void cacheP_SE_Calculation();
322 
325  void calculateP_SE_CPU();
326 
330  void calculateP_SE_CPU(int startLoc, int startTime);
331 
334  void calculateP_SE_OCL();
335 
337  void calculateP_EI_CPU();
338 
340  void calculateP_IR_CPU();
341 
343  void calculateP_RS_CPU();
344 
346  int totalS();
348  int totalE();
350  int totalI();
352  int totalR();
353 
355  int totalS(int tpt);
357  int totalE(int tpt);
359  int totalI(int tpt);
361  int totalR(int tpt);
362 
364  int totalS_star();
366  int totalE_star();
368  int totalI_star();
370  int totalR_star();
371 
373  int totalS_star(int tpt);
375  int totalE_star(int tpt);
377  int totalI_star(int tpt);
379  int totalR_star(int tpt);
380 
382  double avgP_SE();
384  double avgP_RS();
386  double avgP_SE(int tpt);
387 
389  double estimateR0();
391  double* estimateR0(int t);
393  double estimateEffectiveR0();
395  double* estimateEffectiveR0(int t);
397  double* calculateR0Components(int t);
399  double* calculateEffectiveR0Components(int t);
401  double* calculateG(int t);
403  double* calculateIntegratedG(int t);
404 
405 
406 
407 
408  //Logic provider and utility classes
445 
452 
453  //Data
455  int* Y;
479  std::vector<DistanceMatrix*>* scaledDistMatrices;
487  std::vector<FullConditional*>* model;
490  std::vector<IterationTask*>* iterationTasks;
492  double* beta;
494  double* betaPrs;
496  double* rho;
498  double* phi;
500  double* gamma;
502  double* eta;
504  double* offset;
506  double* p_se;
514  int* indexList;
516  double* gamma_ei;
518  double* p_ei;
520  double* gamma_ir;
522  double* p_ir;
524  double* p_rs;
526  int* N;
534  };
535 }
536 #endif
double avgP_SE()
Definition: ModelContextSummaryFunctions.cpp:97
Definition: LSS_FC_R_star.hpp:18
std::vector< DistanceMatrix * > * scaledDistMatrices
Definition: ModelContext.hpp:479
std::vector< FullConditional * > * model
Definition: ModelContext.hpp:487
int totalR()
Definition: ModelContextSummaryFunctions.cpp:40
Definition: LSS_FC_S0.hpp:17
void calculateI_CPU()
Definition: ModelContext.cpp:861
CompartmentalModelMatrix * S
Definition: ModelContext.hpp:457
int dataModel
Definition: ModelContext.hpp:70
FC_Gamma_IR * gamma_ir_fc
Definition: ModelContext.hpp:440
FC_S_Star * S_star_fc
Definition: ModelContext.hpp:426
double * compartmentCache
Definition: ModelContext.hpp:510
Definition: IOProvider.hpp:59
void calculateP_EI_CPU()
Definition: ModelContext.cpp:1053
void calculateR_CPU()
Definition: ModelContext.cpp:919
void calculateP_SE_OCL()
Definition: ModelContext.cpp:1249
Definition: DistanceMatrix.hpp:22
Definition: LSS_FC_Beta_P_RS.hpp:19
modelConfiguration * config
Definition: ModelContext.hpp:483
int totalI()
Definition: ModelContextSummaryFunctions.cpp:36
CovariateMatrix * X
Definition: ModelContext.hpp:475
void calculateGenericCompartment_CPU(CompartmentalModelMatrix *comp, int *comp0, CompartmentalModelMatrix *compStarAdd, CompartmentalModelMatrix *compStarSub)
Definition: ModelContext.cpp:981
int * indexList
Definition: ModelContext.hpp:514
double * p_rs
Definition: ModelContext.hpp:524
PerformDecorrelationStep * decorrelationStepTask
Definition: ModelContext.hpp:451
int * indexLength
Definition: ModelContext.hpp:512
IOProvider * fileProvider
Definition: ModelContext.hpp:410
std::vector< IterationTask * > * iterationTasks
Definition: ModelContext.hpp:490
double * gamma
Definition: ModelContext.hpp:500
void setParameterSamplingMode(int mode)
Definition: ModelContext.cpp:90
InitData * A0
Definition: ModelContext.hpp:473
void configureIterationTasks()
Definition: ModelContext.cpp:440
Definition: CovariateMatrix.hpp:29
int performHybridStep
Definition: ModelContext.hpp:69
int totalI_star()
Definition: ModelContextSummaryFunctions.cpp:70
int * numIterations
Definition: ModelContext.hpp:532
RandomNumberProvider * random
Definition: ModelContext.hpp:413
void setRandomSeed(unsigned int seedValue)
Definition: ModelContext.cpp:36
double estimateR0()
Definition: ModelContextSummaryFunctions.cpp:134
void calculateE_givenI_CPU()
Definition: ModelContext.cpp:815
Definition: CompartmentalModelMatrix.hpp:25
int totalE()
Definition: ModelContextSummaryFunctions.cpp:32
double * offset
Definition: ModelContext.hpp:504
int * N
Definition: ModelContext.hpp:526
struct containing initial slice sampling tuning parameters.
Definition: LSS_FullConditional.hpp:39
int useDecorrelation
Definition: ModelContext.hpp:68
Definition: LSS_IterationTasks.hpp:53
Definition: LSS_IterationTasks.hpp:40
FC_I_Star_overdispersed * I_star_overdispersed_fc
Definition: ModelContext.hpp:442
double * calculateEffectiveR0Components(int t)
Definition: ModelContextSummaryFunctions.cpp:346
FC_R_Star * R_star_fc
Definition: ModelContext.hpp:430
Eigen::Map< MatrixType, Eigen::ColMajor > MatrixMapType
Definition: ModelContext.hpp:19
FC_Rho * rho_fc
Definition: ModelContext.hpp:434
FC_S0 * S0_fc
Definition: ModelContext.hpp:418
Definition: LSS_FC_Rho.hpp:17
double * eta
Definition: ModelContext.hpp:502
void buildModel()
Definition: ModelContext.cpp:466
Definition: LSS_FC_E0.hpp:17
void calculateE_CPU()
Definition: ModelContext.cpp:802
Definition: CovariateMatrix.hpp:19
void setCompartmentSamplingMode(int mode)
Definition: ModelContext.cpp:43
double * beta
Definition: ModelContext.hpp:492
Definition: LSS_FC_R0.hpp:17
CompartmentalModelMatrix * I
Definition: ModelContext.hpp:461
Definition: DistanceMatrix.hpp:16
int totalS()
Definition: ModelContextSummaryFunctions.cpp:28
void simulationIter(bool verbose, bool debug)
Definition: ModelContext.cpp:692
SetCompartmentSamplingIndicesTask * setSamplingIndicesTask
Definition: ModelContext.hpp:447
void populate(InitData *_A0, covariateArgs *xArgs, covariateArgs *xPrsArgs, double *offset, int *Y, compartmentArgs *S_starArgs, compartmentArgs *E_starArgs, compartmentArgs *I_starArgs, compartmentArgs *R_starArgs, scaledDistanceArgs *scaledDistArgs, double *rho, double *phi, double *beta, double *gamma_ei, double *gamma_ir, double *betaPrs, int *N, sliceParameters *sliceWidths, priorControl *priorInformation, modelConfiguration _config)
Definition: ModelContext.cpp:109
void runSimulation(int nIterations, bool verbose, bool debug)
Definition: ModelContext.cpp:725
CompartmentalModelMatrix * E
Definition: ModelContext.hpp:459
PerformHybridSE_EI_UpdateStep * performHybridSE_EI_UpdateTask
Definition: ModelContext.hpp:449
int checkCompartmentBounds()
Definition: ModelContext.cpp:537
int totalS_star()
Definition: ModelContextSummaryFunctions.cpp:62
void calculateE_OCL()
Definition: ModelContext.cpp:853
void calculateGenericCompartment_OCL(int *comp, int *comp0, int *compStarAdd, int *compStarSub)
Definition: ModelContext.cpp:1046
double * calculateIntegratedG(int t)
Definition: ModelContextSummaryFunctions.cpp:186
double avgP_RS()
Definition: ModelContextSummaryFunctions.cpp:122
double * gamma_ir
Definition: ModelContext.hpp:520
Definition: LSS_FC_Phi.hpp:17
Definition: LSS_FullConditional.hpp:86
double * betaPrs
Definition: ModelContext.hpp:494
int totalR_star()
Definition: ModelContextSummaryFunctions.cpp:74
double * p_ir
Definition: ModelContext.hpp:522
int getCompartmentSamplingMode()
Definition: ModelContext.cpp:85
double * p_ei
Definition: ModelContext.hpp:518
Definition: LSS_FC_I0.hpp:18
void calculateP_IR_CPU()
Definition: ModelContext.cpp:1064
CompartmentalModelMatrix * S_star
Definition: ModelContext.hpp:465
void calculateS_CPU()
Definition: ModelContext.cpp:745
CompartmentalModelMatrix * R_star
Definition: ModelContext.hpp:471
void cacheP_SE_Calculation()
Definition: ModelContext.cpp:1219
double * p_se
Definition: ModelContext.hpp:506
void updateSamplingParameters(double desiredRatio, double targetWidth, double proportionChange)
Definition: ModelContext.cpp:683
void calculateR_givenS_CPU()
Definition: ModelContext.cpp:936
FC_E0 * E0_fc
Definition: ModelContext.hpp:420
Definition: RandomNumberProvider.hpp:78
int indexLength
Definition: ModelContext.hpp:67
FC_Beta_P_RS * betaPrs_fc
Definition: ModelContext.hpp:436
~ModelContext()
Definition: ModelContext.cpp:1254
Definition: LSS_FC_S_star.hpp:18
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixType
Definition: ModelContext.hpp:18
FC_R0 * R0_fc
Definition: ModelContext.hpp:424
void printFCValues()
Definition: ModelContext.cpp:647
Definition: LSS_IterationTasks.hpp:27
int compartmentSamplingMode
Definition: ModelContext.hpp:65
struct containing hyperparameters for beta, betaP_RS, P_EI, and P_IR
Definition: LSS_FullConditional.hpp:26
CompartmentalModelMatrix * I_star
Definition: ModelContext.hpp:469
double * p_se_components
Definition: ModelContext.hpp:508
double * calculateR0Components(int t)
Definition: ModelContextSummaryFunctions.cpp:400
Definition: LSS_FC_Gamma_EI.hpp:18
void calculateS_OCL()
Definition: ModelContext.cpp:793
Definition: DistanceMatrix.hpp:36
void calculateI_OCL()
Definition: ModelContext.cpp:911
int totalE_star()
Definition: ModelContextSummaryFunctions.cpp:66
CovariateMatrix * X_pRS
Definition: ModelContext.hpp:477
Definition: OCLProvider.hpp:123
Definition: LSS_FC_Gamma_IR.hpp:18
void calculateI_givenR_CPU()
Definition: ModelContext.cpp:874
int reinfectionMode
Definition: ModelContext.hpp:64
CompartmentalModelMatrix * E_star
Definition: ModelContext.hpp:467
FC_E_Star * E_star_fc
Definition: ModelContext.hpp:428
FC_Beta * beta_fc
Definition: ModelContext.hpp:432
int getParameterSamplingMode()
Definition: ModelContext.cpp:104
Definition: LSS_FC_I_star_overdispersion.hpp:16
void calculateP_SE_CPU()
Definition: ModelContext.cpp:1092
Simple class containing the starting compartment sizes.
Definition: LSS_FullConditional.hpp:55
double * calculateG(int t)
Definition: ModelContextSummaryFunctions.cpp:286
int * isPopulated
Definition: ModelContext.hpp:528
int parameterSamplingMode
Definition: ModelContext.hpp:66
CompartmentalModelMatrix * R
Definition: ModelContext.hpp:463
double * rho
Definition: ModelContext.hpp:496
int * singleLocation
Definition: ModelContext.hpp:530
CompartmentalModelMatrix * tmpContainer
Definition: ModelContext.hpp:481
FC_Phi * phi_fc
Definition: ModelContext.hpp:444
void calculateP_RS_CPU()
Definition: ModelContext.cpp:1078
Eigen::Matrix< int, Eigen::Dynamic, Eigen::Dynamic > IntMatrixType
Definition: ModelContext.hpp:20
Definition: ModelContext.hpp:82
Definition: LSS_FC_E_star.hpp:17
double * phi
Definition: ModelContext.hpp:498
int * Y
Definition: ModelContext.hpp:455
FC_I0 * I0_fc
Definition: ModelContext.hpp:422
Eigen::Map< IntMatrixType, Eigen::ColMajor > IntMatrixMapType
Definition: ModelContext.hpp:21
Definition: CompartmentalModelMatrix.hpp:17
void calculateR_OCL()
Definition: ModelContext.cpp:972
Definition: LSS_IterationTasks.hpp:67
ModelContext()
Definition: ModelContext.cpp:29
Definition: LSS_FC_Beta.hpp:19
double * gamma_ei
Definition: ModelContext.hpp:516
OCLProvider * oclProvider
Definition: ModelContext.hpp:416
Definition: ModelContext.hpp:62
FC_Gamma_EI * gamma_ei_fc
Definition: ModelContext.hpp:438
void calculateS_givenE_CPU()
Definition: ModelContext.cpp:757
double estimateEffectiveR0()
Definition: ModelContextSummaryFunctions.cpp:234