phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
twoundead.cc
Go to the documentation of this file.
1// TwoUndead: Two-host infection model with waning, immigration, demography, and spillover. Hosts are culled upon sampling with a given probability. This is identical to the TwoSpecies model with the exception that dead lineages are not pruned. Instead, they become *ghosts*. (C++)
2#include "master.h"
3#include "popul_proc.h"
4#include "generics.h"
5#include "internal.h"
6
7static int host1 = 0;
8static int host2 = 1;
9static int ghost1 = 2;
10static int ghost2 = 3;
11static int outside = 4;
12
14typedef struct {
15 int S1;
16 int I1;
17 int R1;
18 int S2;
19 int I2;
20 int R2;
21 double N1;
22 double N2;
24
26typedef struct {
27 double Beta11;
28 double Beta12;
29 double Beta21;
30 double Beta22;
31 double gamma1;
32 double gamma2;
33 double psi1;
34 double psi2;
35 double c1;
36 double c2;
37 double omega1;
38 double omega2;
39 double b1;
40 double b2;
41 double d1;
42 double d2;
43 double iota1;
44 double iota2;
45 int S1_0;
46 int S2_0;
47 int I1_0;
48 int I2_0;
49 int R1_0;
50 int R2_0;
52
55
56template<>
57std::string twoundead_proc_t::yaml (std::string tab) const {
58 std::string t = tab + " ";
59 std::string p = tab + "parameter:\n"
68 + YAML_PARAM(c1)
69 + YAML_PARAM(c2)
72 + YAML_PARAM(b1)
73 + YAML_PARAM(b2)
74 + YAML_PARAM(d1)
75 + YAML_PARAM(d2)
76 + YAML_PARAM(iota1)
77 + YAML_PARAM(iota2)
84 std::string s = tab + "state:\n"
85 + YAML_STATE(S1)
86 + YAML_STATE(I1)
87 + YAML_STATE(R1)
88 + YAML_STATE(S2)
89 + YAML_STATE(I2)
90 + YAML_STATE(R2)
91 + YAML_STATE(N1)
92 + YAML_STATE(N2);
93 return p+s;
94}
95
96template<>
97void twoundead_proc_t::update_params (double *p, int n) {
98 int m = 0;
107 PARAM_SET(c1);
108 PARAM_SET(c2);
111 PARAM_SET(b1);
112 PARAM_SET(b2);
113 PARAM_SET(d1);
114 PARAM_SET(d2);
115 PARAM_SET(iota1);
116 PARAM_SET(iota2);
117 if (m != n) err("wrong number of parameters!");
118}
119
120template<>
121void twoundead_proc_t::update_IVPs (double *p, int n) {
122 int m = 0;
129 if (m != n) err("wrong number of initial-value parameters!");
130}
131
132template<>
133double twoundead_proc_t::event_rates (double *rate, int n) const {
134 int m = 0;
135 double total = 0;
136 RATE_CALC(params.Beta11 * state.I1 / state.N1 * state.S1);
137 RATE_CALC(params.Beta22 * state.I2 / state.N2 * state.S2);
138 RATE_CALC(params.Beta12 * state.I2 / state.N2 * state.S1);
139 RATE_CALC(params.Beta21 * state.I1 / state.N1 * state.S2);
140 RATE_CALC(params.gamma1 * state.I1);
141 RATE_CALC(params.gamma2 * state.I2);
142 RATE_CALC(params.omega1 * state.R1);
143 RATE_CALC(params.omega2 * state.R2);
144 RATE_CALC(params.psi1 * params.c1 * state.I1);
145 RATE_CALC(params.psi2 * params.c2* state.I2);
146 RATE_CALC(params.psi1 * (1-params.c1) * state.I1);
147 RATE_CALC(params.psi2 * (1-params.c2) * state.I2);
148 RATE_CALC(params.iota1 * state.S1);
149 RATE_CALC(params.iota2 * state.S2);
150 RATE_CALC(params.d1 * state.S1);
151 RATE_CALC(params.d2 * state.S2);
152 RATE_CALC(params.d1 * state.I1);
153 RATE_CALC(params.d2 * state.I2);
154 RATE_CALC(params.d1 * state.R1);
155 RATE_CALC(params.d2 * state.R2);
156 RATE_CALC(params.b1 * state.N1);
157 RATE_CALC(params.b2 * state.N2);
158 if (m != n) err("wrong number of events!");
159 return total;
160}
161
162template<>
164 state.S1 = params.S1_0;
165 state.I1 = params.I1_0;
166 state.R1 = params.R1_0;
167 state.S2 = params.S2_0;
168 state.I2 = params.I2_0;
169 state.R2 = params.R2_0;
170 state.N1 = double(params.S1_0+params.I1_0+params.R1_0);
171 state.N2 = double(params.S2_0+params.I2_0+params.R2_0);
172 graft(host1,params.I1_0);
173 graft(host2,params.I2_0);
174}
175
176template<>
178 switch (event) {
179 case 0:
180 state.S1 -= 1; state.I1 += 1; birth(host1,host1);
181 break;
182 case 1:
183 state.S2 -= 1; state.I2 += 1; birth(host2,host2);
184 break;
185 case 2:
186 state.S1 -= 1; state.I1 += 1; birth(host2,host1);
187 break;
188 case 3:
189 state.S2 -= 1; state.I2 += 1; birth(host1,host2);
190 break;
191 case 4:
192 state.I1 -= 1; state.R1 += 1; migrate(host1,ghost1);
193 break;
194 case 5:
195 state.I2 -= 1; state.R2 += 1; migrate(host2,ghost2);
196 break;
197 case 6:
198 state.R1 -= 1; state.S1 += 1;
199 break;
200 case 7:
201 state.R2 -= 1; state.S2 += 1;
202 break;
203 case 8:
205 break;
206 case 9:
208 break;
209 case 10:
210 sample(host1);
211 break;
212 case 11:
213 sample(host2);
214 break;
215 case 12:
216 state.S1 -= 1; state.I1 += 1; graft(outside); migrate(outside,host1);
217 break;
218 case 13:
219 state.S2 -= 1; state.I2 += 1; graft(outside); migrate(outside,host2);
220 break;
221 case 14:
222 state.S1 -= 1; state.N1 -= 1;
223 break;
224 case 15:
225 state.S2 -= 1; state.N2 -= 1;
226 break;
227 case 16:
228 state.I1 -= 1; state.N1 -= 1; migrate(host1,ghost1);
229 break;
230 case 17:
231 state.I2 -= 1; state.N2 -= 1; migrate(host2,ghost2);
232 break;
233 case 18:
234 state.R1 -= 1; state.N1 -= 1;
235 break;
236 case 19:
237 state.R2 -= 1; state.N2 -= 1;
238 break;
239 case 20:
240 state.S1 += 1; state.N1 += 1;
241 break;
242 case 21:
243 state.S2 += 1; state.N2 += 1;
244 break;
245 default: // #nocov
246 assert(0); // #nocov
247 break; // #nocov
248 }
249}
250
Encodes the master process.
Definition master.h:22
void sample_migrate(name_t i=0, name_t j=0)
sample_migrate in deme i to deme j
Definition master.h:192
void birth(name_t i=0, name_t j=0, int n=1)
n births into deme j with parent in deme i
Definition master.h:142
void sample(name_t i=0, int n=1)
sample in deme i
Definition master.h:166
void graft(name_t i=0, int m=1)
new root in deme i
Definition master.h:159
void migrate(name_t i=0, name_t j=0)
migration from deme i to deme j
Definition master.h:185
Population process class.
Definition popul_proc.h:20
#define GENERICS(X, TYPE)
Definition generics.h:149
#define err(...)
Definition internal.h:18
#define n
Definition lbdp_pomp.c:8
#define YAML_PARAM(X)
Definition popul_proc.h:190
#define RATE_CALC(X)
Definition popul_proc.h:189
#define YAML_STATE(X)
Definition popul_proc.h:191
#define PARAM_SET(X)
Definition popul_proc.h:187
static int outside
Definition s2i2r2.cc:9
TwoUndead process parameters.
Definition twoundead.cc:26
TwoUndead process state.
Definition twoundead.cc:14
#define I2_0
#define psi1
#define S2_0
#define d1
#define Beta21
#define Beta12
#define S1_0
#define b1
#define Beta22
#define S1
#define R2_0
#define R2
#define R1
#define I2
#define host1
#define R1_0
#define Beta11
#define I1_0
#define N1
#define omega2
#define host2
#define gamma1
#define N2
#define b2
#define S2
#define psi2
#define d2
#define I1
#define gamma2
#define omega1
static int ghost2
Definition twoundead.cc:10
master_t< twoundead_proc_t, 5 > twoundead_genealogy_t
Definition twoundead.cc:54
static int ghost1
Definition twoundead.cc:9
popul_proc_t< twoundead_state_t, twoundead_parameters_t, 22 > twoundead_proc_t
Definition twoundead.cc:53