如何在rjags中获取采样时间?

时间:2016-04-25 02:33:34

标签: r jags r2jags

我用rjags实现了LDA模型。我成功地获得了最终样本:

jags <- jags.model('../lda_jags.bug',
               data = data,
               n.chains = 1,
               n.adapt = 100)

update(jags, 2000)

samples <- jags.samples(jags,
         c('theta', 'phi', 'z'),
         1000)

现在,我可以使用samples$thetasamples$phi来获取thetaphi的结果。但我怎么知道抽样需要多长时间?谢谢!

1 个答案:

答案 0 :(得分:1)

正如@ eipi10所述,您可以在update()调用周围使用system.time()来计算R中的进程。或者,您可以使用runjags包来打印更新模型所花费的(总)时间,包括所有以前调用extend.jags:

library('runjags')
results <- run.jags('../lda_jags.bug', monitor = c('theta', 'phi', 'z'), 
           data = data, n.chains = 1, adapt = 100, burnin = 2000, sample = 1000)
results

# or:

jags <- jags.model('../lda_jags.bug',
               data = data,
               n.chains = 1,
               n.adapt = 0)
runjags <- as.runjags(jags, monitor = c('theta', 'phi', 'z'))
results <- extend.jags(runjags, adapt = 100, burnin = 2000, sample = 1000)
results
results <- extend.jags(runjags, sample = 1000)
results