phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
moran.cc
Go to the documentation of this file.
1 // Moran: The classical Moran 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 m;
12  int g;
14 
16 typedef struct {
17  double mu;
18  double psi;
19  int n;
21 
24 
25 template<>
26 std::string moran_proc_t::yaml (std::string tab) const {
27  std::string t = tab + " ";
28  std::string p = tab + "parameter:\n"
29  + YAML_PARAM(mu)
30  + YAML_PARAM(psi)
31  + YAML_PARAM(n);
32  std::string s = tab + "state:\n"
33  + YAML_STATE(m)
34  + YAML_STATE(g);
35  return p+s;
36 }
37 
38 template<>
39 void moran_proc_t::update_params (double *p, int n) {
40  int m = 0;
41  PARAM_SET(mu);
42  PARAM_SET(psi);
43  if (m != n) err("wrong number of parameters!");
44 }
45 
46 template<>
47 void moran_proc_t::update_IVPs (double *p, int n) {
48  int m = 0;
49  PARAM_SET(n);
50  if (m != n) err("wrong number of initial-value parameters!");
51 }
52 
53 template<>
54 double moran_proc_t::event_rates (double *rate, int n) const {
55  int m = 0;
56  double total = 0;
57  RATE_CALC(params.mu * params.n);
58  RATE_CALC(params.psi * params.n);
59  if (m != n) err("wrong number of events!");
60  return total;
61 }
62 
63 template<>
64 void moran_genealogy_t::rinit (void) {
65  state.m = state.g = 0;
66  graft(deme,params.n);
67 }
68 
69 template<>
70 void moran_genealogy_t::jump (int event) {
71  switch (event) {
72  case 0:
73  state.m += 1; birth(); death();
74  break;
75  case 1:
76  state.g += 1; sample();
77  break;
78  default: // #nocov
79  assert(0); // #nocov
80  break; // #nocov
81  }
82 }
83 
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
#define GENERICS(X, TYPE)
Definition: generics.h:149
#define err(...)
Definition: internal.h:18
#define mu
Definition: lbdp_pomp.c:5
#define n
Definition: lbdp_pomp.c:8
#define psi
Definition: lbdp_pomp.c:6
static int deme
Definition: moran.cc:7
#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
Moran process parameters.
Definition: moran.cc:16
Moran process state.
Definition: moran.cc:10