Simple MCMC With Templates
This is not meant to be used for anything. This is just to illustrate how one might use C++ templates to avoid hassles with using function pointers.
This is an example of using templates to make a function that needs functions (e.g. an MCMC sampler, optimiser, etc) work easily enough in R + Rcpp. See the demo package at tests/testthat/demo for use in a package (the important bit is the
LinkingTo field in the DESCRIPTION. The package also has the same example in
R (which would be the model if you had a sampler that you wanted to use multiple times within a single package).
n <- 5 x0 <- rnorm(n) w <- runif(n, 0, 10) pars <- c(rnorm(n), runif(n)) samples <- simplemcmc::mcmc_example(x0, w, 1000, pars) matplot(samples$x, type="l", lty=1)
MIT + file LICENSE © Rich FitzJohn.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.