phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
si2r.cc
Go to the documentation of this file.
1// SI2R: Two-deme model of superspreading (C++)
2#include "master.h"
3#include "popul_proc.h"
4#include "generics.h"
5#include "internal.h"
6
7static const int L = 1;
8static const int H = 2;
9
11typedef struct {
12 int S;
13 int IL;
14 int IH;
15 int R;
17
19typedef struct {
20 double Beta;
21 double kappa;
22 double gamma;
23 double omega;
24 double chi;
25 double etaL;
26 double etaH;
27 double pop;
28 double S0;
29 double IL0;
30 double IH0;
31 double R0;
33
36
37template<>
38std::string si2r_proc_t::yaml (std::string tab) const {
39 std::string t = tab + " ";
40 std::string p = tab + "parameter:\n"
42 + YAML_PARAM(kappa)
46 + YAML_PARAM(etaL)
47 + YAML_PARAM(etaH)
48 + YAML_PARAM(pop)
49 + YAML_PARAM(S0)
50 + YAML_PARAM(IL0)
51 + YAML_PARAM(IH0)
52 + YAML_PARAM(R0);
53 std::string s = tab + "state:\n"
54 + YAML_STATE(S)
55 + YAML_STATE(IL)
56 + YAML_STATE(IH)
57 + YAML_STATE(R);
58 return p+s;
59}
60
61template<>
62void si2r_proc_t::update_params (double *p, int n) {
63 int m = 0;
65 PARAM_SET(kappa);
69 PARAM_SET(etaL);
70 PARAM_SET(etaH);
71 if (m != n) err("wrong number of parameters!");
72}
73
74template<>
75void si2r_proc_t::update_IVPs (double *p, int n) {
76 int m = 0;
77 PARAM_SET(pop);
79 PARAM_SET(IL0);
80 PARAM_SET(IH0);
82 if (m != n) err("wrong number of initial-value parameters!");
83}
84
85template<>
86double si2r_proc_t::event_rates (double *rate, int n) const {
87 int m = 0;
88 double total = 0;
89 RATE_CALC(params.Beta * state.S * state.IL / params.pop);
90 RATE_CALC(params.kappa * params.Beta * state.S * state.IH / params.pop);
91 RATE_CALC(params.etaL * state.IL);
92 RATE_CALC(params.etaH * state.IH);
93 RATE_CALC(params.gamma * state.IL);
94 RATE_CALC(params.gamma * state.IH);
95 RATE_CALC(params.omega * state.R);
96 RATE_CALC(params.chi * state.IL);
97 RATE_CALC(params.chi * state.IH);
98 if (m != n) err("wrong number of events!");
99 return total;
100}
101
102template<>
104 double f = params.pop/(params.S0+params.IL0+params.IH0+params.R0);
105 state.S = nearbyint(f*params.S0);
106 state.IL = nearbyint(f*params.IL0);
107 state.IH = nearbyint(f*params.IH0);
108 state.R = nearbyint(f*params.R0);
109 graft(L,state.IL);
110 graft(H,state.IH);
111}
112
113template<>
115 switch (event) {
116 case 0:
117 state.S -= 1; state.IL += 1; birth(L,L);
118 break;
119 case 1:
120 state.S -= 1; state.IL += 1; birth(H,L);
121 break;
122 case 2:
123 state.IL -= 1; state.IH += 1; migrate(L,H);
124 break;
125 case 3:
126 state.IL += 1; state.IH -= 1; migrate(H,L);
127 break;
128 case 4:
129 state.IL -= 1; state.R += 1; death(L);
130 break;
131 case 5:
132 state.IH -= 1; state.R += 1; death(H);
133 break;
134 case 6:
135 state.R -= 1; state.S += 1;
136 break;
137 case 7:
138 state.IL -= 1; sample_death(L);
139 break;
140 case 8:
141 state.IH -= 1; sample_death(H);
142 break;
143 default: // #nocov
144 assert(0); // #nocov
145 break; // #nocov
146 }
147}
148
Encodes the master process.
Definition master.h:21
void graft(name_t i=1, int m=1)
new root in deme i
Definition master.h:153
void birth(name_t i=1, name_t j=1, int n=1)
n births into deme j with parent in deme i
Definition master.h:136
void sample_death(name_t i=1, int n=1)
sample_death in deme i
Definition master.h:169
void death(name_t i=1)
death in deme i
Definition master.h:147
void migrate(name_t i=1, name_t j=1)
migration from deme i to deme j
Definition master.h:179
Population process class.
Definition popul_proc.h:16
double event_rates(double *rate, int n) const
Definition si2r.cc:86
#define GENERICS(X, TYPE)
Definition generics.h:133
#define err(...)
Definition internal.h:18
#define chi
Definition lbdp_pomp.c:7
#define n
Definition lbdp_pomp.c:9
#define YAML_PARAM(X)
Definition popul_proc.h:136
#define RATE_CALC(X)
Definition popul_proc.h:135
#define YAML_STATE(X)
Definition popul_proc.h:137
#define PARAM_SET(X)
Definition popul_proc.h:134
#define R0
Definition seirs_pomp.c:35
#define gamma
Definition seirs_pomp.c:29
#define R
Definition seirs_pomp.c:40
#define S0
Definition seirs_pomp.c:32
#define Beta
Definition seirs_pomp.c:27
#define omega
Definition seirs_pomp.c:31
#define S
Definition seirs_pomp.c:37
static const int H
Definition si2r.cc:8
static const int L
Definition si2r.cc:7
master_t< si2r_proc_t, 2 > si2r_genealogy_t
Definition si2r.cc:35
popul_proc_t< si2r_state_t, si2r_parameters_t, 9 > si2r_proc_t
Definition si2r.cc:34
SI2R process parameters.
Definition si2r.cc:19
double gamma
Definition si2r.cc:22
double omega
Definition si2r.cc:23
double Beta
Definition si2r.cc:20
double kappa
Definition si2r.cc:21
double etaH
Definition si2r.cc:26
double etaL
Definition si2r.cc:25
SI2R process state.
Definition si2r.cc:11