sbfnk / rbi

R package for Bayesian inference with state-space models using LibBi.
https://sbfnk.github.io/rbi/
24 stars 9 forks source link

Really long time to run even simple filter operations #14

Closed thigm85 closed 6 years ago

thigm85 commented 6 years ago

I was playing around with RBi and noticed that even very simple filter operations would take a long time to run:

   user  system elapsed 
 40.179   6.096  23.788 

while the display of the libbi obj would claim a much faster run time:

Wrapper around LibBi
======================
Model:  test 
Run time:  0.000202  seconds
Number of samples:  1024 
State trajectories recorded:  x 
Noise trajectories recorded:  w 

And this happens even after I have already run an operation with a model, so that compilation should not be the reason for that time difference AFAIK.

Is there a reason for this duration diff?

sbfnk commented 6 years ago

The first time it's indeed overhead from compiling the model (as you should be able to verify with verbose=TRUE).

Re-running the filter should indeed be much quicker, but there was a bug preventing this. It should be fixed if you reinstall with install_github, as per 0617aa7a27f92ec18f0264c59f8b3a5631bcc2e7.

thigm85 commented 6 years ago

The commit mentioned above fixed the issue when target="posterior". However, the model compilation happens every time I use target="prediction".

Looking at the code I see that this code block indeed trigger model compilation every time prediction is used as a target.

Is this really necessary, or would it be enough to simply call libBi with --init-file without triggering model compilation every time?

sbfnk commented 6 years ago

I think you're right - there is no more need for this code block. Please re-open if this is not fixed by 6267561.

thigm85 commented 6 years ago

Thanks for addressing this. I will let you know if this is not fixed.