[Pomp-commits] r116 - in pkg: . inst/include man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 29 03:36:41 CEST 2009
Author: kingaa
Date: 2009-04-29 03:36:41 +0200 (Wed, 29 Apr 2009)
New Revision: 116
Modified:
pkg/DESCRIPTION
pkg/inst/include/pomp.h
pkg/man/euler.Rd
pkg/src/euler.c
pkg/src/lookup_table.c
pkg/src/pomp.h
pkg/src/pomp_internal.h
Log:
rearrange the headers
rename the prototypes for native routines used in Euler and onestep plugins
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/DESCRIPTION 2009-04-29 01:36:41 UTC (rev 116)
@@ -1,8 +1,8 @@
Package: pomp
Type: Package
Title: Statistical inference for partially observed Markov processes
-Version: 0.23-4
-Date: 2009-04-28
+Version: 0.23-5
+Date: 2009-04-29
Author: Aaron A. King, Edward L. Ionides, Carles Martinez Breto, Steve Ellner, Bruce Kendall
Maintainer: Aaron A. King <kingaa at umich.edu>
Description: Inference methods for partially-observed Markov processes
Modified: pkg/inst/include/pomp.h
===================================================================
--- pkg/inst/include/pomp.h 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/inst/include/pomp.h 2009-04-29 01:36:41 UTC (rev 116)
@@ -7,13 +7,30 @@
#include <Rmath.h>
#include <Rdefines.h>
-// Prototype for one-step Euler simulator, as used by "euler.simulate":
-typedef void euler_step_sim(double *x, const double *p,
- const int *stateindex, const int *parindex, const int *covindex,
- int ncovars, const double *covars,
- double t, double dt);
+// prototypes for C-level access to Euler-multinomial distribution functions
+void reulermultinom (int ntrans, double size, double *rate, double dt, double *trans);
+double deulermultinom (int ntrans, double size, double *rate, double dt, double *trans, int give_log);
+
+// facility for dotting a vector of parameters ('coef') against a vector of basis-function values ('basis')
+double dot_product (int dim, const double *basis, const double *coef);
+
+// Prototype for one-step simulator, as used by "euler.simulate" and "onestep.simulate":
+typedef double pomp_ssa_rate_fn(int j, double t, const double *x, const double *p);
// Description:
// on input:
+// j = integer specifying the number of the reaction whose rate is desired
+// t = time at which the rates are to be evaluated
+// x = vector of state variables
+// p = vector of parameters
+// returns the rate of the j-th reaction
+
+// Prototype for one-step simulator, as used by "euler.simulate" and "onestep.simulate":
+typedef void pomp_onestep_sim(double *x, const double *p,
+ const int *stateindex, const int *parindex, const int *covindex,
+ int ncovars, const double *covars,
+ double t, double dt);
+// Description:
+// on input:
// x = pointer to state vector
// p = pointer to parameter vector
// stateindex = pointer to vector of integers pointing to the states in 'x' in the order specified by
@@ -33,11 +50,11 @@
// Inclusion of these calls in the user-defined function may result in significant slowdown.
-// Prototype for one-step Euler PDF, as used by "euler.density":
-typedef void euler_step_pdf(double *f,
- double *x1, double *x2, double t1, double t2, const double *p,
- const int *stateindex, const int *parindex, const int *covindex,
- int ncovars, const double *covars);
+// Prototype for one-step log probability density function, as used by "onestep.density":
+typedef void pomp_onestep_pdf(double *f,
+ double *x1, double *x2, double t1, double t2, const double *p,
+ const int *stateindex, const int *parindex, const int *covindex,
+ int ncovars, const double *covars);
// Description:
// on input:
// x1 = pointer to state vector at time t1
@@ -57,11 +74,6 @@
// on output:
// f = pointer to the probability density (a single scalar)
-// prototypes for C-level access to Euler-multinomial distribution functions
-void reulermultinom (int ntrans, double size, double *rate, double dt, double *trans);
-double deulermultinom (int ntrans, double size, double *rate, double dt, double *trans, int give_log);
-
-
// Prototype for deterministic skeleton evaluation
typedef void pomp_vectorfield_map (double *f, double *x, double *p,
int *stateindex, int *parindex, int *covindex,
@@ -133,20 +145,4 @@
// on output:
// lik = pointer to scalar containing (log) likelihood
-
-// lookup-table structure, as used internally
-struct lookup_table {
- int length, width;
- int index;
- double *x;
- double *y;
-};
-
-// simple linear interpolation of the lookup table (with derivative if desired)
-// setting dydt = 0 in the call to 'table_lookup' will bypass computation of the derivative
-void table_lookup (struct lookup_table *tab, double x, double *y, double *dydt);
-
-// facility for dotting a vector of parameters ('coef') against a vector of basis-function values ('basis')
-double dot_product (int dim, const double *basis, const double *coef);
-
#endif
Modified: pkg/man/euler.Rd
===================================================================
--- pkg/man/euler.Rd 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/man/euler.Rd 2009-04-29 01:36:41 UTC (rev 116)
@@ -38,13 +38,13 @@
\item{step.fun}{
This can be either an R function or a compiled, dynamically loaded native function containing the model simulator.
It should be written to take a single Euler step from a single point in state space.
- If it is a native function, it must be of type "euler\_step\_sim" as defined in the header "pomp.h", which is included with the package.
+ If it is a native function, it must be of type "pomp\_onestep\_sim" as defined in the header "pomp.h", which is included with the package.
For details on how to write such codes, see Details.
}
\item{dens.fun}{
This can be either an R function or a compiled, dynamically loaded native function containing the model transition log probability density function.
This function will be called to compute the log likelihood of the actual Euler steps.
- It must be of type "euler\_step\_pdf" as defined in the header "pomp.h", which is included with the package.
+ It must be of type "pomp\_onestep\_pdf" as defined in the header "pomp.h", which is included with the package.
For details on how to write such codes, see Details.
}
\item{delta.t}{
@@ -95,7 +95,7 @@
This is accomplished via interpolation of the covariate table.
Additional arguments may be given: these will be filled by the correspondingly-named elements in the \code{userdata} slot of the \code{pomp} object (see \code{\link{pomp}}).
- If \code{step.fun} is written in a native language, it must be a function of type "euler\_step\_sim" as specified in the header "pomp.h" included with the package (see the directory "include" in the installed package directory).
+ If \code{step.fun} is written in a native language, it must be a function of type "pomp\_onestep\_sim" as specified in the header "pomp.h" included with the package (see the directory "include" in the installed package directory).
If \code{dens.fun} is written as an R function, it must have at least the arguments \code{x1}, \code{x2}, \code{t1}, \code{t2}, \code{params}, and \code{\dots}.
On a call to this function, \code{x1} and \code{x2} will be named vectors of state variables at times \code{t1} and \code{t2}, respectively.
@@ -104,7 +104,7 @@
This is accomplished via interpolation of the covariate table.
As above, any additional arguments will be filled by the correspondingly-named elements in the \code{userdata} slot of the \code{pomp} object (see \code{\link{pomp}}).
- If \code{dens.fun} is written in a native language, it must be a function of type "euler\_step\_pdf" as defined in the header "pomp.h" included with the package (see the directory "include" in the installed package directory).
+ If \code{dens.fun} is written in a native language, it must be a function of type "pomp\_onestep\_pdf" as defined in the header "pomp.h" included with the package (see the directory "include" in the installed package directory).
}
\value{
\code{euler.simulate} and \code{onestep.simulate} each return a \code{nvar} x \code{nrep} x \code{ntimes} array, where \code{nvar} is the number of state variables, \code{nrep} is the number of replicate simulations (= number of columns of \code{xstart} and \code{params}), and \code{ntimes} is the length of \code{times}.
Modified: pkg/src/euler.c
===================================================================
--- pkg/src/euler.c 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/src/euler.c 2009-04-29 01:36:41 UTC (rev 116)
@@ -4,7 +4,7 @@
#include <R_ext/Constants.h>
// take nstep Euler-Poisson steps from t1 to t2
-static void euler_simulator (euler_step_sim *estep,
+static void euler_simulator (pomp_onestep_sim *estep,
double *x, double *xstart, double *times, double *params,
int *ndim, double *deltat,
int *stateindex, int *parindex, int *covindex, int *zeroindex,
@@ -93,7 +93,7 @@
}
// take one step from t1 to t2
-static void onestep_simulator (euler_step_sim *estep,
+static void onestep_simulator (pomp_onestep_sim *estep,
double *x, double *xstart, double *times, double *params,
int *ndim,
int *stateindex, int *parindex, int *covindex, int *zeroindex,
@@ -148,41 +148,41 @@
}
}
-// these global objects will pass the needed information to the user-defined function (see 'default_euler_step_fn')
+// these global objects will pass the needed information to the user-defined function (see 'default_onestep_sim_fn')
// each of these is allocated once, globally, and refilled many times
-static SEXP euler_step_Xvec; // state variable vector
-static SEXP euler_step_Pvec; // parameter vector
-static SEXP euler_step_Cvec; // covariate vector
-static SEXP euler_step_time; // time
-static SEXP euler_step_dt; // stepsize
-static int euler_step_nvar; // number of state variables
-static int euler_step_npar; // number of parameters
-static SEXP euler_step_envir; // function's environment
-static SEXP euler_step_fcall; // function call
-static int euler_step_first; // first evaluation?
-static SEXP euler_step_vnames; // names of state variables
-static int *euler_step_vindex; // indices of state variables
+static SEXP _onestep_internal_Xvec; // state variable vector
+static SEXP _onestep_internal_Pvec; // parameter vector
+static SEXP _onestep_internal_Cvec; // covariate vector
+static SEXP _onestep_internal_time; // time
+static SEXP _onestep_internal_dt; // stepsize
+static int _onestep_internal_nvar; // number of state variables
+static int _onestep_internal_npar; // number of parameters
+static SEXP _onestep_internal_envir; // function's environment
+static SEXP _onestep_internal_fcall; // function call
+static int _onestep_internal_first; // first evaluation?
+static SEXP _onestep_internal_vnames; // names of state variables
+static int *_onestep_internal_vindex; // indices of state variables
-#define FIRST (euler_step_first)
-#define VNAMES (euler_step_vnames)
-#define VINDEX (euler_step_vindex)
-#define XVEC (euler_step_Xvec)
-#define PVEC (euler_step_Pvec)
-#define CVEC (euler_step_Cvec)
-#define TIME (euler_step_time)
-#define DT (euler_step_dt)
-#define NVAR (euler_step_nvar)
-#define NPAR (euler_step_npar)
-#define RHO (euler_step_envir)
-#define FCALL (euler_step_fcall)
+#define FIRST (_onestep_internal_first)
+#define VNAMES (_onestep_internal_vnames)
+#define VINDEX (_onestep_internal_vindex)
+#define XVEC (_onestep_internal_Xvec)
+#define PVEC (_onestep_internal_Pvec)
+#define CVEC (_onestep_internal_Cvec)
+#define TIME (_onestep_internal_time)
+#define DT (_onestep_internal_dt)
+#define NVAR (_onestep_internal_nvar)
+#define NPAR (_onestep_internal_npar)
+#define RHO (_onestep_internal_envir)
+#define FCALL (_onestep_internal_fcall)
// this is the euler step function that is evaluated when the user supplies an R function
// (and not a native routine)
// Note that stateindex, parindex, covindex are ignored.
-static void default_euler_step_fn (double *x, const double *p,
- const int *stateindex, const int *parindex, const int *covindex,
- int ncovar, const double *covar,
- double t, double dt)
+static void default_onestep_sim_fn (double *x, const double *p,
+ const int *stateindex, const int *parindex, const int *covindex,
+ int ncovar, const double *covar,
+ double t, double dt)
{
int nprotect = 0;
int *op, k;
@@ -243,7 +243,7 @@
int nparams = LENGTH(paramnames);
int ncovars = LENGTH(covarnames);
int nzeros = LENGTH(zeronames);
- euler_step_sim *ff = NULL;
+ pomp_onestep_sim *ff = NULL;
SEXP X, pindex, sindex, cindex, zindex;
int *sidx, *pidx, *cidx, *zidx;
SEXP fn, Pnames, Cnames;
@@ -270,7 +270,7 @@
}
if (use_native) {
- ff = (euler_step_sim *) R_ExternalPtrAddr(func);
+ ff = (pomp_onestep_sim *) R_ExternalPtrAddr(func);
VINDEX = 0;
} else {
PROTECT(fn = func); nprotect++;
@@ -297,7 +297,7 @@
PROTECT(FCALL = LCONS(XVEC,FCALL)); nprotect++;
SET_TAG(FCALL,install("x"));
PROTECT(FCALL = LCONS(fn,FCALL)); nprotect++;
- ff = (euler_step_sim *) default_euler_step_fn;
+ ff = (pomp_onestep_sim *) default_onestep_sim_fn;
VINDEX = (int *) Calloc(nvar,int);
FIRST = 1;
}
@@ -369,7 +369,7 @@
#undef VINDEX
// compute pdf of a sequence of Euler steps
-static void euler_densities (euler_step_pdf *estep,
+static void euler_densities (pomp_onestep_pdf *estep,
double *f,
double *x, double *times, double *params,
int *ndim,
@@ -418,7 +418,7 @@
}
}
-// these global objects will pass the needed information to the user-defined function (see 'default_euler_dens_fn')
+// these global objects will pass the needed information to the user-defined function (see 'default_onestep_dens_fn')
// each of these is allocated once, globally, and refilled many times
static SEXP euler_dens_Xvec1; // state variable vector
static SEXP euler_dens_Xvec2; // state variable vector
@@ -445,9 +445,9 @@
// this is the euler dens function that is evaluated when the user supplies an R function
// (and not a native routine)
// Note that stateindex, parindex, covindex are ignored.
-static void default_euler_dens_fn (double *f, double *x1, double *x2, double t1, double t2, const double *p,
- const int *stateindex, const int *parindex, const int *covindex,
- int ncovar, const double *covar)
+static void default_onestep_dens_fn (double *f, double *x1, double *x2, double t1, double t2, const double *p,
+ const int *stateindex, const int *parindex, const int *covindex,
+ int ncovar, const double *covar)
{
int nprotect = 0;
int k;
@@ -484,7 +484,7 @@
int nstates = LENGTH(statenames);
int nparams = LENGTH(paramnames);
int ncovars = LENGTH(covarnames);
- euler_step_pdf *ff = NULL;
+ pomp_onestep_pdf *ff = NULL;
SEXP F, pindex, sindex, cindex;
int *pidx, *sidx, *cidx;
SEXP fn, Xnames, Pnames, Cnames;
@@ -499,7 +499,7 @@
PROTECT(Cnames = GET_COLNAMES(GET_DIMNAMES(covar))); nprotect++;
if (inherits(func,"NativeSymbol")) {
- ff = (euler_step_pdf *) R_ExternalPtrAddr(func);
+ ff = (pomp_onestep_pdf *) R_ExternalPtrAddr(func);
} else if (isFunction(func)) {
PROTECT(fn = func); nprotect++;
PROTECT(RHO = (CLOENV(fn))); nprotect++;
@@ -529,7 +529,7 @@
PROTECT(FCALL = LCONS(X1VEC,FCALL)); nprotect++;
SET_TAG(FCALL,install("x1"));
PROTECT(FCALL = LCONS(fn,FCALL)); nprotect++;
- ff = (euler_step_pdf *) default_euler_dens_fn;
+ ff = (pomp_onestep_pdf *) default_onestep_dens_fn;
} else {
UNPROTECT(nprotect);
error("illegal input: supplied function must be either an R function or a compiled native function");
Modified: pkg/src/lookup_table.c
===================================================================
--- pkg/src/lookup_table.c 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/src/lookup_table.c 2009-04-29 01:36:41 UTC (rev 116)
@@ -2,7 +2,7 @@
#include <Rmath.h>
#include <Rdefines.h>
-#include "pomp.h"
+#include "pomp_internal.h"
SEXP lookup_in_table (SEXP ttable, SEXP xtable, SEXP t, int *index) {
int nprotect = 0;
Modified: pkg/src/pomp.h
===================================================================
--- pkg/src/pomp.h 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/src/pomp.h 2009-04-29 01:36:41 UTC (rev 116)
@@ -7,13 +7,30 @@
#include <Rmath.h>
#include <Rdefines.h>
-// Prototype for one-step Euler simulator, as used by "euler.simulate":
-typedef void euler_step_sim(double *x, const double *p,
- const int *stateindex, const int *parindex, const int *covindex,
- int ncovars, const double *covars,
- double t, double dt);
+// prototypes for C-level access to Euler-multinomial distribution functions
+void reulermultinom (int ntrans, double size, double *rate, double dt, double *trans);
+double deulermultinom (int ntrans, double size, double *rate, double dt, double *trans, int give_log);
+
+// facility for dotting a vector of parameters ('coef') against a vector of basis-function values ('basis')
+double dot_product (int dim, const double *basis, const double *coef);
+
+// Prototype for one-step simulator, as used by "euler.simulate" and "onestep.simulate":
+typedef double pomp_ssa_rate_fn(int j, double t, const double *x, const double *p);
// Description:
// on input:
+// j = integer specifying the number of the reaction whose rate is desired
+// t = time at which the rates are to be evaluated
+// x = vector of state variables
+// p = vector of parameters
+// returns the rate of the j-th reaction
+
+// Prototype for one-step simulator, as used by "euler.simulate" and "onestep.simulate":
+typedef void pomp_onestep_sim(double *x, const double *p,
+ const int *stateindex, const int *parindex, const int *covindex,
+ int ncovars, const double *covars,
+ double t, double dt);
+// Description:
+// on input:
// x = pointer to state vector
// p = pointer to parameter vector
// stateindex = pointer to vector of integers pointing to the states in 'x' in the order specified by
@@ -33,11 +50,11 @@
// Inclusion of these calls in the user-defined function may result in significant slowdown.
-// Prototype for one-step Euler PDF, as used by "euler.density":
-typedef void euler_step_pdf(double *f,
- double *x1, double *x2, double t1, double t2, const double *p,
- const int *stateindex, const int *parindex, const int *covindex,
- int ncovars, const double *covars);
+// Prototype for one-step log probability density function, as used by "onestep.density":
+typedef void pomp_onestep_pdf(double *f,
+ double *x1, double *x2, double t1, double t2, const double *p,
+ const int *stateindex, const int *parindex, const int *covindex,
+ int ncovars, const double *covars);
// Description:
// on input:
// x1 = pointer to state vector at time t1
@@ -57,11 +74,6 @@
// on output:
// f = pointer to the probability density (a single scalar)
-// prototypes for C-level access to Euler-multinomial distribution functions
-void reulermultinom (int ntrans, double size, double *rate, double dt, double *trans);
-double deulermultinom (int ntrans, double size, double *rate, double dt, double *trans, int give_log);
-
-
// Prototype for deterministic skeleton evaluation
typedef void pomp_vectorfield_map (double *f, double *x, double *p,
int *stateindex, int *parindex, int *covindex,
@@ -133,20 +145,4 @@
// on output:
// lik = pointer to scalar containing (log) likelihood
-
-// lookup-table structure, as used internally
-struct lookup_table {
- int length, width;
- int index;
- double *x;
- double *y;
-};
-
-// simple linear interpolation of the lookup table (with derivative if desired)
-// setting dydt = 0 in the call to 'table_lookup' will bypass computation of the derivative
-void table_lookup (struct lookup_table *tab, double x, double *y, double *dydt);
-
-// facility for dotting a vector of parameters ('coef') against a vector of basis-function values ('basis')
-double dot_product (int dim, const double *basis, const double *coef);
-
#endif
Modified: pkg/src/pomp_internal.h
===================================================================
--- pkg/src/pomp_internal.h 2009-04-29 01:35:48 UTC (rev 115)
+++ pkg/src/pomp_internal.h 2009-04-29 01:36:41 UTC (rev 116)
@@ -14,6 +14,18 @@
# define MATCHCOLNAMES(X,N) (matchnames(GET_COLNAMES(GET_DIMNAMES(X)),(N)))
# define MATCH_CHAR_TO_ROWNAMES(X,N,A) (match_char_to_names(GET_ROWNAMES(GET_DIMNAMES(X)),(N),(A)))
+// lookup-table structure, as used internally
+struct lookup_table {
+ int length, width;
+ int index;
+ double *x;
+ double *y;
+};
+
+// simple linear interpolation of the lookup table (with derivative if desired)
+// setting dydt = 0 in the call to 'table_lookup' will bypass computation of the derivative
+void table_lookup (struct lookup_table *tab, double x, double *y, double *dydt);
+
/* bspline.c */
SEXP bspline_basis(SEXP x, SEXP degree, SEXP knots);
SEXP bspline_basis_function(SEXP x, SEXP i, SEXP degree, SEXP knots);
@@ -30,7 +42,7 @@
/* resample.c */
SEXP systematic_resampling(SEXP weights);
-static SEXP makearray (int rank, int *dim) {
+static inline SEXP makearray (int rank, int *dim) {
int nprotect = 0;
int *dimp, k;
SEXP dimx, x;
@@ -42,7 +54,7 @@
return x;
}
-static SEXP matchnames (SEXP x, SEXP names) {
+static inline SEXP matchnames (SEXP x, SEXP names) {
int nprotect = 0;
int n = length(names);
int *idx, k;
@@ -58,7 +70,7 @@
return index;
}
-static SEXP match_char_to_names (SEXP x, int n, char **names) {
+static inline SEXP match_char_to_names (SEXP x, int n, char **names) {
int nprotect = 0;
int *idx, k;
SEXP index, nm;
@@ -79,7 +91,7 @@
return index;
}
-static void setrownames (SEXP x, SEXP names, int n) {
+static inline void setrownames (SEXP x, SEXP names, int n) {
int nprotect = 0;
SEXP dimnms, nm;
PROTECT(nm = AS_CHARACTER(names)); nprotect++;
@@ -89,11 +101,11 @@
UNPROTECT(nprotect);
}
-static double expit (double x) {
+static inline double expit (double x) {
return 1.0/(1.0 + exp(-x));
}
-static double logit (double x) {
+static inline double logit (double x) {
return log(x/(1-x));
}
More information about the pomp-commits
mailing list