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 eeulermultinom (int m, double size, const double *rate, double dt, double *trans)
 
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 320 of file pomp.h.

322{
323 double a = theta*prob;
324 double b = theta*(1.0-prob);
325 double f = lchoose(size,x)-lbeta(a,b)+lbeta(a+x,b+size-x);
326 return (give_log) ? f : exp(f);
327}
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 338 of file pomp.h.

340{
341 double p = size/(size+mu);
342 double a = theta*p;
343 double b = theta*(1.0-p);
344 double f = lchoose(size+x-1,size-1)-lbeta(a,b)+lbeta(a+size,b+x);
345 return (give_log) ? f : exp(f);
346}

◆ deulermultinom()

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

Definition at line 200 of file pomp.h.

202{
203 double p = 0.0;
204 double n = 0.0;
205 double ff = 0.0;
206 int k;
207 if ((dt < 0.0) || (size < 0.0) || (floor(size+0.5) != size)) {
208 warn("in 'deulermultinom': NaNs produced.");
209 return R_NaN;
210 }
211 for (k = 0; k < m; k++) {
212 if (rate[k] < 0.0) {
213 warn("in 'deulermultinom': NaNs produced.");
214 return R_NaN;
215 }
216 if (trans[k] < 0.0) {
217 ff = (give_log) ? R_NegInf: 0.0;
218 return ff;
219 }
220 p += rate[k]; // total event rate
221 n += trans[k]; // total number of events
222 }
223 if (n > size) {
224 ff = (give_log) ? R_NegInf: 0.0;
225 return ff;
226 }
227 ff = dbinom(n,size,1-exp(-p*dt),1); // total number of events
228 m -= 1;
229 for (k = 0; k < m; k++) {
230 if ((n > 0) && (p > 0)) {
231 if (rate[k] > p) p = rate[k];
232 ff += dbinom(trans[k],n,rate[k]/p,1);
233 }
234 n -= trans[k];
235 p -= rate[k];
236 }
237 ff = (give_log) ? ff : exp(ff);
238 return ff;
239}
#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 242 of file pomp.h.

244{
245 double p = 0.0;
246 double n = 0.0;
247 double ff = 0.0;
248 int k;
249 for (k = 0; k < m; k++) {
250 if (prob[k] < 0.0) {
251 warn("in 'dmultinom': NaNs produced.");
252 return R_NaN;
253 }
254 if ((x[k] < 0.0) || (floor(x[k]+0.5) != x[k])) {
255 ff = (give_log) ? R_NegInf: 0.0;
256 return ff;
257 }
258 p += prob[k]; // sum of probabilities
259 n += x[k]; // total number of events
260 }
261 for (k = 0; k < m; k++) {
262 if ((n > 0) && (p > 0)) {
263 if (prob[k] > p) p = prob[k];
264 ff += dbinom(x[k],n,prob[k]/p,1);
265 } else if (x[k] < 0.0) {
266 ff = R_NegInf;
267 return ff;
268 }
269 n -= x[k];
270 p -= prob[k];
271 }
272 ff = (give_log) ? ff : exp(ff);
273 return ff;
274}

◆ dot_product()

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

Definition at line 297 of file pomp.h.

299{
300 double p = 0.0;
301 for (int j = 0; j < n; j++) p += x[j]*y[j];
302 return p;
303}

◆ eeulermultinom()

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

Definition at line 137 of file pomp.h.

139{
140 double lambda = 0.0;
141 int j, k;
142 if (!R_FINITE(size) || size < 0.0 || !R_FINITE(dt) || dt < 0.0) {
143 for (k = 0; k < m; k++) trans[k] = R_NaReal;
144 warn("in 'eeulermultinom': NAs produced.");
145 return;
146 }
147 for (k = 0; k < m; k++) {
148 if (!R_FINITE(rate[k]) || rate[k] < 0.0) {
149 for (j = 0; j < m; j++) trans[j] = R_NaReal;
150 warn("in 'eeulermultinom': NAs produced.");
151 return;
152 }
153 lambda += rate[k];
154 }
155 if (lambda > 0.0) {
156 size = size*(1-exp(-lambda*dt));
157 for (k = 0; k < m; k++)
158 trans[k] = size*rate[k]/lambda;
159 } else {
160 for (k = 0; k < m; k++) trans[k] = 0.0;
161 }
162}
Here is the caller graph for this function:

◆ exp2geom_rate_correction()

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

Definition at line 306 of file pomp.h.

308{
309 return (dt > 0) ? log1p(R*dt)/dt : R;
310}
#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 287 of file pomp.h.

289{
290 double sum;
291 int i;
292 for (i = 0, sum = 0.0; i < n; i++) sum += (xt[i] = exp(x[i]));
293 for (i = 0; i < n; i++) xt[i] /= sum;
294}
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 313 of file pomp.h.

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

◆ rbetanbinom()

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

Definition at line 330 of file pomp.h.

332{
333 double p = size/(size+mu);
334 return rnbinom(size,rbeta(p*theta,(1.0-p)*theta));
335}

◆ reulermultinom()

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

Definition at line 165 of file pomp.h.

167{
168 double p = 0.0;
169 int j, k;
170 if ( !R_FINITE(size) || size < 0.0 || floor(size+0.5) != size ||
171 !R_FINITE(dt) || dt < 0.0) {
172 for (k = 0; k < m; k++) trans[k] = R_NaReal;
173 warn("in 'reulermultinom': NAs produced.");
174 return;
175 }
176 for (k = 0; k < m; k++) {
177 if (!R_FINITE(rate[k]) || rate[k] < 0.0) {
178 for (j = 0; j < m; j++) trans[j] = R_NaReal;
179 warn("in 'reulermultinom': NAs produced.");
180 return;
181 }
182 p += rate[k]; // total event rate
183 }
184 if (p > 0.0) {
185 size = rbinom(size,1-exp(-p*dt)); // total number of events
186 m -= 1;
187 for (k = 0; k < m; k++) {
188 if (rate[k] > p) p = rate[k];
189 trans[k] = ((size > 0) && (p > 0)) ? rbinom(size,rate[k]/p) : 0;
190 size -= trans[k];
191 p -= rate[k];
192 }
193 trans[m] = size;
194 } else {
195 for (k = 0; k < m; k++) trans[k] = 0.0;
196 }
197}
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 277 of file pomp.h.

279{
280 double sum;
281 int i;
282 for (i = 0, sum = 0.0; i < n; i++) sum += x[i];
283 for (i = 0; i < n; i++) xt[i] = log(x[i]/sum);
284}
Here is the caller graph for this function: