-
Notifications
You must be signed in to change notification settings - Fork 246
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
Sampling from posterior predictive with Categorical and AutoDiagonalNormal occasionally samples outside support #1402
Comments
Good point! I think one way is to remove the last value |
I'll give that a go soon. Edit: Thinking about it a bit more, the solution you suggest would introduce as slight bias towards the last category, which would completely subsume the error/difference of probabilities summing up to one. Given that, I would prefer renormalising s, i.e. |
This is also the reason for tests failing in funsor pyro-ppl/funsor#594. Funsor assumes that Categorical distribution |
Yeah, please go with it. Maybe we can also do |
@ordabayevy Thanks for the pointer! We typically don't want to modify the inputs of the distributions in numpyro so I hope that @lumip solution will resolve the issue. Maybe we can also fix the issue here for completeness:
|
We encountered a subtle problem when sampling from the posterior predictive distribution for a model containing
Categorical
and using theAutoDiagonalNormal
: In some rare cases, the sample drawn from theCategorical
would be one large than the maximum category index. E.g., a model likemay sample a value of
num_categories
even though the support of the categorical distribution is(0, ..., num_categories-1)
.This seems to arise from the combination of
numpyro.distributions.util._categorical
(and hencenumpyro.distributions.CategoricalProbs
) expecting the passed probability vector to sum up exactly to oneAutoDiagonalNormal
(or probably rather theStickBreakingTransform
) not guaranteeing that due to numerical imprecisionWe observed samples from the
AutoDiagonalNormal
guide for which the probability vectorps
summed up to something just shy of one. In rare cases, the uniform (0,1) sample used innumpyro.distributions.util._categorical
falls above the total sum, resulting in the function to return the largest category index plus one as a value.Our current quick-and-dirty workaround for this is to simply clamp the sampled values to the support but surely there are better ways of handling this, but I haven't given it much thought. Naively it would seem that explicit renormalisation of the probability vector at some point would be the way to go, but I'm not sure that will actually be robust towards the numerical issues that seem to lead to this in the first place..
The text was updated successfully, but these errors were encountered: