JAGS 4.2.0 data blocks cause core dumps on OS X
Brought to you by:
martyn_plummer
It looks like any model with a data block is causing a core dump on OS X. On OS X 10.11.4 using JAGS 4.2.0 (Mac binary downloaded from source forge).
model:
data {
ln_y <- log(y)
}
model {
sigma ~ dunif(0.001, 1000)
alpha ~ dnorm(0, 0.0001)
beta ~ dnorm(0, 0.0001)
for (i in 1:length(y)) {
ln_y[i] ~ dnorm(mu[i], 1/(sigma^2))
mu[i] <- alpha + beta*x[i]
}
}
data:
"x" <-
c(0, 1, 2, 3, 4, 5, 6, 7)
"y" <-
c(9878, 11613, 13808, 18161, 22610, 27452, 31758, 36074)
compile, nchains(1)
parameters:
".RNG.name" <- "base::Mersenne-Twister"
".RNG.seed" <- 1
initialize
update 1000
monitor set alpha, thin(1)
monitor set beta, thin(1)
update 10000
coda *
Results in:
jags-terminal(5201,0x7fff79c16000) malloc: *** error for object 0x7fd818609710: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Anonymous
Using the alternative formulation:
results in the following on exit:
One other note: the bug is also present in version 4.1.0
I am not able to reproduce this on Linux. I ran your test program through valgrind which showed no errors. Let's see if someone can reproduce this on Mac
I can reproduce this bug - I get the seg fault (Segmentation fault: 11) and it always occurs on exit of JAGS - the CODA files are produced with no problems. It only seemd to occur when providing .RNG.name and .RNG.seed in the initial values - if these are removed (or replaced with e.g. sigma) then I don't get the seg fault.
I'm travelling at the moment (so using my laptop with JAGS >4.2.0 compiled from source on OS 10.9.5) but will look into this further when I get back.
OK I managed to tickle this on Linux. It is caused by the double deletion of a random number generator (RNG): the first by the model and the second one by the RNG factory that created it. The first is an error. The second deletion occurs on exit if the C++ runtime calls the RNG factory destructor. This appears to occur systematically on Mac OS X but not on Linux, which is why I had trouble reproducing the bug.
Interesting. Does this explain why the problem only seems to occur if the model includes a
datablock? In my testing, if I omit thedatablock but otherwise use the same model, data, and parameters (pre-processing the data outside of JAGS), then I don't see the error.Yes it is a bug triggered by having simultaneously:
a) a data block and
b) setting the name and seed of the RNG in the initial values