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

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();
77 event = 0;
78 };
Population process class.
Definition popul_proc.h:20
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

◆ 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

◆ 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 };

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()

template<class STATE, class PARAMETERS, size_t NEVENT, size_t NDEME = 1>
double popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::event_rates ( double * rate,
int n ) const

compute event rates

Here is the caller graph for this function:

◆ jump()

◆ 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 };

◆ 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);
168 count++;
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
#define err(...)
Definition internal.h:18

◆ rinit()

◆ 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];
141 if (total_rate > 0) {
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
152 u -= rate[event];
153 event++;
154 }
156 };
static const size_t nevent
Definition popul_proc.h:26
double event_rates(double *rate, int n) const
compute event rates
Here is the caller graph for this function:

◆ update_IVPs()

template<class STATE, class PARAMETERS, size_t NEVENT, size_t NDEME = 1>
void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::update_IVPs ( double * ,
int  )

set initial-value parameters

◆ update_params()

template<class STATE, class PARAMETERS, size_t NEVENT, size_t NDEME = 1>
void popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::update_params ( double * ,
int  )

set parameters

◆ 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()

template<class STATE, class PARAMETERS, size_t NEVENT, size_t NDEME = 1>
std::string popul_proc_t< STATE, PARAMETERS, NEVENT, NDEME >::yaml ( std::string tab) const

machine/human readable info

Friends And Related Symbol 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 };
parameters_t params
Definition popul_proc.h:35
state_t state
Definition popul_proc.h:34

◆ 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 file: