Skip to content

Sampler fails when using custom hybrid likelihood function written with a mixture of R and Rcpp #108

Description

@jameshay218

Really great package and documentation! I've finally got around to seeing how drjacoby will do with a hierarchical ODE model (my sampler is struggling).

Hopefully a quick question, but will provide a minimal example if not...

I am running a pared down version of my full model, and drjacoby seems to be working nicely. However, I have two identical custom likelihood functions: one written in R and one in Cpp with an Rcpp interface. See below: if I just swap from likelihood to likelihood_fast, the sampler tries to run off into weird parts of parameter space. Works totally fine with likelihood.

Is there something about the way the C++ code is organized that prohibits Rcpp function use like this? Maybe I'm accidentally accessing/overwriting some variables in the C++ environment that I shouldn't be?

The reason I think it's some conflict in C++ is that the breakdown occurs even if I call the likelihood_fast function but don't use its output. eg., sampling from the prior by having the likelihood function return 0 at the end.

## pars_all is a vector taking a combination of values from params and misc
## solved is some model output
## obs is a list passed via data
## Likelihood in Rcpp -- doesn't work
tmp_lik <- likelihood_fast(solved, obs[[indiv]], pars_all)
## Likelihood in R -- works fine
tmp_lik <- likelihood(solved, obs[[indiv]], pars_all)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions