0

I have implemented the LDA model with rjags. And I successfully got the final samples with:

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)

Now I can use samples$theta or samples$phi to get the result of theta and phi. But how can I know how long did it take to sample? Thanks!

user5779223
  • 1,460
  • 3
  • 21
  • 42
  • 1
    You can use `system.time()` or, for more detailed assessments, `microbenchmark()` from the `microbenchmark` package. – eipi10 Apr 25 '16 at 02:47
  • Can you please share "lda_jags.bug"? I am trying to make LDA work using JAGS and still don't know how to do it – sam Jul 05 '23 at 19:29

1 Answers1

1

As @eipi10 states you can use system.time() around the update() call to time the process within R. Or, you can use the runjags package which prints the (total) time taken in updating the model, including all previous calls to 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
Matt Denwood
  • 2,537
  • 1
  • 12
  • 16
  • Thanks for your answer. But why do you put another line of `results <- extend.jags(runjags, sample = 1000)` after the `results <- extend.jags(runjags, adapt = 100, burnin = 2000, sample = 1000)` ? – user5779223 Apr 25 '16 at 07:38
  • Just to demonstrate that the total time reported after the second call to extend.jags includes the time taken for the first function call (it is the total time taken in updating the model, not just for that single function call). Obviously you don't need to do that if you just want the original 1000 samples. – Matt Denwood Apr 25 '16 at 07:42
  • Can you please share "lda_jags.bug"? I am trying to make LDA work using JAGS and still don't know how to do it – sam Jul 05 '23 at 19:28