nimble
nimble copied to clipboard
Error when compiling MCMC with both an `RW_PF` and an `RW_PF_block` sampler
Trying to compile an MCMC algorithm that has both an RW_PF sampler and an RW_PF_block sampler
results in the following error message:
Error in nimbleProject$instantiateCmodelValues(thisObj, dll) :
Trying to instantiate a modelValues type that the project has no record of. Try setting option resetFunctions = TRUE in compileNimble
It seems like the compiler is encountering an issue in keeping track of the modelValues objects created by the different PF algorithms for the two different samplers. This issue occurs currently using the devel branch on Windows 10. The code below can be used to reproduce the error:
code <- nimbleCode({
x[1] ~ dnorm(mean = mu0, sd = sigma_x);
y[1] ~ dnorm(x[1], sd = sigma_y);
for(i in 2:N){
x[i] ~ dnorm(mean = x[i-1], sd = sigma_x);
y[i] ~ dnorm(mean = x[i], sd = sigma_y);
}
sigma_x ~ T(dnorm(1, sd = .5), 0,);
sigma_y ~ T(dnorm(0.1, sd = .5), 0,);
mu0 ~ dnorm(0, 1)
})
set.seed(0)
N <- 10
sigma_x <- 1
sigma_y <- .1
x <- rep(NA, N)
y <- x
x[1] <- rnorm(1, 0, sigma_x)
y[1] <- rnorm(1, x[1], sigma_y)
for(i in 2:N){
x[i] <- rnorm(1, x[i-1], sigma_x)
y[i] <- rnorm(1, x[i], sigma_y)
}
consts <- list(N=N)
testdata <- list(y=y)
inits <- list(sigma_x = 1, sigma_y = 0.1, x = x, mu0 = 0)
testModel <- nimbleModel(code = code, data = testdata, constants = consts, inits = inits)
CtestModel <- compileNimble(testModel)
testMCMCconf <- configureMCMC(testModel, nodes = NULL)
testMCMCconf$addSampler('mu0', type = 'RW_PF', control = list(latents = 'x'))
testMCMCconf$addSampler(c('sigma_x', 'sigma_y'),
type = 'RW_PF_block', control = list(latents = 'x'))
testMCMC <- buildMCMC(testMCMCconf)
CtestMCMC <- compileNimble(testMCMC, project = testModel)