phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lbdp.cc
Go to the documentation of this file.
1 // LBDP: Linear birth-death-sampling model (C++)
2 #include "master.h"
3 #include "popul_proc.h"
4 #include "generics.h"
5 #include "internal.h"
6 
7 static int deme = 0;
8 
10 typedef struct {
11  int n;
12 } lbdp_state_t;
13 
15 typedef struct {
16  double lambda;
17  double mu;
18  double psi;
19  int n0;
21 
24 
25 template<>
26 std::string lbdp_proc_t::yaml (std::string tab) const {
27  std::string t = tab + " ";
28  std::string p = tab + "parameter:\n"
30  + YAML_PARAM(mu)
31  + YAML_PARAM(psi)
32  + YAML_PARAM(n0);
33  std::string s = tab + "state:\n"
34  + YAML_STATE(n);
35  return p+s;
36 }
37 
38 template<>
39 void lbdp_proc_t::update_params (double *p, int n) {
40  int m = 0;
42  PARAM_SET(mu);
43  PARAM_SET(psi);
44  if (m != n) err("wrong number of parameters!");
45 }
46 
47 template<>
48 void lbdp_proc_t::update_IVPs (double *p, int n) {
49  int m = 0;
50  PARAM_SET(n0);
51  if (m != n) err("wrong number of initial-value parameters!");
52 }
53 
54 template<>
55 double lbdp_proc_t::event_rates (double *rate, int n) const {
56  int m = 0;
57  double total = 0;
58  RATE_CALC(params.lambda * state.n);
59  RATE_CALC(params.mu * state.n);
60  RATE_CALC(params.psi * state.n);
61  if (m != n) err("wrong number of events!");
62  return total;
63 }
64 
65 template<>
67  state.n = params.n0;
68  graft(deme,params.n0);
69 }
70 
71 template<>
72 void lbdp_genealogy_t::jump (int event) {
73  switch (event) {
74  case 0:
75  state.n += 1; birth();
76  break;
77  case 1:
78  state.n -= 1; death();
79  break;
80  case 2:
81  sample();
82  break;
83  default: // #nocov
84  assert(0); // #nocov
85  break; // #nocov
86  }
87 }
88 
Encodes the master process.
Definition: master.h:22
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 death(name_t i=0)
death in deme i
Definition: master.h:153
void jump(int e)
makes a jump
Definition: lbdp.cc:72
void rinit(void)
initialize the state
Definition: lbdp.cc:66
void graft(name_t i=0, int m=1)
new root in deme i
Definition: master.h:159
Population process class.
Definition: popul_proc.h:20
void update_IVPs(double *, int)
set initial-value parameters
Definition: lbdp.cc:48
void update_params(double *, int)
set parameters
Definition: lbdp.cc:39
std::string yaml(std::string tab) const
machine/human readable info
Definition: lbdp.cc:26
parameters_t params
Definition: popul_proc.h:35
double event_rates(double *rate, int n) const
compute event rates
Definition: lbdp.cc:55
state_t state
Definition: popul_proc.h:34
#define GENERICS(X, TYPE)
Definition: generics.h:149
#define err(...)
Definition: internal.h:18
static int deme
Definition: lbdp.cc:7
#define mu
Definition: lbdp_pomp.c:5
#define n0
Definition: lbdp_pomp.c:7
#define n
Definition: lbdp_pomp.c:8
#define lambda
Definition: lbdp_pomp.c:4
#define psi
Definition: lbdp_pomp.c:6
#define YAML_PARAM(X)
Definition: popul_proc.h:180
#define RATE_CALC(X)
Definition: popul_proc.h:179
#define YAML_STATE(X)
Definition: popul_proc.h:181
#define PARAM_SET(X)
Definition: popul_proc.h:177
LBDP process parameters.
Definition: lbdp.cc:15
double mu
Definition: lbdp.cc:17
double lambda
Definition: lbdp.cc:16
double psi
Definition: lbdp.cc:18
LBDP process state.
Definition: lbdp.cc:10
int n
Definition: lbdp.cc:11