pomp
Inference for partially observed Markov processes
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pomp.h File Reference
#include <R.h>
#include <Rmath.h>
#include <Rdefines.h>
Include dependency graph for pomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define err(...)   Rf_errorcall(R_NilValue,__VA_ARGS__)
 
#define warn(...)   Rf_warningcall(R_NilValue,__VA_ARGS__)
 

Typedefs

typedef void bspline_basis_eval_deriv_t(double x, double *knots, int degree, int nbasis, int deriv, double *y)
 
typedef void periodic_bspline_basis_eval_deriv_t(double x, double period, int degree, int nbasis, int deriv, double *y)
 
typedef const SEXP get_userdata_t(const char *name)
 
typedef const int * get_userdata_int_t(const char *name)
 
typedef const double * get_userdata_double_t(const char *name)
 
typedef void pomp_rinit(double *x, const double *p, double t0, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
 
typedef void pomp_dinit(double *lik, const double *x, const double *p, double t0, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
 
typedef double pomp_ssa_rate_fn(int event, double t, const double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
 
typedef void pomp_onestep_sim(double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t, double dt)
 
typedef void pomp_dprocess(double *loglik, const double *x1, const double *x2, double t1, double t2, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
 
typedef void pomp_skeleton(double *f, const double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)
 
typedef void pomp_rmeasure(double *y, const double *x, const double *p, const int *obsindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)
 
typedef void pomp_dmeasure(double *lik, const double *y, const double *x, const double *p, int give_log, const int *obsindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)
 
typedef void pomp_emeasure(double *f, const double *x, const double *p, const int *obsindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)
 
typedef void pomp_vmeasure(double *f, const double *x, const double *p, const int *vmatindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)
 
typedef void pomp_rprior(double *p, const int *parindex)
 
typedef void pomp_dprior(double *lik, const double *p, int give_log, const int *parindex)
 
typedef void pomp_transform(double *pt, const double *p, const int *parindex)
 

Functions

static R_INLINE double logit (double p)
 
static R_INLINE double expit (double x)
 
static R_INLINE double rgammawn (double sigma, double dt)
 
static R_INLINE void reulermultinom (int m, double size, const double *rate, double dt, double *trans)
 
static R_INLINE double deulermultinom (int m, double size, const double *rate, double dt, double *trans, int give_log)
 
static R_INLINE double dmultinom (int m, const double *prob, double *x, int give_log)
 
static R_INLINE void to_log_barycentric (double *xt, const double *x, int n)
 
static R_INLINE void from_log_barycentric (double *xt, const double *x, int n)
 
static R_INLINE double dot_product (int n, const double *x, const double *y)
 
static R_INLINE double exp2geom_rate_correction (double R, double dt)
 
static R_INLINE double rbetabinom (double size, double prob, double theta)
 
static R_INLINE double dbetabinom (double x, double size, double prob, double theta, int give_log)
 
static R_INLINE double rbetanbinom (double mu, double size, double theta)
 
static R_INLINE double dbetanbinom (double x, double mu, double size, double theta, int give_log)
 

Macro Definition Documentation

◆ err

#define err (   ...)    Rf_errorcall(R_NilValue,__VA_ARGS__)

Definition at line 21 of file pomp.h.

◆ warn

#define warn (   ...)    Rf_warningcall(R_NilValue,__VA_ARGS__)

Definition at line 22 of file pomp.h.

Typedef Documentation

◆ bspline_basis_eval_deriv_t

typedef void bspline_basis_eval_deriv_t(double x, double *knots, int degree, int nbasis, int deriv, double *y)

Definition at line 25 of file pomp.h.

◆ get_userdata_double_t

typedef const double* get_userdata_double_t(const char *name)

Definition at line 36 of file pomp.h.

◆ get_userdata_int_t

typedef const int* get_userdata_int_t(const char *name)

Definition at line 35 of file pomp.h.

◆ get_userdata_t

typedef const SEXP get_userdata_t(const char *name)

Definition at line 34 of file pomp.h.

◆ periodic_bspline_basis_eval_deriv_t

typedef void periodic_bspline_basis_eval_deriv_t(double x, double period, int degree, int nbasis, int deriv, double *y)

Definition at line 30 of file pomp.h.

◆ pomp_dinit

typedef void pomp_dinit(double *lik, const double *x, const double *p, double t0, const int *stateindex, const int *parindex, const int *covindex, const double *covars)

Definition at line 45 of file pomp.h.

◆ pomp_dmeasure

typedef void pomp_dmeasure(double *lik, const double *y, const double *x, const double *p, int give_log, const int *obsindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)

Definition at line 85 of file pomp.h.

◆ pomp_dprior

typedef void pomp_dprior(double *lik, const double *p, int give_log, const int *parindex)

Definition at line 110 of file pomp.h.

◆ pomp_dprocess

typedef void pomp_dprocess(double *loglik, const double *x1, const double *x2, double t1, double t2, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)

Definition at line 65 of file pomp.h.

◆ pomp_emeasure

typedef void pomp_emeasure(double *f, const double *x, const double *p, const int *obsindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)

Definition at line 92 of file pomp.h.

◆ pomp_onestep_sim

typedef void pomp_onestep_sim(double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t, double dt)

Definition at line 58 of file pomp.h.

◆ pomp_rinit

typedef void pomp_rinit(double *x, const double *p, double t0, const int *stateindex, const int *parindex, const int *covindex, const double *covars)

Definition at line 39 of file pomp.h.

◆ pomp_rmeasure

typedef void pomp_rmeasure(double *y, const double *x, const double *p, const int *obsindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)

Definition at line 78 of file pomp.h.

◆ pomp_rprior

typedef void pomp_rprior(double *p, const int *parindex)

Definition at line 106 of file pomp.h.

◆ pomp_skeleton

typedef void pomp_skeleton(double *f, const double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)

Definition at line 72 of file pomp.h.

◆ pomp_ssa_rate_fn

typedef double pomp_ssa_rate_fn(int event, double t, const double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)

Definition at line 51 of file pomp.h.

◆ pomp_transform

typedef void pomp_transform(double *pt, const double *p, const int *parindex)

Definition at line 114 of file pomp.h.

◆ pomp_vmeasure

typedef void pomp_vmeasure(double *f, const double *x, const double *p, const int *vmatindex, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t)

Definition at line 99 of file pomp.h.

Function Documentation

◆ dbetabinom()

static R_INLINE double dbetabinom ( double  x,
double  size,
double  prob,
double  theta,
int  give_log 
)
static

Definition at line 292 of file pomp.h.

294 {
295  double a = theta*prob;
296  double b = theta*(1.0-prob);
297  double f = lchoose(size,x)-lbeta(a,b)+lbeta(a+x,b+size-x);
298  return (give_log) ? f : exp(f);
299 }
Here is the caller graph for this function:

◆ dbetanbinom()

static R_INLINE double dbetanbinom ( double  x,
double  mu,
double  size,
double  theta,
int  give_log 
)
static

Definition at line 310 of file pomp.h.

312 {
313  double p = size/(size+mu);
314  double a = theta*p;
315  double b = theta*(1.0-p);
316  double f = lchoose(size+x-1,size-1)-lbeta(a,b)+lbeta(a+size,b+x);
317  return (give_log) ? f : exp(f);
318 }

◆ deulermultinom()

static R_INLINE double deulermultinom ( int  m,
double  size,
const double *  rate,
double  dt,
double *  trans,
int  give_log 
)
static

Definition at line 172 of file pomp.h.

174 {
175  double p = 0.0;
176  double n = 0.0;
177  double ff = 0.0;
178  int k;
179  if ((dt < 0.0) || (size < 0.0) || (floor(size+0.5) != size)) {
180  warn("in 'deulermultinom': NaNs produced.");
181  return R_NaN;
182  }
183  for (k = 0; k < m; k++) {
184  if (rate[k] < 0.0) {
185  warn("in 'deulermultinom': NaNs produced.");
186  return R_NaN;
187  }
188  if (trans[k] < 0.0) {
189  ff = (give_log) ? R_NegInf: 0.0;
190  return ff;
191  }
192  p += rate[k]; // total event rate
193  n += trans[k]; // total number of events
194  }
195  if (n > size) {
196  ff = (give_log) ? R_NegInf: 0.0;
197  return ff;
198  }
199  ff = dbinom(n,size,1-exp(-p*dt),1); // total number of events
200  m -= 1;
201  for (k = 0; k < m; k++) {
202  if ((n > 0) && (p > 0)) {
203  if (rate[k] > p) p = rate[k];
204  ff += dbinom(trans[k],n,rate[k]/p,1);
205  }
206  n -= trans[k];
207  p -= rate[k];
208  }
209  ff = (give_log) ? ff : exp(ff);
210  return ff;
211 }
#define warn(...)
Definition: pomp.h:22
Here is the caller graph for this function:

◆ dmultinom()

static R_INLINE double dmultinom ( int  m,
const double *  prob,
double *  x,
int  give_log 
)
static

Definition at line 214 of file pomp.h.

216 {
217  double p = 0.0;
218  double n = 0.0;
219  double ff = 0.0;
220  int k;
221  for (k = 0; k < m; k++) {
222  if (prob[k] < 0.0) {
223  warn("in 'dmultinom': NaNs produced.");
224  return R_NaN;
225  }
226  if ((x[k] < 0.0) || (floor(x[k]+0.5) != x[k])) {
227  ff = (give_log) ? R_NegInf: 0.0;
228  return ff;
229  }
230  p += prob[k]; // sum of probabilities
231  n += x[k]; // total number of events
232  }
233  for (k = 0; k < m; k++) {
234  if ((n > 0) && (p > 0)) {
235  if (prob[k] > p) p = prob[k];
236  ff += dbinom(x[k],n,prob[k]/p,1);
237  } else if (x[k] < 0.0) {
238  ff = R_NegInf;
239  return ff;
240  }
241  n -= x[k];
242  p -= prob[k];
243  }
244  ff = (give_log) ? ff : exp(ff);
245  return ff;
246 }

◆ dot_product()

static R_INLINE double dot_product ( int  n,
const double *  x,
const double *  y 
)
static

Definition at line 269 of file pomp.h.

271 {
272  double p = 0.0;
273  for (int j = 0; j < n; j++) p += x[j]*y[j];
274  return p;
275 }

◆ exp2geom_rate_correction()

static R_INLINE double exp2geom_rate_correction ( double  R,
double  dt 
)
static

Definition at line 278 of file pomp.h.

280 {
281  return (dt > 0) ? log1p(R*dt)/dt : R;
282 }
#define R
Definition: gompertz.c:8

◆ expit()

static R_INLINE double expit ( double  x)
static

Definition at line 123 of file pomp.h.

123  {
124  return 1.0/(1.0+exp(-x));
125 }

◆ from_log_barycentric()

static R_INLINE void from_log_barycentric ( double *  xt,
const double *  x,
int  n 
)
static

Definition at line 259 of file pomp.h.

261 {
262  double sum;
263  int i;
264  for (i = 0, sum = 0.0; i < n; i++) sum += (xt[i] = exp(x[i]));
265  for (i = 0; i < n; i++) xt[i] /= sum;
266 }
Here is the caller graph for this function:

◆ logit()

static R_INLINE double logit ( double  p)
static

Definition at line 118 of file pomp.h.

118  {
119  return log(p/(1.0-p));
120 }
Here is the caller graph for this function:

◆ rbetabinom()

static R_INLINE double rbetabinom ( double  size,
double  prob,
double  theta 
)
static

Definition at line 285 of file pomp.h.

287 {
288  return rbinom(size,rbeta(prob*theta,(1.0-prob)*theta));
289 }
Here is the caller graph for this function:

◆ rbetanbinom()

static R_INLINE double rbetanbinom ( double  mu,
double  size,
double  theta 
)
static

Definition at line 302 of file pomp.h.

304 {
305  double p = size/(size+mu);
306  return rnbinom(size,rbeta(p*theta,(1.0-p)*theta));
307 }

◆ reulermultinom()

static R_INLINE void reulermultinom ( int  m,
double  size,
const double *  rate,
double  dt,
double *  trans 
)
static

Definition at line 137 of file pomp.h.

139 {
140  double p = 0.0;
141  int j, k;
142  if ( !R_FINITE(size) || size < 0.0 || floor(size+0.5) != size ||
143  !R_FINITE(dt) || dt < 0.0) {
144  for (k = 0; k < m; k++) trans[k] = R_NaReal;
145  warn("in 'reulermultinom': NAs produced.");
146  return;
147  }
148  for (k = 0; k < m; k++) {
149  if (!R_FINITE(rate[k]) || rate[k] < 0.0) {
150  for (j = 0; j < m; j++) trans[j] = R_NaReal;
151  warn("in 'reulermultinom': NAs produced.");
152  return;
153  }
154  p += rate[k]; // total event rate
155  }
156  if (p > 0.0) {
157  size = rbinom(size,1-exp(-p*dt)); // total number of events
158  m -= 1;
159  for (k = 0; k < m; k++) {
160  if (rate[k] > p) p = rate[k];
161  trans[k] = ((size > 0) && (p > 0)) ? rbinom(size,rate[k]/p) : 0;
162  size -= trans[k];
163  p -= rate[k];
164  }
165  trans[m] = size;
166  } else {
167  for (k = 0; k < m; k++) trans[k] = 0.0;
168  }
169 }
Here is the caller graph for this function:

◆ rgammawn()

static R_INLINE double rgammawn ( double  sigma,
double  dt 
)
static

Definition at line 128 of file pomp.h.

130 {
131  double sigmasq;
132  sigmasq = sigma*sigma;
133  return (sigmasq > 0) ? rgamma(dt/sigmasq,sigmasq) : dt;
134 }
#define sigma
Definition: gompertz.c:93
Here is the caller graph for this function:

◆ to_log_barycentric()

static R_INLINE void to_log_barycentric ( double *  xt,
const double *  x,
int  n 
)
static

Definition at line 249 of file pomp.h.

251 {
252  double sum;
253  int i;
254  for (i = 0, sum = 0.0; i < n; i++) sum += x[i];
255  for (i = 0; i < n; i++) xt[i] = log(x[i]/sum);
256 }
Here is the caller graph for this function: