-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Bug in sampling Binomial with non-scalar shape #4223
Comments
Perhaps somewhat surprisingly, this is not a bug and is expected behavior for MCMC using the Metropolis proposal. The short version of this explanation is that all the proposals for the vector version are getting rejected. The longer explanation is this: for The reason that the normal model provides different results is because it is a continuous model and hence we can use NUTS. NUTS avoids the random walk behavior (i.e. randomly flipping 1/0s) of the vanilla Metropolis algorithm that was used in the binomial case. |
Thanks. Understood. This shortcoming of Metropolis suggests that sample_posterior_predictive() (and also fast_sample_posterior_predictive()) cannot be used with models that have arrays of binomials. A nit: the normal model provides different results despite also using Metropolis; see comment in the original model above. I suspect normal works because as a continuous distribution there are many ways for the samples slightly smaller likelihood and hence still likely to be accepted. |
When a Binomial RV without observations has a vector shape, it samples incorrectly, sampling mostly zeros no matter the values of n and p. It works fine for scalar shapes.
Example:
The three RVs are identical binomials, except that the first RV scalar_binomial is a scalar, the second RV arrayed_binomial has shape 10 with scalar arguments, and the third RV arrayed_binomial_alt has shape 10 with (identical) arrayed arguments. Note also that nothing in this model is constrained by observations.
Sampling issues warnings about all-NaN slices:
The results are peculiar:
scalar_binomial is as expected. arrayed_binomial sees no non-zero samples in this execution, and means of 0.0. Other executions do see some non-zero samples. arrayed_binomial_alt sees no non-zero binomial samples, in this execution or in any others. Everything is nothing.
The same model structure with normals instead of binomials produces expected results:
Normal results:
Versions and main components
The text was updated successfully, but these errors were encountered: