phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > Class Template Referenceabstract

Population process class. More...

#include <popul_proc.h>

Public Member Functions

size_t bytesize (void) const
 size of serialized binary form More...
 
 popul_proc_t (double t0=0)
 
 popul_proc_t (raw_t *o)
 constructor from serialized binary form More...
 
 popul_proc_t (const popul_proc_t &X)
 copy constructor More...
 
popul_proc_toperator= (const popul_proc_t &X)
 copy assignment operator More...
 
 popul_proc_t (popul_proc_t &&)=delete
 move constructor More...
 
popul_proc_toperator= (popul_proc_t &&)=delete
 move assignment operator More...
 
 ~popul_proc_t (void)
 destructor More...
 
slate_t time (void) const
 get current time. More...
 
virtual void valid (void) const
 
void update_params (double *, int)
 set parameters More...
 
void update_IVPs (double *, int)
 set initial-value parameters More...
 
double event_rates (double *rate, int n) const
 compute event rates More...
 
virtual void rinit (void)=0
 initialize the state More...
 
virtual void jump (int e)=0
 makes a jump More...
 
std::string yaml (std::string tab) const
 machine/human readable info More...
 
void update_clocks (void)
 updates clock and next event More...
 
int play (double tfin)
 

Protected Types

typedef STATE state_t
 
typedef PARAMETERS parameters_t
 

Protected Attributes

slate_t next
 
size_t event
 
slate_t current
 
state_t state
 
parameters_t params
 

Static Protected Attributes

static const size_t nevent = NEVENT
 
static const size_t ndeme = NDEME
 

Private Member Functions

void clean (void)
 

Friends

raw_toperator>> (const popul_proc_t &X, raw_t *o)
 binary serialization More...
 
raw_toperator>> (raw_t *o, popul_proc_t &X)
 binary deserialization More...
 

Detailed Description

template<class STATE, class PARAMETERS, size_t NEVENT, size_t NDEME = 1>
class popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >

Population process class.

The class for the simulation of the Markov process.

  • STATE is a datatype that holds the state of the Markov process.
  • PARAMETERS is a datatype for the model parameters
  • NEVENT is the number of event-types
  • NDEME is the number of demes

Definition at line 20 of file popul_proc.h.

Member Typedef Documentation

◆ parameters_t

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
typedef PARAMETERS popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::parameters_t
protected

Definition at line 25 of file popul_proc.h.

◆ state_t

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
typedef STATE popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::state_t
protected

Definition at line 24 of file popul_proc.h.

Constructor & Destructor Documentation

◆ popul_proc_t() [1/4]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::popul_proc_t ( double  t0 = 0)
inline

basic constructor for popul_proc class t0 = initial time

Definition at line 74 of file popul_proc.h.

74  {
75  clean();
76  next = current = slate_t(t0);
77  event = 0;
78  };
slate_t current
Definition: popul_proc.h:33
void clean(void)
Definition: popul_proc.h:39
slate_t next
Definition: popul_proc.h:31
double slate_t
Definition: internal.h:44
Here is the call graph for this function:

◆ popul_proc_t() [2/4]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::popul_proc_t ( raw_t o)
inline

constructor from serialized binary form

Definition at line 80 of file popul_proc.h.

80  {
81  o >> *this;
82  };

◆ popul_proc_t() [3/4]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::popul_proc_t ( const popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > &  X)
inline

copy constructor

Definition at line 84 of file popul_proc.h.

84  {
85  raw_t *o = new raw_t[X.bytesize()];
86  X >> o;
87  o >> *this;
88  delete[] o;
89  };
size_t bytesize(void) const
size of serialized binary form
Definition: popul_proc.h:45
Rbyte raw_t
Definition: internal.h:43
Here is the call graph for this function:

◆ popul_proc_t() [4/4]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::popul_proc_t ( popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > &&  )
delete

move constructor

◆ ~popul_proc_t()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::~popul_proc_t ( void  )
inline

destructor

Definition at line 104 of file popul_proc.h.

104  {
105  clean();
106  };
Here is the call graph for this function:

Member Function Documentation

◆ bytesize()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
size_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::bytesize ( void  ) const
inline

size of serialized binary form

Definition at line 45 of file popul_proc.h.

45  {
46  return 2*sizeof(slate_t) + sizeof(size_t)
47  + sizeof(state_t) + sizeof(parameters_t);
48  };
STATE state_t
Definition: popul_proc.h:24
PARAMETERS parameters_t
Definition: popul_proc.h:25
Here is the caller graph for this function:

◆ clean()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::clean ( void  )
inlineprivate

Definition at line 39 of file popul_proc.h.

39 {}; // memory cleanup
Here is the caller graph for this function:

◆ event_rates()

double twospecies_proc_t::event_rates ( double *  rate,
int  n 
) const

compute event rates

Definition at line 55 of file lbdp.cc.

55  {
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 }
parameters_t params
Definition: popul_proc.h:35
state_t state
Definition: popul_proc.h:34
#define err(...)
Definition: internal.h:18
#define n
Definition: lbdp_pomp.c:8
#define RATE_CALC(X)
Definition: popul_proc.h:179
Here is the caller graph for this function:

◆ jump()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
virtual void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::jump ( int  e)
pure virtual

makes a jump

Here is the caller graph for this function:

◆ operator=() [1/2]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t& popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::operator= ( const popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > &  X)
inline

copy assignment operator

Definition at line 91 of file popul_proc.h.

91  {
92  clean();
93  raw_t *o = new raw_t[X.bytesize()];
94  X >> o;
95  o >> *this;
96  delete[] o;
97  return *this;
98  };
Here is the call graph for this function:

◆ operator=() [2/2]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
popul_proc_t& popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::operator= ( popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > &&  )
delete

move assignment operator

◆ play()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
int popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::play ( double  tfin)
inline

run process to a specified time. return number of events that have occurred.

Definition at line 160 of file popul_proc.h.

160  {
161  int count = 0;
162  if (current > tfin)
163  err("cannot simulate backward! (current t=%lg, requested t=%lg)",current,tfin);
164  while (next < tfin) {
165  current = next;
166  jump(event);
167  update_clocks();
168  count++;
169  R_CheckUserInterrupt();
170  }
171  if (next > tfin) current = tfin; // relies on Markov property
172  return count;
173  };
void update_clocks(void)
updates clock and next event
Definition: popul_proc.h:138
virtual void jump(int e)=0
makes a jump
size_t event
Definition: popul_proc.h:32
Here is the call graph for this function:

◆ rinit()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
virtual void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::rinit ( void  )
pure virtual

initialize the state

◆ time()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
slate_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::time ( void  ) const
inline

get current time.

Definition at line 112 of file popul_proc.h.

112  {
113  return current;
114  };

◆ update_clocks()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::update_clocks ( void  )
inline

updates clock and next event

Definition at line 138 of file popul_proc.h.

138  {
139  double rate[nevent];
140  double total_rate = event_rates(rate,nevent);
141  if (total_rate > 0) {
142  next = current+rexp(1/total_rate);
143  } else {
144  next = R_PosInf;
145  }
146  double u = runif(0,total_rate);
147  event = 0;
148  while (u > rate[event] && event < nevent) {
149  if (rate[event] < 0)
150  err("in '%s' (%s line %d): invalid negative rate[%zd]=%lg", // #nocov
151  __func__,__FILE__,__LINE__,event,rate[event]); // #nocov
152  u -= rate[event];
153  event++;
154  }
155  assert(event < nevent);
156  };
static const size_t nevent
Definition: popul_proc.h:26
double event_rates(double *rate, int n) const
compute event rates
Definition: lbdp.cc:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_IVPs()

void twospecies_proc_t::update_IVPs ( double *  p,
int  n 
)

set initial-value parameters

Definition at line 48 of file lbdp.cc.

48  {
49  int m = 0;
50  PARAM_SET(n0);
51  if (m != n) err("wrong number of initial-value parameters!");
52 }
#define n0
Definition: lbdp_pomp.c:7
#define PARAM_SET(X)
Definition: popul_proc.h:177

◆ update_params()

void twospecies_proc_t::update_params ( double *  p,
int  n 
)

set parameters

Definition at line 39 of file lbdp.cc.

39  {
40  int m = 0;
42  PARAM_SET(mu);
43  PARAM_SET(psi);
44  if (m != n) err("wrong number of parameters!");
45 }
#define mu
Definition: lbdp_pomp.c:5
#define lambda
Definition: lbdp_pomp.c:4
#define psi
Definition: lbdp_pomp.c:6

◆ valid()

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
virtual void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::valid ( void  ) const
inlinevirtual

Definition at line 118 of file popul_proc.h.

118 {};

◆ yaml()

std::string twospecies_proc_t::yaml ( std::string  tab) const

machine/human readable info

Definition at line 26 of file lbdp.cc.

26  {
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 }
#define YAML_PARAM(X)
Definition: popul_proc.h:180
#define YAML_STATE(X)
Definition: popul_proc.h:181

Friends And Related Function Documentation

◆ operator>> [1/2]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
raw_t* operator>> ( const popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > &  X,
raw_t o 
)
friend

binary serialization

Definition at line 50 of file popul_proc.h.

50  {
51  slate_t A[2]; A[0] = X.current; A[1] = X.next;
52  memcpy(o,A,sizeof(A)); o += sizeof(A);
53  memcpy(o,&X.event,sizeof(size_t)); o += sizeof(size_t);
54  memcpy(o,&X.state,sizeof(state_t)); o += sizeof(state_t);
55  memcpy(o,&X.params,sizeof(parameters_t)); o += sizeof(parameters_t);
56  return o;
57  };

◆ operator>> [2/2]

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
raw_t* operator>> ( raw_t o,
popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME > &  X 
)
friend

binary deserialization

Definition at line 59 of file popul_proc.h.

59  {
60  X.clean();
61  slate_t A[2];
62  memcpy(A,o,sizeof(A)); o += sizeof(A);
63  X.current = A[0]; X.next = A[1];
64  memcpy(&X.event,o,sizeof(size_t)); o += sizeof(size_t);
65  memcpy(&X.state,o,sizeof(state_t)); o += sizeof(state_t);
66  memcpy(&X.params,o,sizeof(parameters_t)); o += sizeof(parameters_t);
67  return o;
68  };

Field Documentation

◆ current

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
slate_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::current
protected

Definition at line 33 of file popul_proc.h.

◆ event

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
size_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::event
protected

Definition at line 32 of file popul_proc.h.

◆ ndeme

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
const size_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::ndeme = NDEME
staticprotected

Definition at line 27 of file popul_proc.h.

◆ nevent

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
const size_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::nevent = NEVENT
staticprotected

Definition at line 26 of file popul_proc.h.

◆ next

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
slate_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::next
protected

Definition at line 31 of file popul_proc.h.

◆ params

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
parameters_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::params
protected

Definition at line 35 of file popul_proc.h.

◆ state

template<class STATE , class PARAMETERS , size_t NEVENT, size_t NDEME = 1>
state_t popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::state
protected

Definition at line 34 of file popul_proc.h.


The documentation for this class was generated from the following files: