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
7static int deme = 0;
8
10typedef struct {
11 int n;
13
15typedef struct {
16 double lambda;
17 double mu;
18 double psi;
19 int n0;
21
24
25template<>
26std::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)
32 + YAML_PARAM(n0);
33 std::string s = tab + "state:\n"
34 + YAML_STATE(n);
35 return p+s;
36}
37
38template<>
39void lbdp_proc_t::update_params (double *p, int n) {
40 int m = 0;
44 if (m != n) err("wrong number of parameters!");
45}
46
47template<>
48void lbdp_proc_t::update_IVPs (double *p, int n) {
49 int m = 0;
51 if (m != n) err("wrong number of initial-value parameters!");
52}
53
54template<>
55double 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
65template<>
67 state.n = params.n0;
68 graft(deme,params.n0);
69}
70
71template<>
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 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
double event_rates(double *rate, int n) const
Definition lbdp.cc:55
std::string yaml(std::string tab) const
Definition lbdp.cc:26
#define GENERICS(X, TYPE)
Definition generics.h:149
#define err(...)
Definition internal.h:18
popul_proc_t< lbdp_state_t, lbdp_parameters_t, 3 > lbdp_proc_t
Definition lbdp.cc:22
master_t< lbdp_proc_t, 1 > lbdp_genealogy_t
Definition lbdp.cc:23
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 lambda
Definition lbdp.cc:16
LBDP process state.
Definition lbdp.cc:10