Marco
2013-04-29
Hi everyone
Does anyone of you find a way to parallelize the jags execution?? I'm interested in parallelize the single MCMC computation(the computation of a single chain). I've find in the web the function jags.parallel, but this function is used to parallelize different chains in different cores. Because i use a large dataset, i need a way to parallelizeover multiple cores the updating(adapting) phases.
Thanks everybody
Marco
Daniel Hocking
2013-04-29
Hi Marco,
Here is what has worked best for me
library(parallel)
CL = makeCluster(3) # set number of clusters = to number of desired chains
clusterExport(cl=CL, list("jdata", "params", "inits", "ymax")) # make data available to jags in diff cores
clusterSetRNGStream(cl=CL, iseed=4321)
out <- clusterEvalQ(CL, {
library(rjags)
jm <- jags.model("habitat_random.txt", jdata, inits, n.adapt=100000, n.chains=1)
fm <- coda.samples(jm, params, n.iter=10000, thin=10)
return(as.mcmc(fm))
})
habitat.rand.list = mcmc.list(out) # group output from each core into one list
stopCluster(CL)
plot(habitat.rand.list)
par(mfrow=c(1,1))
summary(habitat.rand.list)
I hope this helps. Let me know if you have questions.
Cheers,
Dan
Daniel J. Hocking
114 James Hall
Department of Natural Resources & the Environment
University of New Hampshire
Durham, NH 03824
dhocking@unh.edu
Office: (603)-862-1408
http://danieljhocking.wordpress.com/
On Apr 29, 2013, at 12:59 PM, Marco ciabo89@users.sf.net wrote:
Hi everyone
Does anyone of you find a way to parallelize the jags execution?? I'm interested in parallelize the single MCMC computation(the computation of a single chain). I've find in the web the function jags.parallel, but this function is used to parallelize different chains in different cores. Because i use a large dataset, i need a way to parallelizeover multiple cores the updating(adapting) phases.
Thanks everybody
MarcoParallelization of JAGS
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mcmc-jags/discussion/610036/
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
Daniel Hocking
2013-04-29
I Marco,
Sorry, after I sent it, I realized that I mis-interpreted your question. I am not sure how to parallelize a single chain.
Best of luck,
Dan
Daniel Hocking
djhocking@gmail.com
http://www.nerunningservices.com
http://danieljhocking.wordpress.com/
On Apr 29, 2013, at 12:59 PM, Marco ciabo89@users.sf.net wrote:
Hi everyone
Does anyone of you find a way to parallelize the jags execution?? I'm interested in parallelize the single MCMC computation(the computation of a single chain). I've find in the web the function jags.parallel, but this function is used to parallelize different chains in different cores. Because i use a large dataset, i need a way to parallelizeover multiple cores the updating(adapting) phases.
Thanks everybody
MarcoParallelization of JAGS
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mcmc-jags/discussion/610036/
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
Marco
2013-04-30
Hi Daniel
Thank you for your reply. Even if you don't know how to parallelize the system for a single chain, maybe you know how to import data files into R object. I've the jags data file, in a txt format, formed by something similar to:
"a"<-2
"D"<-30
"M"<-10
"N"<-10
"mu_0"<-c(0, 0, 0, 0, 0, 0, 0, 0, ..... , 0)
"a_p"<-
structure(c(1.0, 0.0, 0.0, 0.0, 0.0, ..... , 0.0, 1.0)
.Dim=c(30, 30))
"a_g"<- ....
Do you know how i can import this txt file into R in order to use it as data for the MCMC phase?? The same is for the init file.
Thank you so much.
Marco
Martyn Plummer
2013-04-30
R> library(rjags) R> help(read.jagsdata)
Marco
2013-05-01
Thank you very much Martyn!
mark pahuta
2013-05-01
The R dclone library has functions designed for running JAGS in parallel. It also handles random number generation properly.
I've attached the code I use to run it.
Marco
2013-05-03
Thanks mark. However, as for the other suggestion, also your solution parallelize different chains.
mark pahuta
2013-05-03
Since JAGS uses MCMC, you can't run a single chain on different cores, as each step depends on the previous.
What you can do is run fewer iterations on multiple cores, and then combine them after each is in the stationary distribution. Although this wont help with the updating phase
Marco
2013-05-03
Thanks Mark for your time, i really appreciate this.
However, i would like to ask you something more.
I'm trying to using JAGS for a problem similar to the Matrix Factorization. So I've a big sparse matrix. I'm trying to fit the model, but i can not use the nesting format, because I would like to estimate the unknown variables. However this make the computation very slow(the matrix is 1000*1000 more or less, the time required for 100000 adapt iterations is 2 days without adaptation completeness). Have you got any hint to make the computation faster??
Thank you a lot
Marco
Martyn Plummer
2013-05-06
The problem is with the computational complexity of matrix factorization, which is generally of O(n^3), so a 1000*1000 matrix is going to be painfully slow. But your matrix is sparse, so you really want access to efficient sparse matrix factorization. Such algorithms exist, and are used internally by the GLM module, but are not yet available to the user.
In the future, it would be useful to have, for example, a version of the multivariate normal distribution where the precision matrix is given in compressed column format. But this is for a future version.
Marco
2013-05-06
And what about the GPU computing? Have you ever tryed to use the GPU with large datasets? I've found, for instance, the R-gpu and gputools package but I'm not sure that can be used with Jags..
Marco
2013-05-06
And what about the GPU computing? Have you ever tryed to use the GPU with large datasets? I've found, for instance, the R-gpu and gputools package but I'm not sure that can be used with Jags..