Resume: Resumes an interrupted file-backed MCMC

Description Usage Arguments Value See Also Examples

View source: R/mcmc.R

Description

Resume will finish a file-backed MCMC that was interrupted. To resume an MCMC run, specify the MCMC's backing path and the sampling will continue from the last completed sample in the chain. Note, however, that the random number generator state from when the MCMC was interrupted is not restored, so the resulting chain my not be reproducible, even if a seed was specified before the sampling was interrupted.

Usage

1
Resume(backing.path)

Arguments

backing.path

directory path where the (partially completed) MCMC samples were saved

Value

A list of either matrix or big.matrix with the MCMC samples. Each row in the matrices corresponds to one sample from the MCMC chain.

See Also

InitMcmc

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Setup the MCMC
n.iter <- 5
SampleX <- function(x) x + 1
backing.path <- tempfile()
dir.create(backing.path)
x <- 0
interrupt.mcmc <- TRUE
Mcmc <- InitMcmc(n.iter, backing.path=backing.path)

# Interrupt the MCMC during the third iteration
try({
    samps <- Mcmc({
        x <- SampleX(x)
        if(x==3 && interrupt.mcmc) break
    })
}, silent=TRUE)

# The sampling is incomplete
samps <- LoadMcmc(backing.path)
samps$x[,]
rm(samps)

# Resume the MCMC
interrupt.mcmc <- FALSE
samps <- Resume(backing.path)

# All samples are available
samps$x[,]

overture documentation built on Aug. 11, 2019, 1:04 a.m.