FunWithR / MonteCarlo

An R package for simulation studies.
33 stars 15 forks source link

Progress bar along nrep #4

Closed konstunn closed 6 years ago

konstunn commented 7 years ago

Hello. Thanx for your work. Got a question, suggestion, proposal.

How can I setup progress bar along nrep? If that is possible.

Example:

library(MonteCarlo)
MonteCarlo(function(n) list(S=mean(rnorm(n))), nrep=10^4, param_list=list(n=100))

So I've got grid of 1 parameter constellations to be evaluated. And progress bar fills up to 100% immediately. And then I wait for 10000 simulations and don't know what is the progress.

I suppose that number of repetitions is usually much larger than number of parameters in Monte Carlo simulations.

So if it is not possible to configure so, why don't you organize progress bar to increment on every nrep simulation of every single parameter value evaluation? So that one does not get bored waiting.

Well, as a workaround one can do the following trick:

library(MonteCarlo)
n <- 100
N <- 10^4
n_grid <- rep(n, N)
param_list <- list(n=n_grid)
MonteCarlo(function(n) list(S=mean(rnorm(n))), nrep=1, param_list, max_grid=N)

But this looks ugly and works much more slowly.

Moreover, I face a little output bug: missing newline after progress bar is full after return from MonteCarlo().

My session info is (just in case):

R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=ru_RU.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=ru_RU.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=ru_RU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=ru_RU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] PoweR_1.0.6   Rcpp_0.12.11  ggplot2_2.2.1 knitr_1.15.1 

loaded via a namespace (and not attached):
 [1] grid_3.4.0       plyr_1.8.4       gtable_0.2.0     magrittr_1.5    
 [5] evaluate_0.10    scales_0.4.1     rlang_0.1.1      stringi_1.1.5   
 [9] lazyeval_0.2.0   tools_3.4.0      stringr_1.2.0    munsell_0.4.3   
[13] compiler_3.4.0   colorspace_1.3-2 tibble_1.3.3    

Thanks in advance. Looking forward to hearing from you.

FunWithR commented 6 years ago

Hi! The output bug is fixed. Also the progress bar for only one parameter constellation now starts at zero and then jumps to 100 percent. Unfortunately, moving the progress bar along nrep is infeasible in parallel mode, because in this case the reps for each parameter constellation are conducted on separate CPUs, and probably not all parameter constellations are simulated at the same time.