Overture makes writing Markov chain Monte Carlo (MCMC) samplers simpler. With overture you can:
Using overture is easy:
<- function(x) {
SampleX + 1
x
}
<- function(y) {
SampleY * y
y }
<- InitMcmc(3) # Run the chain for 3 iterations Mcmc
<- c(0, 10) # Initial value for x
x <- 2 # Initial value for y y
<- Mcmc({
samples <- SampleX(x)
x <- SampleY(y)
y })
> samples$x
1] [,2]
[,1,] 1 11
[2,] 2 12
[3,] 3 13
[> samples$y
1]
[,1,] 4
[2,] 16
[3,] 256 [
To save samples on disk, specify the directory where the samples should be saved:
<- InitMcmc(3, backing.path="/save/directory/path/")
Mcmc <- Mcmc({
samples <- SampleX(x)
x <- SampleY(y)
y })
The samples can be analyzed as before:
> samples$x[,]
1] [,2]
[,1,] 1 11
[2,] 2 12
[3,] 3 13
[> samples$y[,, drop=FALSE]
1]
[,1,] 4
[2,] 16
[3,] 256 [
To load the samples from disk, use LoadMcmc
:
<- LoadMcmc("/save/directory/path/") loaded.samples
To convert a file-backed MCMC into a list of R in-memory matrices,
use ToMemory
:
<- ToMemory(loaded.samples)
samples.in.memory > samples.in.memory
$x
1] [,2]
[,1,] 1 11
[2,] 2 12
[3,] 3 13
[
$y
1]
[,1,] 4
[2,] 16
[3,] 256 [
Samples from an MCMC can be viewed before its completion. First, start the slow running MCMC as a file-backed chain:
<- InitMcmc(10000, backing.path="/save/directory/path/")
SlowMcmc SlowMcmc({
<- SlowSampler()
x })
Then, in another R process while the MCMC is still running, use
Peek
to load and analyze the samples taken so far:
<- Peek("/save/directory/path/")
samples.so.far $x[,] samples.so.far
More examples and details are given in the package documentation.
To install from CRAN run:
install.packages("overture")
To install from GitHub, after installing devtools run:
::install_github("kurtis-s/overture") devtools
If you aren’t sure which version to install, you probably want to install from CRAN.