-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
newton_solver
halts sampling
#2985
Comments
We also tried this with cmdstan directly, so we don't think this is an issue with the interface. |
It seems R's |
@charlesm93 would you maybe have any ideas on why the solver gets stuck in this case and doesn't error? |
@DemetriPananos do you know what the solution is supposed to be here? |
@spinkney No, I don't know the solution. I'm not so concerned that stan can't solve it -- R has problems too -- I'm more concerned that Stan just halts rather than raising a warning or something more reasonable. |
I agree. In the meantime, there's this code #2859 (comment). Would that help you? I'm getting an answer of 0.00714. For quatiles 0.1, 0.25, 0.5, 0.75, 0.9 I get
|
We found our own work around, but thought I should raise this to the Stan team |
@DemetriPananos, thanks for reporting the issue. EDIT: My original comment was incorrect. I was able to recreate it. Please see #2985 (comment). I was able to recreate the issue using cmdstanr, but I think it's upstream from the Math library (maybe somewhere in Stan?). I just created a C++ unit test to test the behavior and it stops as expected. I added this to the end of
And it passes. (It successfully stops and throws an The next step is to find out why it's not stopping on that exception. |
I'm going to try to plug in what gets generated from stanc to see if there's different behavior. |
The generated code, as a standalone C++ test, does end up in a loop. Here's what the C++ now looks like. There was minor modification to remove things from the
|
And I found it. The
For some reason, this doesn't trigger an exception. |
Update: I made an error in my original test. (I accidentally grouped terms.) It does go into an infinite loop! This is due to something going to
|
@DemetriPananos, please try this for the model and see what you get:
The update is 3 lines within the
When I run it, I end up with output like this:
@charlesm93, any thoughts on what to do? Is there a way to have |
I was able to simplify the example a bit:
different values of the starting |
Description
I've been trying to implement a simple sampler in the
generated quantities
block using the inverse CDF method. First, I draw a uniform random variable on (0, 1) then usenewton_solver
to sample an x. The method seems to work well for a few iterations, but then sampling completely halts. @rok-cesnovar has narrowed this down to cases when the uniform random variable is close to 0.Example
I've also tried trying to solve on the log scale (using the log cdf and log(u)) and the problem persists. The sampling simply halts and does not continue, no error messages.
Current Version:
v4.7.0
The text was updated successfully, but these errors were encountered: