Programmatic access to Stan warnings

71 views
Skip to first unread message

Kevin Van Horn

unread,
Mar 10, 2016, 12:33:17 PM3/10/16
to Stan users mailing list
Stan produces a number of warnings for human consumption; some of these are in the progress output (e.g., numerical problems), and for RStan, some of these are given by warnings() (e.g., divergent transitions). Is there any way in RStan to access these as objects that R code can examine? Are they stored in the stanfit object anywhere?

Ben Goodrich

unread,
Mar 10, 2016, 2:22:51 PM3/10/16
to Stan users mailing list
On Thursday, March 10, 2016 at 12:33:17 PM UTC-5, Kevin Van Horn wrote:
Stan produces a number of warnings for human consumption; some of these are in the progress output (e.g., numerical problems), and for RStan, some of these are given by warnings() (e.g., divergent transitions). Is there any way in RStan to access these as objects that R code can examine? Are they stored in the stanfit object anywhere?

They aren't stored in the stanfit object. There is a random file in tempdir() that numerical problems are written to, but they are not broken down by chain. The warnings() are generated based on things that are stored, namely the matrices produced by get_sampler_params().

Ben

Michael Betancourt

unread,
Mar 10, 2016, 2:27:28 PM3/10/16
to stan-...@googlegroups.com
More specifically, you can do things like

> sampler_params <- get_sampler_params(fit, inc_warmup=FALSE)
> sum(sapply(sampler_params, function(x) c(x[,’n_divergent__’]))[,1])

> sampler_params <- get_sampler_params(fit, inc_warmup=FALSE)
> sum(sapply(sampler_params, function(x) c(x[,’treedepth__’]))[,1])


--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Krzysztof Sakrejda

unread,
Mar 10, 2016, 2:36:47 PM3/10/16
to Stan users mailing list
The desire to use warnings as a way of programmatically deciding on the quality of a run (perhaps before it is finished) is one that reaches pretty deep into the core Stan library because currently these warnings are only emitted as text strings which means programmatic use is fragile (i.e.-requires string matching or regex).  If you want this to get/stay on the agenda open an issue (stan-dev/stan), preferably with a usage example.

Krzysztof


On Thursday, March 10, 2016 at 12:33:17 PM UTC-5, Kevin Van Horn wrote:

Bob Carpenter

unread,
Mar 10, 2016, 2:39:42 PM3/10/16
to stan-...@googlegroups.com
At least now at the Stan API services level the warnings are
sent to their own callback (even if that does just eventually
get piped to stdout). The next step would be to add structure
like a logger (with levels like DEBUG, WARN, ERROR, FATAL that
you'd access programatically.

- Bob
Reply all
Reply to author
Forward
0 new messages