stan-dev / stan-dev/rstan

reject strings getting lost in output

Open
#734 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

When a Stan program hits a reject("foo"); statement, RStan doesn't print "foo".

Reproducible Steps:

The following Stan program will diverge with a "hello" message on about 50% of its iterations.

> code <- 
'parameters { real<lower = 0, upper = 1> y; } 
 model { if (y < 0.5) reject("***********hello**************"); }'
Current Output
> stan(model_code = code, refresh = 0, init = function(n) list(y = 0.8))
recompiling to avoid crashing R session
Inference for Stan model: cf47a628a1d7c499108cca7cff14c58a.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

      mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat
y     0.74    0.01 0.14  0.51  0.62  0.74  0.86  0.99   336 1.01
lp__ -1.96    0.04 0.79 -4.42 -2.14 -1.64 -1.44 -1.39   351 1.01

Samples were drawn using NUTS(diag_e) at Tue Jan 21 18:08:45 2020.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).
Warning messages:
1: There were 2058 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup 
2: Examine the pairs() plot to diagnose sampling problems
 
3: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
http://mc-stan.org/misc/warnings.html#bulk-ess 
Expected Output:

I expect to see the "hello" message in the divergence warnings.

The message does show up if it occurs during init, which is why I provided a custom init.

RStan Version:
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.15.2

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rstan_2.19.2          ggplot2_3.1.0         StanHeaders_2.18.1-10

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18       pillar_1.2.3       compiler_3.5.0     plyr_1.8.4        
 [5] bindr_0.1.1        prettyunits_1.0.2  base64enc_0.1-3    tools_3.5.0       
 [9] pkgbuild_1.0.2     tibble_1.4.2       gtable_0.2.0       pkgconfig_2.0.2   
[13] rlang_0.4.0        cli_1.0.0          parallel_3.5.0     loo_2.0.0         
[17] bindrcpp_0.2.2     gridExtra_2.3      withr_2.1.2        dplyr_0.7.6       
[21] stats4_3.5.0       grid_3.5.0         tidyselect_0.2.4   glue_1.2.0        
[25] inline_0.3.15      R6_2.2.2           processx_3.2.0     callr_3.0.0       
[29] purrr_0.2.5        magrittr_1.5       scales_0.5.0       ps_1.2.0          
[33] codetools_0.2-15   matrixStats_0.54.0 assertthat_0.2.0   colorspace_1.3-2  
[37] lazyeval_0.2.1     munsell_0.4.3      crayon_1.3.4      

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible Stan program and the RStan sampling output shown in the issue, then trace how divergence warnings are assembled and emitted. Done means the reject("hello") text from sampling iterations appears in the divergence warnings, as it already does during initialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.