-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
categorical_logit_rng() doesn't accept negative_infinity() input #3331
Comments
Hi, @mhollanders, and thanks for the reproducible bug report. Boundary conditions are challenging for something like Stan due to how floating-point arithmetic differs from real numbers. We've been torn in the past on what to do in cases like these, and as you can see, the result isn't entirely consistent. Alternative case Does this also work if you set int test2 = categorical_rng(softmax(log_theta)); If
The case at hand This case is degenerate for simplexes in that 0 values are on the boundary of parameter space, so they go to plus or minus infinity in the unconstrained representations Stan uses for sampling. Technically, a unit simplex can have zero values, but they play havoc with floating point. This isn't technically a bug so much as undefined behavior given our documentation. You'll see that the doc says that Flagging this so Alternatively, we could try to extend to the boundaries. We've done that in some cases, like allowing 0 as a simplex in Workaround You can just apply Recommendation I think we should fix this so that it does the right thing on the boundary even if it loses derivative information for parameters. |
Thanks for the clear explanation Bob, I appreciate your time. |
I found a similar issue when working with Considering that softmax is defined in terms of the exponential function, this corresponds to the fact: So IMHO it seems reasonable to define: softmax([..., −∞, ...]) = [..., 0, ...] softmax([..., +∞, ...]) = error Either way, I would suggest at least making the documentation of softmax more explicit on this matter. |
Hello everyone,
The following Stan program:
yields this error:
Given that exponentiating the normalised log probabilities works for
categorical_rng
, I think this is a bug. Please let me know if I'm wrong.Thanks,
Matt
The text was updated successfully, but these errors were encountered: