-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose diagnostic check functions #205
Comments
Yeah I agree we should expose these. I think we should also change the name of Maybe a method Also I think it would be useful if these methods returned the value of diagnostic to the user instead of only printing messages (it can also print messages). |
If stan-dev/posterior will have these checks (see stan-dev/posterior#77), we should just use those. The divergences, treedepth and ebfmi use sampler diagnostics so those are Stan specific and will be done by our helper functions. |
Yeah I agree |
What should we do here for now:
This one should be simple. |
I think posterior is going to end up including warnings also for HMC/NUTS, so I think all of them could end up being replace by posterior. Do you think we should just wait for posterior or implement them and then replace them with posterior's versions? |
Lets just wait for posterior then and move the milestone if you agree. |
Sounds good |
So what I think the API for this should be:
I think we should just go with it now that we have the three sampler diagnostics checks. The rhat/eff checks can be added later. |
I like this idea. We should think carefully about what object |
Just stumbled on this (calling CmdStan in a wrapper, so user never runs |
@rok-cesnovar and anyone else interested, I have some time to work on this, but I wanted to get a bit of feedback first. I have an idea for a method For example, what do you think about these examples? # here diagnose_sampler() prints the messages and returns a list
# containing the values of the diagnostics
# it could also have a `quiet` argument to turn off printing the messages.
> fit$diagnose_sampler()
Warning: 283 of 4000 (7.0%) transitions ended with a divergence.
This may indicate insufficient exploration of the posterior distribution.
Possible remedies include:
* Increasing adapt_delta closer to 1 (default is 0.8)
* Reparameterizing the model (e.g. using a non-centered parameterization)
* Using informative or weakly informative prior distributions
Warning: 1 of 4 chains had energy-based Bayesian fraction of missing information (E-BFMI) less than 0.2.
This may indicate poor exploration of the posterior.
$divergences
[1] 283
$max_treedepths
[1] 0
$min_ebfmi
[1] 0.1841229 # using quiet=TRUE
> fit$diagnose_sampler(quiet = TRUE)
$divergences
[1] 283
$max_treedepths
[1] 0
$min_ebfmi
[1] 0.1841229 # selecting diagnostics
> fit$diagnose_sampler(diagnostics = c("treedepth", "ebfmi"))
Warning: 1 of 4 chains had energy-based Bayesian fraction of missing information (E-BFMI) less than 0.2.
This may indicate poor exploration of the posterior.
$max_treedepths
[1] 0
$min_ebfmi
[1] 0.1841229 We could also do what I think Martin was suggesting and have two separate methods for this, but I'm not sure we want the user to have to call two separate methods to get the warnings and the values. But I'm happy to be convinced otherwise. |
I like it. Any reason to return max_treedepths and not just a vector of all tree depths? Same with ebfmi. I know there are users that compute both by reading sampler diagnostics as they need them to diagnose different runs. For example, when working towards getting those treedepths not to get maxed out, that info is crucial. |
Since tree depths are different for each chain and each iteration I was thinking they would just use
Yeah I can change it to include the ebfmi for each chain instead of just the min. |
Yeah, maybe max_treedepth for all chains is fine. Maybe for ebmfi split by chains is better? I don't really have a strong opinion, just bouncing ideas :) |
So maybe the returned list looks like this? It has the total number of divergences, the total number of times hitting max treedepth, and the ebfmi for each chain:
|
Just double checking: am I correct that Just want to double check that this is all accurate; otherwise I think it would be wise to distinguish reaching max treedepth and terminating via the NUTS criterion versus premature termination due to max treedepth. As things are, a user with poor mixing might decide to increase treedepth even if doing so has absolutely no effect on the exploration. |
Yeah, I think you are correct. @jsocolar does rstan have this function? |
Not that I know of. |
Yeah I also think you're right that currently if it says it hit max treedepth it's not clear whether the trajectory was halted prematurely. Unfortunately I think we're stuck with that for now. I guess we can document this caveat in the doc for this new method. @jsocolar Suggestions for how to word it? |
Looks great to me. |
@jgabry I'm a bit behind the times perhaps on what the actual recommendation is for these treedepth issues. If I'm on the default And in the latter case, would we want to just warn about hitting max treedepth or do we also want to warn about all treedepths in excess of N, where N is some appropriate number (possibly greater than 10). |
Actually I just remembered that these pieces of advice or caveats about interpretations should go in the website discussed in #505. The idea is to put all that stuff in one place so we don't have write it out separately for each interface and so we can make updates in one place instead of having to change warning messages. So I don't think we need to include this info with this new method other than to point to that website. But since you asked,
this is tricky because on the one hand if increasing
That's a great question. I have not thought about this enough to have a good answer. Anyway, these are all good things for us to think more about. If you're up for it I would raise these questions when we ask for comments on the website mentioned in #505. It sounds like we're close to doing that. |
Last thing: |
That seems like a good idea. I think the warning message should probably report the total (summing over chains) but we can return a separate number for each chain. @rok-cesnovar Does that sound ok to you? |
Yes, that sounds great! |
I guess if we're going to do it by chain for treedepth and ebfmi we should also do it for divergences too for consistency, right? The warning messages can stay the same though. |
Ok I've updated so that the output now looks like this (in this case only divergences warranted a warning):
|
@rok-cesnovar @jsocolar and anyone else who's interested, a few questions:
|
I agree that The following suggestions are awkward in their own way, but here they are for consideration: |
In my code doing similar things I use |
Thanks for the suggestions. I think using the |
Ok, I've updated it to use |
check_sampler_transitions_treedepth
andcheck_divergences
should be accessible to the user in some way.Either separately or as part of
fit$diagnose()
or something with possibly other checks.Cmdstan's diagnostics checks E-BMFI which is simple (only requires
energy__
I think) and two that require reading all data (ESS and RHAT checks).The text was updated successfully, but these errors were encountered: