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
7static int deme = 0;
8
10typedef struct {
11 int m;
12 int g;
14
16typedef struct {
17 double mu;
18 double psi;
19 int n;
21
24
25template<>
26std::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)
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
38template<>
39void moran_proc_t::update_params (double *p, int n) {
40 int m = 0;
43 if (m != n) err("wrong number of parameters!");
44}
45
46template<>
47void 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
53template<>
54double 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
63template<>
65 state.m = state.g = 0;
66 graft(deme,params.n);
67}
68
69template<>
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 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 moran.cc:54
std::string yaml(std::string tab) const
Definition moran.cc:26
#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 n
Definition lbdp_pomp.c:8
#define psi
Definition lbdp_pomp.c:6
master_t< moran_proc_t, 1 > moran_genealogy_t
Definition moran.cc:23
popul_proc_t< moran_state_t, moran_parameters_t, 2 > moran_proc_t
Definition moran.cc:22
#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