[Pomp-commits] r1035 - in pkg/pompExamples: . inst/examples src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 24 19:26:53 CET 2014


Author: kingaa
Date: 2014-12-24 19:26:52 +0100 (Wed, 24 Dec 2014)
New Revision: 1035

Modified:
   pkg/pompExamples/DESCRIPTION
   pkg/pompExamples/inst/examples/bbp.R
   pkg/pompExamples/src/bbp.c
Log:
- bombay plague example now uses codes compiled into package

Modified: pkg/pompExamples/DESCRIPTION
===================================================================
--- pkg/pompExamples/DESCRIPTION	2014-12-22 12:03:33 UTC (rev 1034)
+++ pkg/pompExamples/DESCRIPTION	2014-12-24 18:26:52 UTC (rev 1035)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Additional pomp examples
 Version: 0.24-1
-Date: 2014-12-22
+Date: 2014-12-24
 Maintainer: Aaron A. King <kingaa at umich.edu>
 Authors at R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),
 	   email="kingaa at umich.edu"),

Modified: pkg/pompExamples/inst/examples/bbp.R
===================================================================
--- pkg/pompExamples/inst/examples/bbp.R	2014-12-22 12:03:33 UTC (rev 1034)
+++ pkg/pompExamples/inst/examples/bbp.R	2014-12-24 18:26:52 UTC (rev 1035)
@@ -48,37 +48,43 @@
        beta=2,delta=1.5,y0=0.0004,theta=54,
        sigma=0.02,
        mu=0,gamma=0.2,ratio=10000
-     ),
+       ),
      rprocess=euler.sim(
-       step.fun=Csnippet("
-                         double X = exp(x);
-                         double Y = exp(y);
-                         double dx, dy, dn, dW, ito;
-                         dx = (mu*(1.0/X-1)+(delta-beta)*Y)*dt;
-                         dy = (beta*X+delta*(Y-1)-gamma-mu)*dt;
-                         dn = -delta*Y*dt;
-                         dW = rnorm(0,sigma*sqrt(dt));
-                         ito = 0.5*sigma*sigma*dt;
-                         x += dx - beta*Y*(dW-beta*Y*ito);
-                         y += dy + beta*X*(dW+beta*X*ito);
-                         n += dn;
-                         "
-         ),
+       step.fun="_bbp_stepfn",
+       PACKAGE="pompExamples",
+### step.fun=Csnippet("
+###                   double X = exp(x);
+###                   double Y = exp(y);
+###                   double dx, dy, dn, dW, ito;
+###                   dx = (mu*(1.0/X-1)+(delta-beta)*Y)*dt;
+###                   dy = (beta*X+delta*(Y-1)-gamma-mu)*dt;
+###                   dn = -delta*Y*dt;
+###                   dW = rnorm(0,sigma*sqrt(dt));
+###                   ito = 0.5*sigma*sigma*dt;
+###                   x += dx - beta*Y*(dW-beta*Y*ito);
+###                   y += dy + beta*X*(dW+beta*X*ito);
+###                   n += dn;
+###                   "
+###   ),
        delta.t=1/24/7
        ),
-     skeleton=Csnippet("
-                        double X = exp(x);
-                        double Y = exp(y);
-                        Dx = mu*(1.0/X-1)+(delta-beta)*Y;
-                        Dy = beta*X+delta*(Y-1)-gamma-mu;
-                        Dn = -delta*Y;
-                        "
-       ),
+     skeleton="_bbp_skelfn",
+### skeleton=Csnippet("
+###                    double X = exp(x);
+###                    double Y = exp(y);
+###                    Dx = mu*(1.0/X-1)+(delta-beta)*Y;
+###                    Dy = beta*X+delta*(Y-1)-gamma-mu;
+###                    Dn = -delta*Y;
+###                    "
+###   ),
      skeleton.type="vectorfield",
      paramnames=c("beta","delta","mu","gamma","sigma","theta","ratio"),
      statenames=c("x","y","n"),
-     rmeasure=Csnippet("deaths=rnbinom_mu(theta,ratio*exp(y));"),
-     dmeasure=Csnippet("lik=dnbinom_mu(deaths,theta,ratio*exp(y),give_log);"),
+     rmeasure="_bbp_rmeasure",
+     dmeasure="_bbp_dmeasure",
+     PACKAGE="pompExamples",
+###     rmeasure=Csnippet("deaths=rnbinom_mu(theta,ratio*exp(y));"),
+###     dmeasure=Csnippet("lik=dnbinom_mu(deaths,theta,ratio*exp(y),give_log);"),
      logvar=c("beta","delta","ratio","sigma","theta","mu"),
      logitvar=c("y0"),
      parameter.inv.transform=function (params, logvar, logitvar, ...) {

Modified: pkg/pompExamples/src/bbp.c
===================================================================
--- pkg/pompExamples/src/bbp.c	2014-12-22 12:03:33 UTC (rev 1034)
+++ pkg/pompExamples/src/bbp.c	2014-12-24 18:26:52 UTC (rev 1035)
@@ -1,8 +1,7 @@
-/* pomp model file: _bombay_plague */
+/* pomp model file: _bbp */
 
 #include <pomp.h>
 #include <R_ext/Rdynload.h>
-
  
 #define Beta	(__p[__parindex[0]])
 #define delta	(__p[__parindex[1]])
@@ -27,57 +26,57 @@
 #define Tratio	(__pt[__parindex[6]])
 #define lik	(__lik[0])
 
-void _bombay_plague_rmeasure (double *__y, double *__x, double *__p, int *__obsindex, int *__stateindex, int *__parindex, int *__covindex, int __ncovars, double *__covars, double t)
+void _bbp_rmeasure (double *__y, double *__x, double *__p, int *__obsindex, int *__stateindex, int *__parindex, int *__covindex, int __ncovars, double *__covars, double t)
 {
- deaths=rnbinom_mu(theta,ratio*exp(y)); 
+  deaths=rnbinom_mu(theta,ratio*exp(y)); 
 }
 
 
-void _bombay_plague_dmeasure (double *__lik, double *__y, double *__x, double *__p, int give_log, int *__obsindex, int *__stateindex, int *__parindex, int *__covindex, int __ncovars, double *__covars, double t)
+void _bbp_dmeasure (double *__lik, double *__y, double *__x, double *__p, int give_log, int *__obsindex, int *__stateindex, int *__parindex, int *__covindex, int __ncovars, double *__covars, double t)
 {
- lik=dnbinom_mu(deaths,theta,ratio*exp(y),give_log); 
+  lik=dnbinom_mu(deaths,theta,ratio*exp(y),give_log); 
 }
 
 
-void _bombay_plague_stepfn (double *__x, const double *__p, const int *__stateindex, const int *__parindex, const int *__covindex, int __covdim, const double *__covars, double t, double dt)
+void _bbp_stepfn (double *__x, const double *__p, const int *__stateindex, const int *__parindex, const int *__covindex, int __covdim, const double *__covars, double t, double dt)
 {
 
-                         double X = exp(x);
-                         double Y = exp(y);
-                         double dx, dy, dn, dW, ito;
-                         dx = (mu*(1.0/X-1)+(delta-Beta)*Y)*dt;
-                         dy = (Beta*X+delta*(Y-1)-gamma-mu)*dt;
-                         dn = -delta*Y*dt;
-                         dW = rnorm(0,sigma*sqrt(dt));
-                         ito = 0.5*sigma*sigma*dt;
-                         x += dx - Beta*Y*(dW-Beta*Y*ito);
-                         y += dy + Beta*X*(dW+Beta*X*ito);
-                         n += dn;
+  double X = exp(x);
+  double Y = exp(y);
+  double dx, dy, dn, dW, ito;
+  dx = (mu*(1.0/X-1)+(delta-Beta)*Y)*dt;
+  dy = (Beta*X+delta*(Y-1)-gamma-mu)*dt;
+  dn = -delta*Y*dt;
+  dW = rnorm(0,sigma*sqrt(dt));
+  ito = 0.5*sigma*sigma*dt;
+  x += dx - Beta*Y*(dW-Beta*Y*ito);
+  y += dy + Beta*X*(dW+Beta*X*ito);
+  n += dn;
                           
 }
 
 
-void _bombay_plague_skelfn (double *__f, double *__x, double *__p, int *__stateindex, int *__parindex, int *__covindex, int __ncovars, double *__covars, double t)
+void _bbp_skelfn (double *__f, double *__x, double *__p, int *__stateindex, int *__parindex, int *__covindex, int __ncovars, double *__covars, double t)
 {
 
-                        double X = exp(x);
-                        double Y = exp(y);
-                        Dx = mu*(1.0/X-1)+(delta-Beta)*Y;
-                        Dy = Beta*X+delta*(Y-1)-gamma-mu;
-                        Dn = -delta*Y;
+  double X = exp(x);
+  double Y = exp(y);
+  Dx = mu*(1.0/X-1)+(delta-Beta)*Y;
+  Dy = Beta*X+delta*(Y-1)-gamma-mu;
+  Dn = -delta*Y;
                          
 }
 
 
-void _bombay_plague_rprior (double *__p, int *__parindex)
+void _bbp_rprior (double *__p, int *__parindex)
 {
-   error("'rprior' not defined"); 
+  error("'rprior' not defined"); 
 }
 
 
-void _bombay_plague_dprior (double *__lik, double *__p, int give_log, int *__parindex)
+void _bbp_dprior (double *__lik, double *__p, int give_log, int *__parindex)
 {
-   error("'dprior' not defined"); 
+  error("'dprior' not defined"); 
 }
 
 #undef Beta



More information about the pomp-commits mailing list