phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
popul_proc_t< STATE, PARAMETERS, NEVENT > 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
 
virtual void rinit (void)=0
 initialize the state
 
virtual void jump (int e)=0
 makes a jump
 
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
 
string_t yaml (string_t 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
 

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>
class popul_proc_t< STATE, PARAMETERS, NEVENT >

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

Definition at line 16 of file popul_proc.h.

Member Typedef Documentation

◆ parameters_t

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

Definition at line 21 of file popul_proc.h.

◆ state_t

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

Definition at line 20 of file popul_proc.h.

Constructor & Destructor Documentation

◆ popul_proc_t() [1/4]

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

basic constructor for popul_proc class t0 = initial time

Definition at line 69 of file popul_proc.h.

69 {
70 clean();
72 event = 0;
73 };
Population process class.
Definition popul_proc.h:16
void clean(void)
Definition popul_proc.h:34
slate_t current
Definition popul_proc.h:28
slate_t next
Definition popul_proc.h:26
double slate_t
Definition internal.h:53

◆ popul_proc_t() [2/4]

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

constructor from serialized binary form

Definition at line 75 of file popul_proc.h.

75 {
76 o >> *this;
77 };

◆ popul_proc_t() [3/4]

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

copy constructor

Definition at line 79 of file popul_proc.h.

79 {
80 raw_t *o = new raw_t[X.bytesize()];
81 X >> o;
82 o >> *this;
83 delete[] o;
84 };
size_t bytesize(void) const
size of serialized binary form
Definition popul_proc.h:40

◆ popul_proc_t() [4/4]

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

move constructor

◆ ~popul_proc_t()

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

destructor

Definition at line 99 of file popul_proc.h.

99 {
100 clean();
101 };

Member Function Documentation

◆ bytesize()

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

size of serialized binary form

Definition at line 40 of file popul_proc.h.

40 {
41 return 2*sizeof(slate_t) + sizeof(size_t)
42 + sizeof(state_t) + sizeof(parameters_t);
43 };
PARAMETERS parameters_t
Definition popul_proc.h:21
STATE state_t
Definition popul_proc.h:20
Here is the caller graph for this function:

◆ clean()

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

Definition at line 34 of file popul_proc.h.

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

◆ event_rates()

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

compute event rates

◆ jump()

◆ operator=() [1/2]

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

copy assignment operator

Definition at line 86 of file popul_proc.h.

86 {
87 clean();
88 raw_t *o = new raw_t[X.bytesize()];
89 X >> o;
90 o >> *this;
91 delete[] o;
92 return *this;
93 };

◆ operator=() [2/2]

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

move assignment operator

◆ play()

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

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

Definition at line 172 of file popul_proc.h.

174{
175 int count = 0;
176 if (current > tfin)
177 err("cannot simulate backward! (current t=%lg, requested t=%lg)",current,tfin);
178 while (next < tfin) {
179 current = next;
180 jump(event);
182 count++;
184 }
185 if (next > tfin) current = tfin; // relies on Markov property
186 return count;
187}
virtual void jump(int e)=0
makes a jump
size_t event
Definition popul_proc.h:27
void update_clocks(void)
updates clock and next event
Definition popul_proc.h:142
#define err(...)
Definition internal.h:18
Here is the call graph for this function:

◆ rinit()

◆ time()

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

get current time.

Definition at line 107 of file popul_proc.h.

107 {
108 return current;
109 };

◆ update_clocks()

template<class STATE, class PARAMETERS, size_t NEVENT>
void popul_proc_t< STATE, PARAMETERS, NEVENT >::update_clocks ( void )

updates clock and next event

Definition at line 141 of file popul_proc.h.

143{
144 double rate[nevent];
146 if (R_FINITE(total_rate)) {
147 if (total_rate > 0) {
149 } else {
150 next = R_PosInf;
151 }
152 } else {
153 for (event = 0; event < nevent; event++) {
154 if (!R_FINITE(rate[event]))
155 Rprintf("in '%s': invalid event rate[%zd]=%lg\n",__func__,event,rate[event]);
156 }
157 err("in '%s': invalid total event rate=%lg", __func__,total_rate);
158 }
159 double u = runif(0,total_rate);
160 event = 0;
161 while (u > rate[event] && event < nevent) {
162 if (rate[event] < 0)
163 err("in '%s': negative rate[%zd]=%lg",__func__,event,rate[event]); // #nocov
164 u -= rate[event];
165 event++;
166 }
168}
static const size_t nevent
Definition popul_proc.h:22
double event_rates(double *rate, int n) const
compute event rates
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_IVPs()

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

set initial-value parameters

◆ update_params()

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

set parameters

◆ valid()

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

Definition at line 111 of file popul_proc.h.

111{};

◆ yaml()

template<class STATE, class PARAMETERS, size_t NEVENT>
string_t popul_proc_t< STATE, PARAMETERS, NEVENT >::yaml ( string_t tab) const

machine/human readable info

Friends And Related Symbol Documentation

◆ operator>> [1/2]

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

binary serialization

Definition at line 45 of file popul_proc.h.

45 {
46 slate_t A[2]; A[0] = X.current; A[1] = X.next;
47 memcpy(o,A,sizeof(A)); o += sizeof(A);
48 memcpy(o,&X.event,sizeof(size_t)); o += sizeof(size_t);
49 memcpy(o,&X.state,sizeof(state_t)); o += sizeof(state_t);
50 memcpy(o,&X.params,sizeof(parameters_t)); o += sizeof(parameters_t);
51 return o;
52 };
state_t state
Definition popul_proc.h:29
parameters_t params
Definition popul_proc.h:30

◆ operator>> [2/2]

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

binary deserialization

Definition at line 54 of file popul_proc.h.

54 {
55 X.clean();
56 slate_t A[2];
57 memcpy(A,o,sizeof(A)); o += sizeof(A);
58 X.current = A[0]; X.next = A[1];
59 memcpy(&X.event,o,sizeof(size_t)); o += sizeof(size_t);
60 memcpy(&X.state,o,sizeof(state_t)); o += sizeof(state_t);
61 memcpy(&X.params,o,sizeof(parameters_t)); o += sizeof(parameters_t);
62 return o;
63 };

Field Documentation

◆ current

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

Definition at line 28 of file popul_proc.h.

◆ event

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

Definition at line 27 of file popul_proc.h.

◆ nevent

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

Definition at line 22 of file popul_proc.h.

◆ next

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

Definition at line 26 of file popul_proc.h.

◆ params

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

Definition at line 30 of file popul_proc.h.

◆ state

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

Definition at line 29 of file popul_proc.h.


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