GithubHelp home page GithubHelp logo

Comments (4)

kingaa avatar kingaa commented on July 28, 2024

Use spy to view the C file you've created with your C snippets. By default, this is stored in the temporary directory. You can change this using the cdir and cfile options.

Most people find it easiest to work with C snippets, but you can certainly link to a library of your own. See
FAQ 3.7. The C API for pomp is described here. In particular, if you furnish your own basic model components, they must conform to the prototypes for such functions.

I am not sure what you have in mind by "a long external data stream". Are you envisioning that rprocess should depend on covariates? If so, does the existing facility for covariates solve the problem?

More generally, you can do almost anything you want in the C snippets, as long as they are valid C. That doesn't mean that the resulting calculation will be correct, or even meaningful, of course!

from pomp.

Fuhan-Yang avatar Fuhan-Yang commented on July 28, 2024

Thanks for the answers. Does that mean the declarations void pomp_* should always stay the same?

The covariates facility is what I need. But I'm having issues running simulations. Below is my test pomp model:

#### daily integrated pomp model ####

library(pomp)
library(dplyr)
library(ggplot2)

dat <- data.frame(
  daynum = c(1:3652),
  dat = rbinom(3652,size = 10, prob = 0.3) + c(1:3652)* 0.1 - 0.3
)

covar <- data.frame(
  daynum = dat$daynum,
  step = 1.1
)

### initial condition ###
step_rinit <- Csnippet("
  x = 0;
  y = 0;
")

### process model ###

## stochastic version ##
step_rproc <- Csnippet("
    
    double dx = 0.1;
    double dy = -0.1;
    
    dx = dx + step * s;
    dy = dy + 0.5 * step * s;
    
    y = y + dx + dy;
    x = x + dx + dy;

")

### measure model ###
step_dmeas <- Csnippet("
  lik = dbinom(dat, y, rho, give_log);
")

step_rmeas <- Csnippet("
  dat = rbinom(y, rho);
")

##### plug in pomp ####
test_pomp <- 
  pomp(data = dat,
       times = 'daynum',
       t0 = 1,
       rinit = step_rinit,
       rprocess = euler(step_rproc,delta.t = 1),
       rmeasure = step_rmeas,
       dmeasure = step_dmeas,
       covar = covariate_table(covar$step,times = covar$daynum),
       covarnames = 'step',
       obsnames = 'dat',
       statenames = c('x','y'),
       paramnames = c('s','rho'),
       cdir = 'c')


test_pomp |>
  simulate(nsim = 20, 
           params = c(s = 0.2,rho = 1),
           covar = covariate_table(covar$step,times = covar$daynum),
           covarnames = 'step',
           format = 'data.frame') |>
  ggplot() + 
  geom_line(aes(x = daynum, y = y,color = .id))

The model just tests if the process model can be affected by the covariates. There are no issues building the pomp model, but error appeared in simulate as "Error: in ‘simulate’: variable 'step' not found among the covariates." . Can you please tell me what happened?

from pomp.

kingaa avatar kingaa commented on July 28, 2024

Cf. the following, in particular, the call to covariate_table. Note there is no need to reinsert covar in the call to simulate.

##### plug in pomp ####
dat |>
  pomp(
    times = "daynum",
    t0 = 1,
    rinit = step_rinit,
    rprocess = euler(step_rproc,delta.t = 1),
    rmeasure = step_rmeas,
    dmeasure = step_dmeas,
    covar = covariate_table(covar,times="daynum"),
    statenames = c("x","y"),
    paramnames = c("s","rho"),
    cdir = "c"
  ) -> test_pomp

test_pomp |>
  simulate(
    nsim = 20, 
    params = c(s = 0.2,rho = 1),
    format = "data.frame"
  ) |>
  ggplot(aes(x = daynum, y = y, color = .id)) + 
  geom_line()

While I think the above addresses your immediate question, and I take it that you've cobbled this up for purely illustrative purposes, I do point out that it makes little sense to include step as a covariate, since it is constant and could more properly be included as a parameter.

from pomp.

Fuhan-Yang avatar Fuhan-Yang commented on July 28, 2024

Thank you so much for the prompt answer! Yes, this model is oversimplified to test the code implementation and to visually check the effect of the simple covariate. Thanks again for all the guidance. My issue is resolved and I will close it now.

from pomp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.